Skip to content

Commit 52d22ad

Browse files
Team member fix (#157)
* feat: add method to retrieve user information by team ID and corresponding unit tests * refactor: remove unused import of ObjectId in migrate_add_creator_to_teams command * refactor: improve code readability in migrate_add_creator_to_teams command and user retrieval method * feat: enhance watchlist API with pagination and task addition functionality * refactor: improve formatting of OpenApiResponse descriptions in watchlist API * fix: correct import path for GetWatchlistTasksResponse in watchlist API --------- Co-authored-by: Amit Prakash <[email protected]>
1 parent f24e9d1 commit 52d22ad

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

todo/views/watchlist.py

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,41 @@
1313
from todo.dto.watchlist_dto import CreateWatchlistDTO
1414
from todo.dto.responses.create_watchlist_response import CreateWatchlistResponse
1515
from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiResponse
16+
from drf_spectacular.types import OpenApiTypes
17+
from todo.dto.responses.get_watchlist_task_response import GetWatchlistTasksResponse
1618

1719

1820
class WatchlistListView(APIView):
21+
@extend_schema(
22+
operation_id="get_watchlist_tasks",
23+
summary="Get paginated list of watchlisted tasks",
24+
description="Retrieve a paginated list of tasks that are added to the authenticated user's watchlist.",
25+
tags=["watchlist"],
26+
parameters=[
27+
OpenApiParameter(
28+
name="page",
29+
type=OpenApiTypes.INT,
30+
location=OpenApiParameter.QUERY,
31+
description="Page number for pagination (default: 1)",
32+
required=False,
33+
),
34+
OpenApiParameter(
35+
name="limit",
36+
type=OpenApiTypes.INT,
37+
location=OpenApiParameter.QUERY,
38+
description="Number of tasks per page (default: 10, max: 100)",
39+
required=False,
40+
),
41+
],
42+
responses={
43+
200: OpenApiResponse(
44+
response=GetWatchlistTasksResponse,
45+
description="Paginated list of watchlisted tasks returned successfully",
46+
),
47+
400: OpenApiResponse(response=ApiErrorResponse, description="Bad request - validation error"),
48+
500: OpenApiResponse(response=ApiErrorResponse, description="Internal server error"),
49+
},
50+
)
1951
def get(self, request: Request):
2052
"""
2153
Retrieve a paginated list of tasks that are added to watchlist.
@@ -32,6 +64,20 @@ def get(self, request: Request):
3264
)
3365
return Response(data=response.model_dump(mode="json"), status=status.HTTP_200_OK)
3466

67+
@extend_schema(
68+
operation_id="add_task_to_watchlist",
69+
summary="Add a task to the watchlist",
70+
description="Add a task to the authenticated user's watchlist.",
71+
tags=["watchlist"],
72+
request=CreateWatchlistSerializer,
73+
responses={
74+
201: OpenApiResponse(response=CreateWatchlistResponse, description="Task added to watchlist successfully"),
75+
400: OpenApiResponse(
76+
response=ApiErrorResponse, description="Bad request - validation error or already in watchlist"
77+
),
78+
500: OpenApiResponse(response=ApiErrorResponse, description="Internal server error"),
79+
},
80+
)
3581
def post(self, request: Request):
3682
"""
3783
Add a task to the watchlist.
@@ -65,22 +111,23 @@ class WatchlistDetailView(APIView):
65111
@extend_schema(
66112
operation_id="update_watchlist_task",
67113
summary="Update watchlist status of a task",
68-
description="Update the isActive status of a task in the user's watchlist.",
114+
description="Update the isActive status of a task in the authenticated user's watchlist. This allows users to activate or deactivate watching a specific task.",
69115
tags=["watchlist"],
70116
parameters=[
71117
OpenApiParameter(
72118
name="task_id",
73-
type=str,
119+
type=OpenApiTypes.STR,
74120
location=OpenApiParameter.PATH,
75-
description="Unique identifier of the task to update in the watchlist.",
121+
description="Unique identifier of the task to update in the watchlist",
122+
required=True,
76123
),
77124
],
78125
request=UpdateWatchlistSerializer,
79126
responses={
80-
200: OpenApiResponse(description="Watchlist task updated successfully"),
81-
400: OpenApiResponse(description="Bad request"),
82-
404: OpenApiResponse(description="Task not found in watchlist"),
83-
500: OpenApiResponse(description="Internal server error"),
127+
200: OpenApiResponse(description="Watchlist task status updated successfully"),
128+
400: OpenApiResponse(response=ApiErrorResponse, description="Bad request - validation error"),
129+
404: OpenApiResponse(response=ApiErrorResponse, description="Task not found in watchlist"),
130+
500: OpenApiResponse(response=ApiErrorResponse, description="Internal server error"),
84131
},
85132
)
86133
def patch(self, request: Request, task_id: str):

0 commit comments

Comments
 (0)