сделал добавление, редактирование и удаление набора без валидации
This commit is contained in:
parent
61a315d047
commit
fa85189cf1
@ -0,0 +1,84 @@
|
||||
"""Исправил у контента линз у нужных полей int на float
|
||||
|
||||
Revision ID: e2c127e2d330
|
||||
Revises: 15df0d2bfad5
|
||||
Create Date: 2025-02-27 09:50:29.338115
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'e2c127e2d330'
|
||||
down_revision: Union[str, None] = '15df0d2bfad5'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.alter_column('set_contents', 'tor',
|
||||
existing_type=sa.INTEGER(),
|
||||
type_=sa.Float(),
|
||||
existing_nullable=False)
|
||||
op.alter_column('set_contents', 'trial',
|
||||
existing_type=sa.INTEGER(),
|
||||
type_=sa.Float(),
|
||||
existing_nullable=False)
|
||||
op.alter_column('set_contents', 'esa',
|
||||
existing_type=sa.INTEGER(),
|
||||
type_=sa.Float(),
|
||||
existing_nullable=False)
|
||||
op.alter_column('set_contents', 'fvc',
|
||||
existing_type=sa.INTEGER(),
|
||||
type_=sa.Float(),
|
||||
existing_nullable=False)
|
||||
op.alter_column('set_contents', 'preset_refraction',
|
||||
existing_type=sa.INTEGER(),
|
||||
type_=sa.Float(),
|
||||
existing_nullable=False)
|
||||
op.alter_column('set_contents', 'diameter',
|
||||
existing_type=sa.INTEGER(),
|
||||
type_=sa.Float(),
|
||||
existing_nullable=False)
|
||||
op.alter_column('set_contents', 'periphery_toricity',
|
||||
existing_type=sa.INTEGER(),
|
||||
type_=sa.Float(),
|
||||
existing_nullable=False)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.alter_column('set_contents', 'periphery_toricity',
|
||||
existing_type=sa.Float(),
|
||||
type_=sa.INTEGER(),
|
||||
existing_nullable=False)
|
||||
op.alter_column('set_contents', 'diameter',
|
||||
existing_type=sa.Float(),
|
||||
type_=sa.INTEGER(),
|
||||
existing_nullable=False)
|
||||
op.alter_column('set_contents', 'preset_refraction',
|
||||
existing_type=sa.Float(),
|
||||
type_=sa.INTEGER(),
|
||||
existing_nullable=False)
|
||||
op.alter_column('set_contents', 'fvc',
|
||||
existing_type=sa.Float(),
|
||||
type_=sa.INTEGER(),
|
||||
existing_nullable=False)
|
||||
op.alter_column('set_contents', 'esa',
|
||||
existing_type=sa.Float(),
|
||||
type_=sa.INTEGER(),
|
||||
existing_nullable=False)
|
||||
op.alter_column('set_contents', 'trial',
|
||||
existing_type=sa.Float(),
|
||||
type_=sa.INTEGER(),
|
||||
existing_nullable=False)
|
||||
op.alter_column('set_contents', 'tor',
|
||||
existing_type=sa.Float(),
|
||||
type_=sa.INTEGER(),
|
||||
existing_nullable=False)
|
||||
# ### end Alembic commands ###
|
||||
@ -1,21 +0,0 @@
|
||||
import axios from "axios";
|
||||
import CONFIG from "../../core/Config.jsx";
|
||||
|
||||
|
||||
const deleteSetContent = async (token, set_content_id) => {
|
||||
try {
|
||||
const response = await axios.delete(`${CONFIG.BASE_URL}/set_content/${set_content_id}/`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
if (error.response?.status === 401) {
|
||||
throw new Error("Ошибка авторизации: пользователь не найден или токен недействителен");
|
||||
}
|
||||
throw new Error(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
export default deleteSetContent;
|
||||
@ -2,9 +2,9 @@ import axios from "axios";
|
||||
import CONFIG from "../../core/Config.jsx";
|
||||
|
||||
|
||||
const updateSetContent = async (token, set_content) => {
|
||||
const updateSetContent = async (token, set_content, set_id) => {
|
||||
try {
|
||||
const response = await axios.put(`${CONFIG.BASE_URL}/set_content/${set_content.id}/`, set_content, {
|
||||
const response = await axios.put(`${CONFIG.BASE_URL}/set_content/${set_id}/`, set_content, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
|
||||
@ -2,9 +2,9 @@ import axios from "axios";
|
||||
import CONFIG from "../../core/Config.jsx";
|
||||
|
||||
|
||||
const updateSet = async (token, set) => {
|
||||
const updateSet = async (token, set_id, set) => {
|
||||
try {
|
||||
const response = await axios.put(`${CONFIG.BASE_URL}/sets/${set.id}/`, set, {
|
||||
const response = await axios.put(`${CONFIG.BASE_URL}/sets/${set_id}/`, set, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
|
||||
@ -23,13 +23,12 @@ const SetFormModal = ({visible, onCancel, setData, onSubmit}) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (setData) {
|
||||
form.setFieldsValue({ title: setData.title || "" });
|
||||
form.setFieldsValue({title: setData.title || ""});
|
||||
}
|
||||
fetchSetContents();
|
||||
}, [setData, form]);
|
||||
|
||||
|
||||
|
||||
const fetchSetContents = async () => {
|
||||
if (!setData) return;
|
||||
|
||||
@ -70,7 +69,7 @@ const SetFormModal = ({visible, onCancel, setData, onSubmit}) => {
|
||||
preset_refraction: 0,
|
||||
diameter: 0,
|
||||
periphery_toricity: 0,
|
||||
side: "left",
|
||||
side: "левая",
|
||||
count: 1,
|
||||
type_id: null
|
||||
}]);
|
||||
@ -88,7 +87,7 @@ const SetFormModal = ({visible, onCancel, setData, onSubmit}) => {
|
||||
|
||||
const handleSubmit = () => {
|
||||
form.validateFields().then(values => {
|
||||
onSubmit({...values, contents: content});
|
||||
onSubmit({...values}, content);
|
||||
});
|
||||
};
|
||||
|
||||
@ -163,8 +162,8 @@ const SetFormModal = ({visible, onCancel, setData, onSubmit}) => {
|
||||
value={record.side}
|
||||
onChange={value => updateContentItem(index, "side", value)}
|
||||
>
|
||||
<Option value="left">Левая</Option>
|
||||
<Option value="right">Правая</Option>
|
||||
<Option value="левая">Левая</Option>
|
||||
<Option value="правая">Правая</Option>
|
||||
</Select>,
|
||||
},
|
||||
{
|
||||
@ -232,7 +231,7 @@ const SetFormModal = ({visible, onCancel, setData, onSubmit}) => {
|
||||
rowKey="id"
|
||||
pagination={false}
|
||||
scroll={{x: "max-content", y: 300}}
|
||||
locale={{ emptyText: "Добавьте элементы" }}
|
||||
locale={{emptyText: "Добавьте элементы"}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ import updateSet from "../api/sets/UpdateSet.jsx";
|
||||
import addSet from "../api/sets/AddSet.jsx";
|
||||
import deleteSet from "../api/sets/DeleteSet.jsx";
|
||||
import addSetContent from "../api/set_content/AddSetContent.jsx";
|
||||
import updateSetContent from "../api/set_content/UpdateSetContent.jsx";
|
||||
|
||||
|
||||
const SetLensesPage = () => {
|
||||
@ -114,7 +115,9 @@ const SetLensesPage = () => {
|
||||
refreshed_set = await addNewSet(set);
|
||||
}
|
||||
|
||||
if (refreshed_set) {
|
||||
if (refreshed_set && selectedSet) {
|
||||
await updateContent(content, refreshed_set.id);
|
||||
} else if (refreshed_set && !selectedSet) {
|
||||
await setContent(content, refreshed_set.id);
|
||||
}
|
||||
|
||||
@ -132,6 +135,7 @@ const SetLensesPage = () => {
|
||||
|
||||
const setContent = async (content, set_id) => {
|
||||
try {
|
||||
console.log(content);
|
||||
await addSetContent(user.token, content, set_id);
|
||||
} catch (error) {
|
||||
console.error("Ошибка сохранения набора:", error);
|
||||
@ -143,6 +147,19 @@ const SetLensesPage = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const updateContent = async (content, set_id) => {
|
||||
try {
|
||||
await updateSetContent(user.token, content, set_id);
|
||||
} catch (error) {
|
||||
console.error("Ошибка сохранения набора:", error);
|
||||
notification.error({
|
||||
message: "Ошибка сохранения набора",
|
||||
description: "Проверьте подключение к сети.",
|
||||
placement: "topRight",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const editCurrentSet = async (set) => {
|
||||
const refreshed_set = await updateSet(user.token, selectedSet.id, set);
|
||||
notification.success({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user