37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
from sqlalchemy.orm import selectinload
|
|
|
|
from models import DealTag
|
|
from models.project import Project
|
|
from repositories.built_in_module import BuiltInModuleRepository
|
|
from repositories.mixins import *
|
|
from schemas.project import CreateProjectSchema, UpdateProjectSchema
|
|
|
|
|
|
class ProjectRepository(
|
|
RepCrudMixin[Project, CreateProjectSchema, UpdateProjectSchema]
|
|
):
|
|
entity_class = Project
|
|
entity_not_found_msg = "Проект не найден"
|
|
|
|
def _apply_options(self, stmt: Select) -> Select:
|
|
return stmt.options(
|
|
selectinload(Project.boards),
|
|
selectinload(Project.tags).joinedload(DealTag.tag_color),
|
|
)
|
|
|
|
def _process_get_all_stmt(self, stmt: Select) -> Select:
|
|
return self._apply_options(stmt).order_by(Project.id)
|
|
|
|
def _process_get_by_id_stmt(self, stmt: Select) -> Select:
|
|
return self._apply_options(stmt)
|
|
|
|
async def update(self, project: Project, data: UpdateProjectSchema) -> Project:
|
|
if data.built_in_modules is not None:
|
|
built_in_modules = data.built_in_modules
|
|
module_ids = [module.id for module in built_in_modules]
|
|
data.built_in_modules = await BuiltInModuleRepository(
|
|
self.session
|
|
).get_by_ids(module_ids)
|
|
|
|
return await self._apply_update_data_to_model(project, data, True)
|