From 4cbd0885da673bb605c93945d321e6d3e416ed1d Mon Sep 17 00:00:00 2001 From: andrei Date: Thu, 27 Feb 2025 09:58:51 +0500 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=B2?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0=D1=86=D0=B8=D1=8E=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B8=20=D0=BD=D0=B0=D0=B1=D0=BE=D1=80?= =?UTF-8?q?=D0=B0=20=D0=B8=20=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/infrastructure/sets_service.py | 7 ++++++ web-app/src/components/sets/SetFormModal.jsx | 26 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/api/app/infrastructure/sets_service.py b/api/app/infrastructure/sets_service.py index c11c1b3..5994f60 100644 --- a/api/app/infrastructure/sets_service.py +++ b/api/app/infrastructure/sets_service.py @@ -4,6 +4,7 @@ from fastapi import HTTPException from sqlalchemy.ext.asyncio import AsyncSession from starlette import status +from app.application.set_content_repository import SetContentRepository from app.application.sets_repository import SetsRepository from app.domain.entities.set import SetEntity from app.domain.models import Set @@ -12,6 +13,7 @@ from app.domain.models import Set class SetsService: def __init__(self, db: AsyncSession): self.sets_repository = SetsRepository(db) + self.set_content_repository = SetContentRepository(db) async def get_all_sets(self) -> list[SetEntity]: sets = await self.sets_repository.get_all() @@ -54,6 +56,11 @@ class SetsService: if not _set: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Set not found") + set_content = await self.set_content_repository.get_by_set_id(set_id) + await self.set_content_repository.delete_list_sets( + list(set_content) + ) + result = await self.sets_repository.delete(_set) return SetEntity( diff --git a/web-app/src/components/sets/SetFormModal.jsx b/web-app/src/components/sets/SetFormModal.jsx index d069724..c5eef8d 100644 --- a/web-app/src/components/sets/SetFormModal.jsx +++ b/web-app/src/components/sets/SetFormModal.jsx @@ -75,6 +75,31 @@ const SetFormModal = ({visible, onCancel, setData, onSubmit}) => { }]); }; + const validateContent = () => { + for (const item of content) { + if ( + item.tor === null || + item.trial === null || + item.esa === null || + item.fvc === null || + item.preset_refraction === null || + item.diameter === null || + item.periphery_toricity === null || + item.side === null || + item.count === null || + item.type_id === null + ) { + notification.error({ + message: "Ошибка валидации", + description: "Все поля в таблице должны быть заполнены перед сохранением.", + placement: "topRight", + }); + return false; + } + } + return true; + }; + const updateContentItem = (index, field, value) => { const updated = [...content]; updated[index][field] = value; @@ -87,6 +112,7 @@ const SetFormModal = ({visible, onCancel, setData, onSubmit}) => { const handleSubmit = () => { form.validateFields().then(values => { + if (!validateContent()) return; onSubmit({...values}, content); }); };