refactor: repository get all mixin
This commit is contained in:
@ -1,24 +1,30 @@
|
||||
from sqlalchemy import select, Select
|
||||
from typing import overload
|
||||
|
||||
from sqlalchemy import Select
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
from models.project import Project
|
||||
from repositories.base import BaseRepository
|
||||
from repositories.mixins import RepDeleteMixin, RepCreateMixin, GetByIdMixin
|
||||
from repositories.mixins import (
|
||||
RepDeleteMixin,
|
||||
RepCreateMixin,
|
||||
GetByIdMixin,
|
||||
GetAllMixin,
|
||||
)
|
||||
from schemas.project import CreateProjectSchema, UpdateProjectSchema
|
||||
|
||||
|
||||
class ProjectRepository(
|
||||
BaseRepository,
|
||||
GetAllMixin[Project],
|
||||
RepDeleteMixin[Project],
|
||||
RepCreateMixin[Project, CreateProjectSchema],
|
||||
GetByIdMixin[Project],
|
||||
):
|
||||
entity_class = Project
|
||||
|
||||
async def get_all(self) -> list[Project]:
|
||||
stmt = select(Project).where(Project.is_deleted.is_(False)).order_by(Project.id)
|
||||
result = await self.session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
def _process_get_all_stmt(self, stmt: Select) -> Select:
|
||||
return stmt.order_by(Project.id)
|
||||
|
||||
def _process_get_by_id_stmt(self, stmt: Select) -> Select:
|
||||
return stmt.options(selectinload(Project.boards))
|
||||
|
||||
Reference in New Issue
Block a user