Skip to content

Commit

Permalink
♻️ Rename org path params to teams (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanx64 authored Apr 16, 2024
1 parent ce429e7 commit 750a134
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions backend/app/api/routes/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ def read_teams(
return TeamsPublic(data=teams, count=count)


@router.get("/{org_id}", response_model=TeamWithUserPublic)
def read_team(session: SessionDep, current_user: CurrentUser, org_id: int) -> Any:
@router.get("/{team_id}", response_model=TeamWithUserPublic)
def read_team(session: SessionDep, current_user: CurrentUser, team_id: int) -> Any:
"""
Retrieve an team by its ID and returns it along with its associated users.
"""
query = select(Team).options(
selectinload(Team.user_links).selectinload(UserTeamLink.user) # type: ignore
)
query = query.where(
Team.id == org_id,
Team.id == team_id,
col(Team.user_links).any(col(UserTeamLink.user) == current_user),
)
team = session.exec(query).first()
Expand All @@ -85,11 +85,11 @@ def create_team(
return team


@router.put("/{org_id}", response_model=TeamPublic)
@router.put("/{team_id}", response_model=TeamPublic)
def update_team(
session: SessionDep,
current_user: CurrentUser,
org_id: int,
team_id: int,
team_in: TeamUpdate,
) -> Any:
"""
Expand All @@ -99,7 +99,7 @@ def update_team(
select(UserTeamLink)
.options(selectinload(UserTeamLink.team)) # type: ignore
.where(
UserTeamLink.team_id == org_id,
UserTeamLink.team_id == team_id,
UserTeamLink.user == current_user,
)
)
Expand All @@ -122,16 +122,18 @@ def update_team(
return org


@router.delete("/{org_id}", response_model=Message)
def delete_team(session: SessionDep, current_user: CurrentUser, org_id: int) -> Message:
@router.delete("/{team_id}", response_model=Message)
def delete_team(
session: SessionDep, current_user: CurrentUser, team_id: int
) -> Message:
"""
Delete an team from the database.
"""
query = (
select(UserTeamLink)
.options(selectinload(UserTeamLink.team)) # type: ignore
.where(
UserTeamLink.team_id == org_id,
UserTeamLink.team_id == team_id,
UserTeamLink.user == current_user,
)
)
Expand All @@ -154,11 +156,11 @@ def delete_team(session: SessionDep, current_user: CurrentUser, org_id: int) ->
return Message(message="Team deleted")


@router.post("/{org_id}/users/", response_model=UserTeamLinkPublic)
@router.post("/{team_id}/users/", response_model=UserTeamLinkPublic)
def add_member_to_team(
session: SessionDep,
current_user: CurrentUser,
org_id: int,
team_id: int,
member_in: TeamCreateMember,
) -> Any:
"""
Expand All @@ -172,7 +174,7 @@ def add_member_to_team(
)
)
.where(
UserTeamLink.team_id == org_id,
UserTeamLink.team_id == team_id,
UserTeamLink.user == current_user,
)
)
Expand Down Expand Up @@ -201,11 +203,11 @@ def add_member_to_team(
return user_team


@router.put("/{org_id}/users/{user_id}", response_model=UserTeamLinkPublic)
@router.put("/{team_id}/users/{user_id}", response_model=UserTeamLinkPublic)
def update_member_in_team(
session: SessionDep,
current_user: CurrentUser,
org_id: int,
team_id: int,
user_id: int,
member_in: TeamUpdateMember,
) -> Any:
Expand All @@ -220,7 +222,7 @@ def update_member_in_team(
)
)
.where(
UserTeamLink.team_id == org_id,
UserTeamLink.team_id == team_id,
UserTeamLink.user == current_user,
)
)
Expand Down Expand Up @@ -251,11 +253,11 @@ def update_member_in_team(
return member_link


@router.delete("/{org_id}/users/{user_id}", response_model=Message)
@router.delete("/{team_id}/users/{user_id}", response_model=Message)
def remove_member_from_team(
session: SessionDep,
current_user: CurrentUser,
org_id: int,
team_id: int,
user_id: int,
) -> Message:
"""
Expand All @@ -274,7 +276,7 @@ def remove_member_from_team(
)
)
.where(
UserTeamLink.team_id == org_id,
UserTeamLink.team_id == team_id,
UserTeamLink.user == current_user,
)
)
Expand Down

0 comments on commit 750a134

Please sign in to comment.