Files
Crm-Backend/repositories/board.py

35 lines
1.0 KiB
Python

from sqlalchemy import Select
from sqlalchemy.orm import selectinload
from models import Board
from repositories.base import BaseRepository
from repositories.mixins import (
RepDeleteMixin,
RepCreateMixin,
GetByIdMixin,
GetAllMixin,
RepUpdateMixin,
)
from schemas.board import UpdateBoardSchema, CreateBoardSchema
class BoardRepository(
BaseRepository,
GetAllMixin[Board],
RepDeleteMixin[Board],
RepCreateMixin[Board, CreateBoardSchema],
RepUpdateMixin[Board, UpdateBoardSchema],
GetByIdMixin[Board],
):
entity_class = Board
def _process_get_all_stmt_with_args(self, stmt: Select, *args) -> Select:
project_id = args[0]
return stmt.where(Board.project_id == project_id).order_by(Board.lexorank)
def _process_get_by_id_stmt(self, stmt: Select) -> Select:
return stmt.options(selectinload(Board.deals))
async def update(self, board: Board, data: UpdateBoardSchema) -> Board:
return await self._apply_update_data_to_model(board, data, True)