Merge branch 'organizations' (cherry-picked)

This commit is contained in:
Artem Kashaev
2025-11-27 15:38:47 +05:00
parent 4b45073bd3
commit 8c326501bf
9 changed files with 292 additions and 22 deletions
+13
View File
@@ -4,6 +4,7 @@ from __future__ import annotations
from collections.abc import Sequence
from sqlalchemy import select
from sqlalchemy.orm import selectinload
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.organization import Organization, OrganizationCreate
@@ -42,6 +43,18 @@ class OrganizationRepository:
result = await self._session.scalars(stmt)
return result.unique().all()
async def get_membership(self, organization_id: int, user_id: int) -> OrganizationMember | None:
stmt = (
select(OrganizationMember)
.where(
OrganizationMember.organization_id == organization_id,
OrganizationMember.user_id == user_id,
)
.options(selectinload(OrganizationMember.organization))
)
result = await self._session.scalars(stmt)
return result.first()
async def create(self, data: OrganizationCreate) -> Organization:
organization = Organization(name=data.name)
self._session.add(organization)