feat: cards, attributes and modules

This commit is contained in:
2025-02-19 14:46:31 +04:00
parent a509a3a586
commit 1af78ce08a
61 changed files with 3212 additions and 2795 deletions

View File

@@ -0,0 +1,37 @@
from typing import Optional
from sqlalchemy import select
from sqlalchemy.orm import joinedload, selectinload
from card_attributes.handlers.base_handler import BaseHandler
from models import Attribute, project_attribute, card_relations
class CardAttributesQueryHandler(BaseHandler):
async def get_attributes_for_project(self, project_id: int) -> list[Attribute]:
stmt = (
select(Attribute)
.join(project_attribute, project_attribute.c.attribute_id == Attribute.id)
.where(project_attribute.c.project_id == project_id)
)
attributes = (await self.session.scalars(stmt)).all()
return list(attributes)
async def get_attr_by_name(self, attr_name: str) -> Optional[Attribute]:
stmt = (
select(Attribute)
.options(
selectinload(Attribute.projects),
)
.where(Attribute.name == attr_name)
)
attribute = (await self.session.scalars(stmt)).first()
return attribute
async def get_card_ids_by_group_id(self, group_id: int) -> list[int]:
stmt = (
select(card_relations.c.card_id)
.where(card_relations.c.group_id == group_id)
)
ids = await self.session.scalars(stmt)
return list(ids)