feat: deals filters

This commit is contained in:
2025-09-01 17:54:45 +04:00
parent 93141da22c
commit 57c3ada2fa
8 changed files with 90 additions and 14 deletions

View File

@ -4,27 +4,43 @@ from sqlalchemy import select
from models import Deal, CardStatusHistory, Board
from repositories.base import BaseRepository
from schemas.base import SortDir
from schemas.deal import UpdateDealSchema, CreateDealSchema
from utils.sorting import apply_sorting
class DealRepository(BaseRepository):
async def get_all(
self,
board_id: Optional[int],
project_id: Optional[int],
page: Optional[int],
items_per_page: Optional[int],
field: Optional[str],
direction: Optional[SortDir],
project_id: Optional[int],
board_id: Optional[int],
status_id: Optional[int],
id: Optional[int],
name: Optional[str],
) -> tuple[list[Deal], int]:
stmt = select(Deal).where(Deal.is_deleted.is_(False))
if board_id:
stmt = stmt.where(Deal.board_id == board_id)
if id:
stmt = stmt.where(Deal.id == id)
if project_id:
stmt = stmt.join(Board).where(Board.project_id == project_id)
if board_id:
stmt = stmt.where(Deal.board_id == board_id)
if status_id:
stmt = stmt.where(Deal.status_id == status_id)
if name:
stmt = stmt.where(Deal.name.ilike(f"%{name}%"))
total_items = len((await self.session.execute(stmt)).all())
stmt = stmt.order_by(Deal.lexorank)
if field and direction is not None:
stmt = apply_sorting(stmt, Deal, field, direction)
else:
stmt = stmt.order_by(Deal.lexorank)
if page and items_per_page:
stmt = self._apply_pagination(stmt, page, items_per_page)