4
4
from todo .models .common .pyobjectid import PyObjectId
5
5
from todo .repositories .team_repository import TeamRepository , UserTeamDetailsRepository
6
6
from todo .repositories .user_repository import UserRepository
7
+ from todo .constants .messages import AppMessages
7
8
8
9
9
10
class TeamService :
@@ -13,18 +14,8 @@ def create_team(cls, dto: CreateTeamDTO, created_by_user_id: str) -> CreateTeamR
13
14
Create a new team with members and POC.
14
15
"""
15
16
try :
16
- # Validate that all member IDs exist
17
- if dto .member_ids :
18
- for user_id in dto .member_ids :
19
- user = UserRepository .get_by_id (user_id )
20
- if not user :
21
- raise ValueError (f"User with ID { user_id } not found" )
22
-
23
- # Validate POC exists if provided
24
- if dto .poc_id :
25
- poc_user = UserRepository .get_by_id (dto .poc_id )
26
- if not poc_user :
27
- raise ValueError (f"POC user with ID { dto .poc_id } not found" )
17
+ # Member IDs and POC ID validation is handled at DTO level
18
+ member_ids = dto .member_ids or []
28
19
29
20
# Create team
30
21
team = TeamModel (
@@ -41,8 +32,8 @@ def create_team(cls, dto: CreateTeamDTO, created_by_user_id: str) -> CreateTeamR
41
32
user_teams = []
42
33
43
34
# Add members to the team
44
- if dto . member_ids :
45
- for user_id in dto . member_ids :
35
+ if member_ids :
36
+ for user_id in member_ids :
46
37
user_team = UserTeamDetailsModel (
47
38
user_id = PyObjectId (user_id ),
48
39
team_id = created_team .id ,
@@ -53,7 +44,7 @@ def create_team(cls, dto: CreateTeamDTO, created_by_user_id: str) -> CreateTeamR
53
44
user_teams .append (user_team )
54
45
55
46
# Add POC if not already in member_ids
56
- if dto .poc_id and dto .poc_id not in dto . member_ids :
47
+ if dto .poc_id and dto .poc_id not in member_ids :
57
48
poc_user_team = UserTeamDetailsModel (
58
49
user_id = PyObjectId (dto .poc_id ),
59
50
team_id = created_team .id ,
@@ -64,7 +55,7 @@ def create_team(cls, dto: CreateTeamDTO, created_by_user_id: str) -> CreateTeamR
64
55
user_teams .append (poc_user_team )
65
56
66
57
# Add creator if not already in member_ids
67
- if created_by_user_id not in dto . member_ids :
58
+ if created_by_user_id not in member_ids :
68
59
creator_user_team = UserTeamDetailsModel (
69
60
user_id = PyObjectId (created_by_user_id ),
70
61
team_id = created_team .id ,
@@ -90,7 +81,7 @@ def create_team(cls, dto: CreateTeamDTO, created_by_user_id: str) -> CreateTeamR
90
81
updated_at = created_team .updated_at ,
91
82
)
92
83
93
- return CreateTeamResponse (team = team_dto )
84
+ return CreateTeamResponse (team = team_dto , message = AppMessages . TEAM_CREATED )
94
85
95
86
except Exception as e :
96
87
raise ValueError (str (e ))
0 commit comments