/
BelgradeGambit
/
CLP
Обзор
Документация
Войти
/
BelgradeGambit
/
CLP
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
client/src/services/api.js
93 строки
3 KB
SaintTonka
11
09 янв 2025, 01:55
09 янв 2025, 01:55
31b3fd6
Код
Авторство
О чём код?
const API_BASE_URL = 'http://localhost:8000/api'; export async function fetchTeachers() { const response = await fetch(`${API_BASE_URL}/instructor/`); const data = await response.json(); console.log("Загруженные данные преподавателей:", data); return data; } export async function getTeacher(teacherId) { const response = await fetch(`${API_BASE_URL}/instructor/${teacherId}`); return response.json(); } export async function hireTeacher(teacher) { const response = await fetch(`${API_BASE_URL}/instructor/`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(teacher), }); return response.json(); } export async function fireTeacher(instructorId) { const response = await fetch(`${API_BASE_URL}/instructor/${instructorId}`, { method: 'DELETE', }); if (!response.ok) { throw new Error(`Ошибка удаления преподавателя: ${response.statusText}`); } return response.json(); } export async function transferTeacher(teacherId, newDepartmentId) { const response = await fetch(`${API_BASE_URL}/instructor/${teacherId}/department/${newDepartmentId}`, { method: 'PATCH', }); return response.json(); } // Студенты export async function fetchStudents() { const response = await fetch(`${API_BASE_URL}/student/`); return response.json(); } export async function getStudent(studentId) { const response = await fetch(`${API_BASE_URL}/student/${studentId}`); return response.json(); } export async function admitStudent(student) { const response = await fetch(`${API_BASE_URL}/student/`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(student), }); return response.json(); } export async function expelStudent(studentId) { const response = await fetch(`${API_BASE_URL}/student/${studentId}`, { method: 'DELETE', }); return response.json(); } export async function removeStudentFromGroup(studentId, groupId) { const response = await fetch(`${API_BASE_URL}/student/${studentId}/group/${groupId}`, { method: 'DELETE', }); return response.json(); } export async function transferStudent(studentId, newDepartmentId) { const response = await fetch(`${API_BASE_URL}/student/${studentId}/department/${newDepartmentId}`, { method: 'PATCH', }); return response.json(); } export async function fetchDepartments() { const response = await fetch(`${API_BASE_URL}/departments`); return response.json(); }