feat: status and board in deal schema
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.orm import joinedload
|
||||||
|
|
||||||
from models import Deal, CardStatusHistory, Board
|
from models import Deal, CardStatusHistory, Board
|
||||||
from repositories.base import BaseRepository
|
from repositories.base import BaseRepository
|
||||||
@ -22,7 +23,11 @@ class DealRepository(BaseRepository):
|
|||||||
id: Optional[int],
|
id: Optional[int],
|
||||||
name: Optional[str],
|
name: Optional[str],
|
||||||
) -> tuple[list[Deal], int]:
|
) -> tuple[list[Deal], int]:
|
||||||
stmt = select(Deal).where(Deal.is_deleted.is_(False))
|
stmt = (
|
||||||
|
select(Deal)
|
||||||
|
.options(joinedload(Deal.status), joinedload(Deal.board))
|
||||||
|
.where(Deal.is_deleted.is_(False))
|
||||||
|
)
|
||||||
|
|
||||||
if id:
|
if id:
|
||||||
stmt = stmt.where(Deal.id == id)
|
stmt = stmt.where(Deal.id == id)
|
||||||
@ -49,7 +54,11 @@ class DealRepository(BaseRepository):
|
|||||||
return list(result.scalars().all()), total_items
|
return list(result.scalars().all()), total_items
|
||||||
|
|
||||||
async def get_by_id(self, deal_id: int) -> Optional[Deal]:
|
async def get_by_id(self, deal_id: int) -> Optional[Deal]:
|
||||||
stmt = select(Deal).where(Deal.id == deal_id, Deal.is_deleted.is_(False))
|
stmt = (
|
||||||
|
select(Deal)
|
||||||
|
.options(joinedload(Deal.status), joinedload(Deal.board))
|
||||||
|
.where(Deal.id == deal_id, Deal.is_deleted.is_(False))
|
||||||
|
)
|
||||||
result = await self.session.execute(stmt)
|
result = await self.session.execute(stmt)
|
||||||
return result.scalar_one_or_none()
|
return result.scalar_one_or_none()
|
||||||
|
|
||||||
@ -58,7 +67,8 @@ class DealRepository(BaseRepository):
|
|||||||
self.session.add(deal)
|
self.session.add(deal)
|
||||||
await self.session.commit()
|
await self.session.commit()
|
||||||
await self.session.refresh(deal)
|
await self.session.refresh(deal)
|
||||||
return deal
|
print(deal.id)
|
||||||
|
return await self.get_by_id(deal.id)
|
||||||
|
|
||||||
async def update(self, deal: Deal, data: UpdateDealSchema) -> Deal:
|
async def update(self, deal: Deal, data: UpdateDealSchema) -> Deal:
|
||||||
deal.lexorank = data.lexorank if data.lexorank else deal.lexorank
|
deal.lexorank = data.lexorank if data.lexorank else deal.lexorank
|
||||||
|
|||||||
@ -2,6 +2,8 @@ from datetime import datetime
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from schemas.base import BaseSchema, BaseResponse, PaginationInfoSchema
|
from schemas.base import BaseSchema, BaseResponse, PaginationInfoSchema
|
||||||
|
from schemas.board import BoardSchema
|
||||||
|
from schemas.status import StatusSchema
|
||||||
|
|
||||||
|
|
||||||
# region Entities
|
# region Entities
|
||||||
@ -11,8 +13,8 @@ class DealSchema(BaseSchema):
|
|||||||
id: int
|
id: int
|
||||||
name: str
|
name: str
|
||||||
lexorank: str
|
lexorank: str
|
||||||
status_id: int
|
status: StatusSchema
|
||||||
board_id: int
|
board: BoardSchema
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user