39 lines
1.1 KiB
Python
39 lines
1.1 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,
|
|
)
|
|
from schemas.board import UpdateBoardSchema, CreateBoardSchema
|
|
|
|
|
|
class BoardRepository(
|
|
BaseRepository,
|
|
GetAllMixin[Board],
|
|
RepDeleteMixin[Board],
|
|
RepCreateMixin[Board, CreateBoardSchema],
|
|
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:
|
|
board.lexorank = data.lexorank if data.lexorank else board.lexorank
|
|
board.name = data.name if data.name else board.name
|
|
|
|
self.session.add(board)
|
|
await self.session.commit()
|
|
await self.session.refresh(board)
|
|
return board
|