feat: patch and get statuses endpoints
This commit is contained in:
@ -1 +1,4 @@
|
||||
from .board import BoardRepository as BoardRepository
|
||||
from .deal import DealRepository as DealRepository
|
||||
from .project import ProjectRepository as ProjectRepository
|
||||
from .status import StatusRepository as StatusRepository
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
from models import Board
|
||||
from repositories.base import BaseRepository
|
||||
@ -8,10 +7,8 @@ from schemas.board import UpdateBoardSchema
|
||||
|
||||
class BoardRepository(BaseRepository):
|
||||
async def get_all(self, project_id: int) -> list[Board]:
|
||||
stmt = (
|
||||
select(Board)
|
||||
.where(Board.is_deleted.is_(False), Board.project_id == project_id)
|
||||
.options(selectinload(Board.statuses))
|
||||
stmt = select(Board).where(
|
||||
Board.is_deleted.is_(False), Board.project_id == project_id
|
||||
)
|
||||
result = await self.session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
31
repositories/status.py
Normal file
31
repositories/status.py
Normal file
@ -0,0 +1,31 @@
|
||||
from sqlalchemy import select
|
||||
|
||||
from models import Status
|
||||
from repositories.base import BaseRepository
|
||||
from schemas.status import UpdateStatusSchema
|
||||
|
||||
|
||||
class StatusRepository(BaseRepository):
|
||||
async def get_all(self, board_id: int) -> list[Status]:
|
||||
stmt = (
|
||||
select(Status)
|
||||
.where(Status.is_deleted.is_(False), Status.board_id == board_id)
|
||||
)
|
||||
result = await self.session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
async def get_by_id(self, status_id: int) -> Status | None:
|
||||
stmt = select(Status).where(
|
||||
Status.id == status_id, Status.is_deleted.is_(False)
|
||||
)
|
||||
result = await self.session.execute(stmt)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
async def update(self, status: Status, data: UpdateStatusSchema) -> Status:
|
||||
status.lexorank = data.lexorank if data.lexorank else status.lexorank
|
||||
status.name = data.name if data.name else status.name
|
||||
|
||||
self.session.add(status)
|
||||
await self.session.commit()
|
||||
await self.session.refresh(status)
|
||||
return status
|
||||
Reference in New Issue
Block a user