fix: fixed attribute removing from module

This commit is contained in:
2025-11-02 12:29:18 +04:00
parent 2700538945
commit be878717e5
3 changed files with 15 additions and 23 deletions

View File

@ -69,25 +69,25 @@ class ModuleService(
raise ForbiddenException("Нельзя менять встроенный модуль")
return True
async def add_attribute(self, request: AddAttributeRequest) -> AddAttributeResponse:
module, attribute = await self._get_module_and_attr_from_request(request)
async def add_attribute(self, module_id: int, attribute_id: int) -> AddAttributeResponse:
module, attribute = await self._get_module_and_attr_from_request(module_id, attribute_id)
await self.repository.add_attribute_to_module(module, attribute)
return AddAttributeResponse(message="Аттрибут успешно добавлен к модулю")
async def delete_attribute(
self, request: DeleteAttributeRequest
self, module_id: int, attribute_id: int
) -> DeleteAttributeResponse:
module, attribute = await self._get_module_and_attr_from_request(request)
module, attribute = await self._get_module_and_attr_from_request(module_id, attribute_id)
await self.repository.delete_attribute_from_module(module, attribute)
return DeleteAttributeResponse(message="Аттрибут успешно удален из модуля")
async def _get_module_and_attr_from_request(
self, request: AddAttributeRequest | DeleteAttributeRequest
self, module_id: int, attribute_id: int,
) -> tuple[Module, Attribute]:
module = await self.repository.get_by_id(request.module_id)
module = await self.repository.get_by_id(module_id)
if module.is_built_in:
raise ForbiddenException("Нельзя менять встроенный модуль")
attr_repo = AttributeRepository(self.repository.session)
attribute = await attr_repo.get_by_id(request.attribute_id)
attribute = await attr_repo.get_by_id(attribute_id)
return module, attribute