Files
Crm-Backend/services/deal_tag.py
2025-10-19 12:12:08 +04:00

38 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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]
)