feat(frontend): React UI — pages, forms, audit log section, Tailwind, Vite build
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: '/api',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
// Response interceptor — normalize errors
|
||||
api.interceptors.response.use(
|
||||
(res) => res,
|
||||
(err) => {
|
||||
const message =
|
||||
err.response?.data?.error ||
|
||||
err.response?.data?.message ||
|
||||
err.message ||
|
||||
'An unexpected error occurred';
|
||||
const details = err.response?.data?.details || null;
|
||||
return Promise.reject({ message, details, status: err.response?.status });
|
||||
}
|
||||
);
|
||||
|
||||
export default api;
|
||||
|
||||
// ── Experiments ────────────────────────────────────────────────────────────────
|
||||
export const experimentsApi = {
|
||||
list: () => api.get('/experiments').then((r) => r.data),
|
||||
get: (id) => api.get(`/experiments/${id}`).then((r) => r.data),
|
||||
create: (data) => api.post('/experiments', data).then((r) => r.data),
|
||||
update: (id, data) => api.put(`/experiments/${id}`, data).then((r) => r.data),
|
||||
delete: (id) => api.delete(`/experiments/${id}`),
|
||||
};
|
||||
|
||||
// ── Animals ───────────────────────────────────────────────────────────────────
|
||||
export const animalsApi = {
|
||||
list: (experimentId) =>
|
||||
api.get('/animals', { params: { experimentId } }).then((r) => r.data),
|
||||
get: (id) => api.get(`/animals/${id}`).then((r) => r.data),
|
||||
create: (data) => api.post('/animals', data).then((r) => r.data),
|
||||
update: (id, data) => api.put(`/animals/${id}`, data).then((r) => r.data),
|
||||
delete: (id) => api.delete(`/animals/${id}`),
|
||||
};
|
||||
|
||||
// ── Daily Statuses ─────────────────────────────────────────────────────────────
|
||||
export const dailyStatusesApi = {
|
||||
list: (animalId) =>
|
||||
api.get('/daily-statuses', { params: { animalId } }).then((r) => r.data),
|
||||
get: (id) => api.get(`/daily-statuses/${id}`).then((r) => r.data),
|
||||
create: (data) => api.post('/daily-statuses', data).then((r) => r.data),
|
||||
update: (id, data) => api.put(`/daily-statuses/${id}`, data).then((r) => r.data),
|
||||
delete: (id) => api.delete(`/daily-statuses/${id}`),
|
||||
};
|
||||
|
||||
// ── Audit Logs ────────────────────────────────────────────────────────────────
|
||||
export const auditLogsApi = {
|
||||
list: (params) => api.get('/audit-logs', { params }).then((r) => r.data),
|
||||
};
|
||||
Reference in New Issue
Block a user