refactor: repository get all mixin

This commit is contained in:
2025-09-05 11:13:49 +04:00
parent c1d3ac98f0
commit 7990e7d460
4 changed files with 58 additions and 19 deletions

View File

@ -1,28 +1,29 @@
from sqlalchemy import select, Select
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
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
async def get_all(self, project_id: int) -> list[Board]:
stmt = (
select(Board)
.where(Board.is_deleted.is_(False), Board.project_id == project_id)
.order_by(Board.lexorank)
)
result = await self.session.execute(stmt)
return list(result.scalars().all())
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))