feat: deal tags

This commit is contained in:
2025-10-19 12:12:08 +04:00
parent d7c7d1775f
commit ffee658349
16 changed files with 355 additions and 8 deletions

37
services/deal_tag.py Normal file
View File

@ -0,0 +1,37 @@
from models import DealTag
from repositories import DealTagRepository, DealRepository
from schemas.deal_tag import *
from services.mixins import *
class DealTagService(
ServiceCrudMixin[DealTag, DealTagSchema, CreateDealTagRequest, UpdateDealTagRequest]
):
schema_class = DealTagSchema
entity_deleted_msg = "Тег успешно удален"
entity_updated_msg = "Тег успешно обновлен"
entity_created_msg = "Тег успешно создан"
def __init__(self, session: AsyncSession):
self.repository = DealTagRepository(session)
async def switch_tag(self, request: SwitchDealTagRequest) -> SwitchDealTagResponse:
tag: DealTag = await self.repository.get_by_id(request.tag_id)
if request.deal_id:
deal = await DealRepository(self.repository.session).get_by_id(
request.deal_id
)
await self.repository.switch_tag_in_deal(tag, deal)
else:
deals = await DealRepository(self.repository.session).get_by_group_id(
request.group_id
)
await self.repository.switch_tag_in_deals(tag, deals)
return SwitchDealTagResponse(ok=True, message="Успешно")
async def get_tag_colors(self) -> GetTagColorsResponse:
colors = await self.repository.get_tag_colors()
return GetTagColorsResponse(
items=[DealTagColorSchema.model_validate(color) for color in colors]
)