14
14
from drf_spectacular .utils import extend_schema , OpenApiParameter , OpenApiResponse
15
15
from drf_spectacular .types import OpenApiTypes
16
16
from todo .dto .team_dto import TeamDTO
17
+ from todo .services .user_service import UserService
17
18
18
19
19
20
class TeamListView (APIView ):
@@ -99,7 +100,7 @@ class TeamDetailView(APIView):
99
100
@extend_schema (
100
101
operation_id = "get_team_by_id" ,
101
102
summary = "Get team by ID" ,
102
- description = "Retrieve a single team by its unique identifier" ,
103
+ description = "Retrieve a single team by its unique identifier. Optionally, set ?member=true to get users belonging to this team. " ,
103
104
tags = ["teams" ],
104
105
parameters = [
105
106
OpenApiParameter (
@@ -108,20 +109,34 @@ class TeamDetailView(APIView):
108
109
location = OpenApiParameter .PATH ,
109
110
description = "Unique identifier of the team" ,
110
111
),
112
+ OpenApiParameter (
113
+ name = "member" ,
114
+ type = OpenApiTypes .BOOL ,
115
+ location = OpenApiParameter .QUERY ,
116
+ description = "If true, returns users that belong to this team instead of team details." ,
117
+ required = False ,
118
+ ),
111
119
],
112
120
responses = {
113
- 200 : OpenApiResponse (description = "Team retrieved successfully" ),
121
+ 200 : OpenApiResponse (description = "Team or team members retrieved successfully" ),
114
122
404 : OpenApiResponse (description = "Team not found" ),
115
123
500 : OpenApiResponse (description = "Internal server error" ),
116
124
},
117
125
)
118
126
def get (self , request : Request , team_id : str ):
119
127
"""
120
- Retrieve a single team by ID.
128
+ Retrieve a single team by ID, or users in the team if ?member=true .
121
129
"""
122
130
try :
123
- team_dto : TeamDTO = TeamService .get_team_by_id (team_id )
124
- return Response (data = team_dto .model_dump (mode = "json" ), status = status .HTTP_200_OK )
131
+ member = request .query_params .get ("member" , "false" ).lower () == "true"
132
+ if member :
133
+ from todo .repositories .team_repository import UserTeamDetailsRepository
134
+ user_ids = UserTeamDetailsRepository .get_users_by_team_id (team_id )
135
+ users = UserService .get_users_by_ids (user_ids )
136
+ return Response (data = [user .model_dump (mode = "json" ) for user in users ], status = status .HTTP_200_OK )
137
+ else :
138
+ team_dto : TeamDTO = TeamService .get_team_by_id (team_id )
139
+ return Response (data = team_dto .model_dump (mode = "json" ), status = status .HTTP_200_OK )
125
140
except ValueError as e :
126
141
fallback_response = ApiErrorResponse (
127
142
statusCode = 404 ,
0 commit comments