feat: deal tags
This commit is contained in:
37
services/deal_tag.py
Normal file
37
services/deal_tag.py
Normal 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]
|
||||
)
|
||||
Reference in New Issue
Block a user