Implement car reservation schedule management system

Co-authored-by: pdf114514 <57948770+pdf114514@users.noreply.github.com>
Agent-Logs-Url: https://github.com/pdf114514/CarReservation/sessions/1d8c6b05-0e8d-4484-a2d8-8d427dfad9cb
This commit is contained in:
copilot-swe-agent[bot]
2026-03-20 18:03:33 +00:00
parent 3458e4d376
commit 50d3803610
22 changed files with 4500 additions and 0 deletions

27
frontend/src/api.js Normal file
View File

@@ -0,0 +1,27 @@
const API_BASE = '/api';
async function request(path, options = {}) {
const res = await fetch(`${API_BASE}${path}`, {
headers: { 'Content-Type': 'application/json' },
...options,
});
if (!res.ok) {
const err = await res.json().catch(() => ({ error: 'Unknown error' }));
throw new Error(err.error || `HTTP ${res.status}`);
}
return res.json();
}
export const api = {
// Cars
getCars: () => request('/cars'),
createCar: (data) => request('/cars', { method: 'POST', body: JSON.stringify(data) }),
updateCar: (id, data) => request(`/cars/${id}`, { method: 'PUT', body: JSON.stringify(data) }),
deleteCar: (id) => request(`/cars/${id}`, { method: 'DELETE' }),
// Reservations
getReservations: () => request('/reservations'),
createReservation: (data) => request('/reservations', { method: 'POST', body: JSON.stringify(data) }),
updateReservation: (id, data) => request(`/reservations/${id}`, { method: 'PUT', body: JSON.stringify(data) }),
deleteReservation: (id) => request(`/reservations/${id}`, { method: 'DELETE' }),
};