Skip to content

Commit adf0286

Browse files
committed
docs(backend): Simplify controller docstrings
1 parent 26b7856 commit adf0286

File tree

4 files changed

+77
-209
lines changed

4 files changed

+77
-209
lines changed

app_api/app/api/accounts/auth/controllers.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
"""
2-
Authentication controller module.
3-
4-
This module provides authentication endpoints for user login and logout
5-
functionality with JWT token-based authentication.
6-
"""
1+
"""Authentication controller module."""
72

83
from typing import Annotated, Any
94

@@ -45,17 +40,6 @@ async def login(
4540
4641
Validates user credentials, updates last login timestamp, and returns
4742
a JWT token for authenticated access.
48-
49-
Args:
50-
request: The incoming request containing application state
51-
data: Login credentials containing username and password
52-
auth_service: Authentication service for credential validation
53-
54-
Returns:
55-
Response containing JWT token and user information
56-
57-
Raises:
58-
HTTPException: If credentials are invalid (401)
5943
"""
6044
user = await auth_service.authenticate_user(data.username, data.password)
6145
if not user:
@@ -71,12 +55,7 @@ async def login(
7155
@post("/logout")
7256
async def logout(self) -> Response[None]:
7357
"""
74-
Log out the current user.
75-
76-
Clears the authentication token cookie to log out the user.
77-
78-
Returns:
79-
Empty response with token cookie deleted
58+
Log out the current user by clearing the authentication token.
8059
"""
8160
response = Response(content=None, status_code=HTTP_200_OK)
8261
response.delete_cookie("token")

app_api/app/api/accounts/permissions/controllers.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ class PermissionController(Controller):
3030
dependencies = {"permission_service": Provide(provide_permission_service)}
3131
exception_handlers = {NotFoundError: not_found_error_handler}
3232

33-
@get("/", summary="ListPermissions", guards=[has_permission("permissions", "list")])
33+
@get(
34+
"/",
35+
summary="ListPermissions",
36+
guards=[has_permission("permissions", "list")],
37+
)
3438
async def list(self, permission_service: PermissionService) -> Sequence[Permission]:
3539
"""
36-
List all permissions sorted by name.
37-
38-
Requires the 'permissions:list' permission.
40+
List all permissions in the system.
3941
40-
Raises:
41-
PermissionDeniedException: If the user lacks 'permissions:list' permission
42+
This endpoint requires the 'permissions:list' permission.
4243
"""
4344
return await permission_service.list()
4445

@@ -52,23 +53,21 @@ async def create(self, data: Permission, permission_service: PermissionService)
5253
"""
5354
Create a new permission.
5455
56+
Creates a new permission with the provided resource and action data.
5557
Requires the 'permissions:create' permission.
56-
57-
Raises:
58-
PermissionDeniedException: If the user lacks 'permissions:create' permission
5958
"""
6059
return await permission_service.create(data)
6160

62-
@get("/{permission_id:uuid}", summary="FetchPermission", guards=[has_permission("permissions", "read")])
61+
@get(
62+
"/{permission_id:uuid}",
63+
summary="FetchPermission",
64+
guards=[has_permission("permissions", "read")],
65+
)
6366
async def fetch(self, permission_id: UUID, permission_service: PermissionService) -> Permission:
6467
"""
65-
Fetch a specific permission by ID.
68+
Fetch a specific permission by its UUID.
6669
6770
Requires the 'permissions:read' permission.
68-
69-
Raises:
70-
NotFoundError: If the permission is not found (handled by not_found_error_handler)
71-
PermissionDeniedException: If the user lacks 'permissions:read' permission
7271
"""
7372
return await permission_service.get(permission_id)
7473

@@ -85,13 +84,9 @@ async def update(
8584
permission_service: PermissionService,
8685
) -> Permission:
8786
"""
88-
Update an existing permission.
87+
Update an existing permission's data.
8988
9089
Requires the 'permissions:update' permission.
91-
92-
Raises:
93-
NotFoundError: If the permission is not found (handled by not_found_error_handler)
94-
PermissionDeniedException: If the user lacks 'permissions:update' permission
9590
"""
9691
return await permission_service.update(item_id=permission_id, data=data.as_builtins())
9792

@@ -103,12 +98,8 @@ async def update(
10398
)
10499
async def delete(self, permission_id: UUID, permission_service: PermissionService) -> None:
105100
"""
106-
Delete a permission by ID.
101+
Delete a permission from the system.
107102
108103
Requires the 'permissions:delete' permission.
109-
110-
Raises:
111-
NotFoundError: If the permission is not found (handled by not_found_error_handler)
112-
PermissionDeniedException: If the user lacks 'permissions:delete' permission
113104
"""
114105
await permission_service.delete(permission_id)

app_api/app/api/accounts/roles/controllers.py

Lines changed: 30 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
"""
2-
Role management controller module.
3-
4-
This module provides CRUD operations for managing user roles
5-
in the role-based access control system.
6-
"""
1+
"""Role management controller module."""
72

83
from typing import Any, Sequence
94
from uuid import UUID
@@ -40,88 +35,62 @@ class RoleController(Controller):
4035
dependencies = {"role_service": Provide(provide_role_service)}
4136
exception_handlers = {NotFoundError: not_found_error_handler}
4237

43-
@get("/", summary="ListRoles", guards=[has_permission("roles", "list")])
38+
@get(
39+
"/",
40+
summary="ListRoles",
41+
guards=[has_permission("roles", "list")],
42+
)
4443
async def list(self, role_service: RoleService) -> Sequence[Role]:
4544
"""
46-
Get all roles in the system.
47-
48-
Requires the 'roles:list' permission.
49-
50-
Args:
51-
role_service: Role service for business operations
45+
List all roles in the system.
5246
53-
Returns:
54-
List of all role objects
55-
56-
Raises:
57-
PermissionDeniedException: If the user lacks 'roles:list' permission
47+
This endpoint requires the 'roles:list' permission.
5848
"""
5949
return await role_service.list()
6050

61-
@post("/", summary="CreateRole", dto=RoleCreateDTO, guards=[has_permission("roles", "create")])
51+
@post(
52+
"/",
53+
summary="CreateRole",
54+
dto=RoleCreateDTO,
55+
guards=[has_permission("roles", "create")],
56+
)
6257
async def create(self, data: Role, role_service: RoleService) -> Role:
6358
"""
64-
Create a new role.
65-
66-
Requires the 'roles:create' permission.
67-
68-
Args:
69-
data: Role data for creation
70-
role_service: Role service for business operations
59+
Create a new role with associated permissions.
7160
72-
Returns:
73-
The created role object
74-
75-
Raises:
76-
PermissionDeniedException: If the user lacks 'roles:create' permission
77-
HTTPException: If validation fails
61+
Creates a new role with the provided data and assigns any specified
62+
permissions. Requires the 'roles:create' permission.
7863
"""
7964
try:
8065
return await role_service.create_role_with_permissions(data)
8166
except ValueError as exc:
8267
raise HTTPException(detail=str(exc), status_code=400) from exc
8368

84-
@get("/{role_id:uuid}", summary="FetchRole", guards=[has_permission("roles", "read")])
69+
@get(
70+
"/{role_id:uuid}",
71+
summary="FetchRole",
72+
guards=[has_permission("roles", "read")],
73+
)
8574
async def fetch(self, role_id: UUID, role_service: RoleService) -> Role:
8675
"""
87-
Get a specific role by ID.
76+
Fetch a specific role by its UUID.
8877
8978
Requires the 'roles:read' permission.
90-
91-
Args:
92-
role_id: UUID of the role to retrieve
93-
role_service: Role service for business operations
94-
95-
Returns:
96-
The requested role object
97-
98-
Raises:
99-
NotFoundError: If the role is not found (handled by not_found_error_handler)
100-
PermissionDeniedException: If the user lacks 'roles:read' permission
10179
"""
10280
return await role_service.get(role_id)
10381

10482
@patch(
105-
"/{role_id:uuid}", summary="UpdateRole", dto=RoleUpdateDTO, guards=[has_permission("roles", "update")]
83+
"/{role_id:uuid}",
84+
summary="UpdateRole",
85+
dto=RoleUpdateDTO,
86+
guards=[has_permission("roles", "update")],
10687
)
10788
async def update(self, role_id: UUID, data: DTOData[Role], role_service: RoleService) -> Role:
10889
"""
109-
Update an existing role.
110-
111-
Requires the 'roles:update' permission.
112-
113-
Args:
114-
role_id: UUID of the role to update
115-
data: Updated role data
116-
role_service: Role service for business operations
117-
118-
Returns:
119-
The updated role object
90+
Update an existing role's data and permissions.
12091
121-
Raises:
122-
NotFoundError: If the role is not found (handled by not_found_error_handler)
123-
PermissionDeniedException: If the user lacks 'roles:update' permission
124-
HTTPException: If validation fails
92+
Updates the specified role's information and permission assignments
93+
with the provided data. Requires the 'roles:update' permission.
12594
"""
12695
try:
12796
return await role_service.update_role_with_permissions(role_id, data.as_builtins())

0 commit comments

Comments
 (0)