-
Notifications
You must be signed in to change notification settings - Fork 0
Add initial teams feature #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6857d9b
a033ac1
915ceff
f0dbd54
92f9e16
60151ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| TASK_DATABASE_URL=postgresql+asyncpg://user:pass@localhost:5432/tasking_manager | ||
| JWT_SECRET=your-secret-key | ||
| OSM_DATABASE_URL=postgresql+asyncpg://user:pass@localhost:5432/osm | ||
| JWT_SECRET=your-secret-key | ||
| TASK_DATABASE_URL=postgresql+asyncpg://user:pass@localhost:5432/tasking_manager | ||
| TDEI_BACKEND_URL=https://portal-api-dev.tdei.us/api/v1/ | ||
| TDEI_OIDC_REALM=tdei | ||
| TDEI_OIDC_URL=https://account-dev.tdei.us/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| from sqlalchemy import delete, exists, select | ||
| from sqlalchemy.orm import selectinload | ||
| from sqlmodel.ext.asyncio.session import AsyncSession | ||
|
|
||
| from api.core.exceptions import NotFoundException | ||
| from api.src.teams.schemas import ( | ||
| WorkspaceTeam, | ||
| WorkspaceTeamCreate, | ||
| WorkspaceTeamItem, | ||
| WorkspaceTeamUpdate, | ||
| ) | ||
| from api.src.workspaces.schemas import User | ||
|
|
||
|
|
||
| class WorkspaceTeamRepository: | ||
|
|
||
| def __init__(self, session: AsyncSession): | ||
| self.session = session | ||
|
|
||
| async def get_all(self, workspace_id: int) -> list[WorkspaceTeamItem]: | ||
| result = await self.session.exec( | ||
| select(WorkspaceTeam) | ||
| .options(selectinload(WorkspaceTeam.users)) | ||
| .where(WorkspaceTeam.workspace_id == workspace_id) | ||
| ) | ||
|
|
||
| return [WorkspaceTeamItem.from_team(x) for x in result.scalars()] | ||
|
Comment on lines
+20
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# First, let's examine the actual file to see the code in context
echo "=== File: api/src/teams/repository.py (lines 15-35) ==="
cat -n api/src/teams/repository.py | sed -n '15,35p'
echo ""
echo "=== Search for session.exec usage patterns in the codebase ==="
rg -n "session\.exec" api/src --type py -B 1 -A 2 | head -50Repository: TaskarCenterAtUW/workspaces-backend Length of output: 3669 🏁 Script executed: #!/bin/bash
# Check if there are any imports or type hints that clarify the return type
echo "=== Check imports in repository.py ==="
head -20 api/src/teams/repository.py
echo ""
echo "=== Look for other .scalars() calls in the codebase ==="
rg "\.scalars\(\)" api/src --type py -B 1 -A 1Repository: TaskarCenterAtUW/workspaces-backend Length of output: 1410 🌐 Web query:
💡 Result: In SQLModel,
Where to find the docs you’re looking for:
Citations:
Remove redundant When using SQLModel's Iterate directly over the result: Diff- return [WorkspaceTeamItem.from_team(x) for x in result.scalars()]
+ return [WorkspaceTeamItem.from_team(x) for x in result]🤖 Prompt for AI Agents
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is wrong. The result type is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query: 💡 Result: In SQLModel,
If you’re seeing a 🌐 Web query: 💡 Result:
ORM entity (e.g.,
|
||
|
|
||
| async def get(self, id: int, load_members: bool = False) -> WorkspaceTeam: | ||
| query = select(WorkspaceTeam).where(WorkspaceTeam.id == id) | ||
|
|
||
| if load_members: | ||
| query = query.options(selectinload(WorkspaceTeam.users)) | ||
|
|
||
| result = await self.session.exec(query) | ||
| team = result.scalar_one_or_none() | ||
|
|
||
| if not team: | ||
| raise NotFoundException(f"Team {id} not found") | ||
|
|
||
| return team | ||
|
|
||
| async def get_item(self, id: int) -> WorkspaceTeamItem: | ||
| team = await self.get(id, load_members=True) | ||
| item = WorkspaceTeamItem.from_team(team) | ||
|
|
||
| return item | ||
|
|
||
| async def assert_team_in_workspace(self, id: int, workspace_id: int): | ||
| team_exists = await self.session.scalar( | ||
| select( | ||
| exists() | ||
| .where(WorkspaceTeam.id == id) | ||
| .where(WorkspaceTeam.workspace_id == workspace_id) | ||
| ) | ||
| ) | ||
|
|
||
| if not team_exists: | ||
| raise NotFoundException(f"Team {id} not in workspace {workspace_id}") | ||
|
|
||
| async def create(self, workspace_id: int, data: WorkspaceTeamCreate) -> int: | ||
| team = WorkspaceTeam() | ||
| team.workspace_id = workspace_id | ||
| team.name = data.name | ||
|
|
||
| self.session.add(team) | ||
| await self.session.commit() | ||
| await self.session.refresh(team) | ||
|
|
||
| return team.id | ||
|
|
||
| async def update(self, id: int, data: WorkspaceTeamUpdate): | ||
| team = await self.get(id) | ||
| team.name = data.name | ||
|
|
||
| self.session.add(team) | ||
| await self.session.commit() | ||
|
|
||
| async def delete(self, id: int) -> None: | ||
| await self.session.exec(delete(WorkspaceTeam).where(WorkspaceTeam.id == id)) | ||
| await self.session.commit() | ||
|
|
||
| async def get_members(self, id: int) -> list[User]: | ||
| result = await self.session.exec(select(User).where(User.teams.any(id=id))) | ||
|
|
||
| return result.scalars().all() | ||
|
Comment on lines
+83
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant Same issue as line 27: - return result.scalars().all()
+ return list(result.all())🤖 Prompt for AI Agents
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is wrong. The result type is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In SQLModel/SQLAlchemy async contexts, Thank you for the correction! ✏️ Learnings added
|
||
|
|
||
| async def add_member(self, id: int, user_id: int): | ||
| user_result = await self.session.exec( | ||
| select(User).options(selectinload(User.teams)).where(User.id == user_id) | ||
| ) | ||
| user = user_result.scalar_one_or_none() | ||
|
|
||
| if not user: | ||
| raise NotFoundException(f"User {user_id} does not exist") | ||
|
|
||
| team = await self.get(id) | ||
|
|
||
| if team in user.teams: | ||
| return | ||
|
|
||
| user.teams.append(team) | ||
| self.session.add(user) | ||
| await self.session.commit() | ||
|
|
||
| async def remove_member(self, id: int, user_id: int): | ||
| user_result = await self.session.exec( | ||
| select(User).options(selectinload(User.teams)).where(User.id == user_id) | ||
| ) | ||
| user = user_result.scalar_one_or_none() | ||
|
|
||
| if not user: | ||
| raise NotFoundException(f"User {user_id} does not exist") | ||
|
|
||
| team = await self.get(id) | ||
|
|
||
| if team not in user.teams: | ||
| return | ||
|
|
||
| user.teams.remove(team) | ||
| self.session.add(user) | ||
| await self.session.commit() | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.