This commit is contained in:
2026-05-11 22:08:50 +03:00
commit 9f4bf13276
11 changed files with 618 additions and 0 deletions

54
frontend/js/api.js Normal file
View File

@@ -0,0 +1,54 @@
// frontend/js/api.js
// Base URL for backend API (adjust if using different host/port)
const API_BASE = "http://localhost:5000/api";
export async function fetchCases(params = {}) {
const query = new URLSearchParams(params).toString();
const res = await fetch(`${API_BASE}/cases${query ? `?${query}` : ''}`);
return await res.json();
}
export async function createCase(data) {
const res = await fetch(`${API_BASE}/cases`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
return await res.json();
}
export async function getCase(id) {
const res = await fetch(`${API_BASE}/cases/${id}`);
return await res.json();
}
export async function updateCase(id, data) {
const res = await fetch(`${API_BASE}/cases/${id}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
return await res.json();
}
export async function deleteCase(id) {
const res = await fetch(`${API_BASE}/cases/${id}`, { method: "DELETE" });
return await res.json();
}
export async function uploadFiles(caseId, fileList) {
const form = new FormData();
for (const f of fileList) {
form.append("files", f);
}
const res = await fetch(`${API_BASE}/cases/${caseId}/files`, {
method: "POST",
body: form,
});
return await res.json();
}
export async function listFiles(caseId) {
const res = await fetch(`${API_BASE}/cases/${caseId}/files`);
return await res.json();
}