сделал валидацию при редактировании набора и поправил удаление набора
This commit is contained in:
parent
fa85189cf1
commit
4cbd0885da
@ -4,6 +4,7 @@ from fastapi import HTTPException
|
|||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
from starlette import status
|
from starlette import status
|
||||||
|
|
||||||
|
from app.application.set_content_repository import SetContentRepository
|
||||||
from app.application.sets_repository import SetsRepository
|
from app.application.sets_repository import SetsRepository
|
||||||
from app.domain.entities.set import SetEntity
|
from app.domain.entities.set import SetEntity
|
||||||
from app.domain.models import Set
|
from app.domain.models import Set
|
||||||
@ -12,6 +13,7 @@ from app.domain.models import Set
|
|||||||
class SetsService:
|
class SetsService:
|
||||||
def __init__(self, db: AsyncSession):
|
def __init__(self, db: AsyncSession):
|
||||||
self.sets_repository = SetsRepository(db)
|
self.sets_repository = SetsRepository(db)
|
||||||
|
self.set_content_repository = SetContentRepository(db)
|
||||||
|
|
||||||
async def get_all_sets(self) -> list[SetEntity]:
|
async def get_all_sets(self) -> list[SetEntity]:
|
||||||
sets = await self.sets_repository.get_all()
|
sets = await self.sets_repository.get_all()
|
||||||
@ -54,6 +56,11 @@ class SetsService:
|
|||||||
if not _set:
|
if not _set:
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Set not found")
|
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)
|
result = await self.sets_repository.delete(_set)
|
||||||
|
|
||||||
return SetEntity(
|
return SetEntity(
|
||||||
|
|||||||
@ -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 updateContentItem = (index, field, value) => {
|
||||||
const updated = [...content];
|
const updated = [...content];
|
||||||
updated[index][field] = value;
|
updated[index][field] = value;
|
||||||
@ -87,6 +112,7 @@ const SetFormModal = ({visible, onCancel, setData, onSubmit}) => {
|
|||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
form.validateFields().then(values => {
|
form.validateFields().then(values => {
|
||||||
|
if (!validateContent()) return;
|
||||||
onSubmit({...values}, content);
|
onSubmit({...values}, content);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user