Skip to content

Commit b728893

Browse files
committed
Subteams: Fixing issue with getSubteamsByGroup + minor fixes in subteams code
1 parent f47e03c commit b728893

4 files changed

Lines changed: 19 additions & 16 deletions

File tree

backend/api/routes/subteams.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
subteam_router = APIRouter()
99

1010
#### GET Requests ####
11-
@subteam_router.get("/", response_model=list[SubTeam])
11+
@subteam_router.get("/")
1212
async def get_subteams():
1313
subteams = subteams_serial(subteams_collection.find())
1414
#return {"data":subteams}
1515
return subteams
1616

1717

1818
# get subteams within a project
19-
@subteam_router.get("/getSubteamsByGroup", response_model=list[SubTeam])
19+
@subteam_router.get("/getSubteamsByGroup")
2020
async def get_subteams_by_group(request: GetSubteamsByGroupRequest):
2121
group_id = request.group_id
2222
# Validate group ID
@@ -28,7 +28,7 @@ async def get_subteams_by_group(request: GetSubteamsByGroupRequest):
2828

2929

3030
# get all task for a subteam
31-
@subteam_router.get("/getTasksBySubteam", response_model=list[Task])
31+
@subteam_router.get("/getTasksBySubteam")
3232
async def get_tasks_by_subteam(request: GetTasksBySubteamRequest):
3333
team_name = request.team_name
3434
# Check if subteam exists
@@ -47,7 +47,7 @@ async def get_tasks_by_subteam(request: GetTasksBySubteamRequest):
4747
return {"data": {"subteam": team_name, "tasks": tasks}}
4848

4949
#### POST Requests ####
50-
@subteam_router.post("/createSubteam", response_model=SubTeam, status_code=status.HTTP_201_CREATED)
50+
@subteam_router.post("/createSubteam", status_code=status.HTTP_201_CREATED)
5151
async def create_subteam(request : CreateSubteamRequest):
5252
# Check if team_name already exists
5353
if subteams_collection.find_one({"team_name": request.team_name}):
@@ -87,14 +87,15 @@ async def create_subteam(request : CreateSubteamRequest):
8787
inserted_subteam = subteams_collection.insert_one(newSubTeam)
8888
# created_subteam = subteams_collection.find_one({"team_name": request.team_name})
8989
newSubTeam["_id"] = str(inserted_subteam.inserted_id)
90+
newSubTeam["group"] = str(newSubTeam["group"])
9091

9192
# add subteam id to the groups' "subteams" field
92-
updated_group = groups_collection.find_one_and_update(
93-
{"_id": ObjectId(request.group)}, # find by group id
94-
{"$addToSet": {"subteams": inserted_subteam.inserted_id}},
95-
return_document=True)
93+
# groups_collection.find_one_and_update(
94+
# {"_id": request.group}, # find by group id
95+
# {"$addToSet": {"subteams": inserted_subteam.inserted_id}},
96+
# return_document=True)
9697

97-
return {"message": "Subteam created successfully", "data": {newSubTeam}}
98+
return {"message": "Subteam created successfully", "data":newSubTeam}
9899

99100
#### DELETE Requests ####
100101
@subteam_router.delete("/deleteSubteam", status_code=status.HTTP_201_CREATED)

backend/db/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class SubTeam(BaseModel): #_id as Primary key, automatically created, can be fou
4747
id: Optional[str] = Field(alias="_id", default=None)
4848
team_name: str
4949
members: List[str] # List of Foreign Keys referencing User.email
50-
tasks: List[str] # List of Foreign Keys referencing Task.id
50+
tasks: Optional[List[str]] = None # List of Foreign Keys referencing Task.id
5151
group: str # Foreign Key referencing Group.id
5252

5353

backend/db/schemas.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ def _task_serial(task: dict) -> Task:
6666
}
6767

6868
def _subteam_serial(subteam: dict) -> SubTeam:
69-
return {
70-
"team_name": subteam["team_name"],
71-
"members": subteam["members"],
72-
"tasks": subteam["tasks"],
73-
"group": str(subteam["group"])
74-
}
69+
return SubTeam( # Use the SubTeam model
70+
team_name=subteam["team_name"],
71+
members=subteam["members"], # Assuming these are already emails or strings
72+
tasks=[str(task_id) for task_id in subteam.get("tasks", [])], # Convert ObjectId to str
73+
group=str(subteam["group"]) # Convert group ObjectId to str
74+
)
7575

7676
def _notification_serial(notification: dict) -> Notification:
7777
return Notification(

backend/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from api.routes.files import files_router
88
from api.routes.chat import chat_router
99
from api.routes.notifications import notifications_router
10+
from api.routes.subteams import subteam_router
1011
from fastapi.middleware.cors import CORSMiddleware
1112
import logging
1213
import os
@@ -52,6 +53,7 @@
5253
app.include_router(chat_router, tags=["Chat"])
5354
app.include_router(tasks_router, prefix="/api", tags=["Task Comments"])
5455
app.include_router(notifications_router, prefix="/api/notifications", tags=["Notifications"])
56+
app.include_router(subteam_router, prefix="/api/subteams", tags=["Subteams"])
5557

5658
if __name__ == "__main__":
5759
port = int(os.getenv("PORT", 8000))

0 commit comments

Comments
 (0)