feat: deal attributes editing

This commit is contained in:
2025-10-27 10:02:02 +04:00
parent a579ae4145
commit 759a8d6478
6 changed files with 183 additions and 5 deletions

View File

@ -1,4 +1,4 @@
from models import Attribute
from models import Attribute, AttributeValue, AttributeLabel
from repositories import AttributeRepository
from schemas.attribute import *
from services.mixins import *
@ -29,3 +29,37 @@ class AttributeService(
return GetAllAttributeTypesResponse(
items=[AttributeTypeSchema.model_validate(t) for t in types]
)
async def get_deal_module_attributes(
self, deal_id: int, module_id: int
) -> GetDealModuleAttributesResponse:
deal_attributes: list[
tuple[Attribute, AttributeValue, AttributeLabel]
] = await self.repository.get_deal_module_attributes(deal_id, module_id)
attributes = []
for attr, attr_value, attr_label in deal_attributes:
attribute = DealModuleAttributeSchema(
attribute_id=attr.id,
label=attr_label.label if attr_label else attr.label,
original_label=attr.label,
value=attr_value.value if attr_value else attr.default_value,
type=AttributeTypeSchema.model_validate(attr.type),
default_value=attr.default_value,
description=attr.description,
is_applicable_to_group=attr.is_applicable_to_group,
is_shown_on_dashboard=attr.is_shown_on_dashboard,
is_highlight_if_expired=attr.is_highlight_if_expired,
is_nullable=attr.is_nullable,
)
attributes.append(attribute)
return GetDealModuleAttributesResponse(attributes=attributes)
async def update_deal_module_attributes(
self, deal_id: int, module_id: int, request: UpdateDealModuleAttributesRequest
) -> UpdateDealModuleAttributesResponse:
await self.repository.update_or_create_deal_attribute_values(
deal_id, module_id, request.attributes
)
return UpdateDealModuleAttributesResponse(message="Успешно сохранено")