добавил методы для по работе с апи Наборами и СОдержанием наобора
This commit is contained in:
parent
24405f1e06
commit
c3ddff6173
21
web-app/src/api/set_content/AddSetContent.jsx
Normal file
21
web-app/src/api/set_content/AddSetContent.jsx
Normal file
@ -0,0 +1,21 @@
|
||||
import axios from "axios";
|
||||
import CONFIG from "../../core/Config.jsx";
|
||||
|
||||
|
||||
const addSetContent = async (token, set_content) => {
|
||||
try {
|
||||
const response = await axios.post(`${CONFIG.BASE_URL}/set_content/`, set_content, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
if (error.response?.status === 401) {
|
||||
throw new Error("Ошибка авторизации: пользователь не найден или токен недействителен");
|
||||
}
|
||||
throw new Error(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
export default addSetContent;
|
||||
21
web-app/src/api/set_content/DeleteSetContent.jsx
Normal file
21
web-app/src/api/set_content/DeleteSetContent.jsx
Normal file
@ -0,0 +1,21 @@
|
||||
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;
|
||||
21
web-app/src/api/set_content/GetSetContentBySetId.jsx
Normal file
21
web-app/src/api/set_content/GetSetContentBySetId.jsx
Normal file
@ -0,0 +1,21 @@
|
||||
import axios from "axios";
|
||||
import CONFIG from "../../core/Config.jsx";
|
||||
|
||||
|
||||
const getSetContentBySetId = async (token, set_id) => {
|
||||
try {
|
||||
const response = await axios.get(`${CONFIG.BASE_URL}/set_content/${set_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 getSetContentBySetId;
|
||||
21
web-app/src/api/set_content/UpdateSetContent.jsx
Normal file
21
web-app/src/api/set_content/UpdateSetContent.jsx
Normal file
@ -0,0 +1,21 @@
|
||||
import axios from "axios";
|
||||
import CONFIG from "../../core/Config.jsx";
|
||||
|
||||
|
||||
const updateSetContent = async (token, set_content) => {
|
||||
try {
|
||||
const response = await axios.put(`${CONFIG.BASE_URL}/set_content/${set_content.id}/`, set_content, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
if (error.response?.status === 401) {
|
||||
throw new Error("Ошибка авторизации: пользователь не найден или токен недействителен");
|
||||
}
|
||||
throw new Error(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
export default updateSetContent;
|
||||
21
web-app/src/api/sets/AddSet.jsx
Normal file
21
web-app/src/api/sets/AddSet.jsx
Normal file
@ -0,0 +1,21 @@
|
||||
import axios from "axios";
|
||||
import CONFIG from "../../core/Config.jsx";
|
||||
|
||||
|
||||
const AddSet = async (token, set) => {
|
||||
try {
|
||||
const response = await axios.post(`${CONFIG.API_URL}/sets`, set, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
if (error.response?.status === 401) {
|
||||
throw new Error("Ошибка авторизации: пользователь не найден или токен недействителен");
|
||||
}
|
||||
throw new Error(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
export default AddSet;
|
||||
20
web-app/src/api/sets/DeleteSet.jsx
Normal file
20
web-app/src/api/sets/DeleteSet.jsx
Normal file
@ -0,0 +1,20 @@
|
||||
import axios from "axios";
|
||||
import CONFIG from "../../core/Config.jsx";
|
||||
|
||||
const deleteSet = async (token, set_id) => {
|
||||
try {
|
||||
const response = await axios.delete(`${CONFIG.BASE_URL}/sets/${set_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 deleteSet;
|
||||
20
web-app/src/api/sets/GetAllSets.jsx
Normal file
20
web-app/src/api/sets/GetAllSets.jsx
Normal file
@ -0,0 +1,20 @@
|
||||
import axios from "axios";
|
||||
import CONFIG from "../../core/Config.jsx";
|
||||
|
||||
const getAllSets = async (token) => {
|
||||
try {
|
||||
const response = await axios.get(`${CONFIG.BASE_URL}/sets/`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
if (error.response?.status === 401) {
|
||||
throw new Error("Ошибка авторизации: пользователь не найден или токен недействителен");
|
||||
}
|
||||
throw new Error(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
export default getAllSets;
|
||||
21
web-app/src/api/sets/UpdateSet.jsx
Normal file
21
web-app/src/api/sets/UpdateSet.jsx
Normal file
@ -0,0 +1,21 @@
|
||||
import axios from "axios";
|
||||
import CONFIG from "../../core/Config.jsx";
|
||||
|
||||
|
||||
const updateSet = async (token, set) => {
|
||||
try {
|
||||
const response = await axios.put(`${CONFIG.BASE_URL}/sets/${set.id}/`, set, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
if (error.response?.status === 401) {
|
||||
throw new Error("Ошибка авторизации: пользователь не найден или токен недействителен");
|
||||
}
|
||||
throw new Error(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
export default updateSet;
|
||||
Loading…
x
Reference in New Issue
Block a user