29 setLoading(false);
30 } else {
31 // Fallback to API calls if no initial data
32 loadData();
33 }
38 setLoading(true);
39 const [cyclesRes, symptomsRes, predictionRes] = await Promise.all([
40 fetch('/api/cycles'),
41 fetch('/api/symptoms'),
42 fetch('/api/cycles/predictions/next').catch(() => ({ ok: false }))
43 ]);
44
68 try {
69 const [cyclesRes, predictionRes] = await Promise.all([
70 fetch('/api/cycles'),
71 fetch('/api/cycles/predictions/next').catch(() => ({ ok: false }))
72 ]);
73
91 // Reload symptoms after update
92 try {
93 const symptomsRes = await fetch('/api/symptoms');
94 if (symptomsRes.ok) {
95 const symptomsData = await symptomsRes.json();
1# Backend - Pastry Shop API
2
3This directory contains the server-side logic for the pastry ordering system.
6
7- `index.ts` - Main Hono application with routes and static file serving
8- `routes/orders.ts` - Order management API endpoints
9- `database/` - Database setup and query functions
10
11## API Endpoints
12
13### Orders
14- `POST /api/orders` - Create a new order
15- `GET /api/orders` - Get all orders (for admin)
16- `PATCH /api/orders/:id/status` - Update order status
17
18### Pages
49## Error Handling
50
51- Input validation for all API endpoints
52- Proper HTTP status codes
53- Detailed error messages for debugging
24
25- ES6 modules for clean code organization
26- Async/await for API calls
27- Form validation and error handling
28- Local cart state management
14await initializeDatabase();
15
16// API routes
17app.route('/api/orders', ordersRouter);
18
19// Serve static files
65 async function loadOrders() {
66 try {
67 const response = await fetch('/api/orders');
68 const orders = await response.json();
69
136 async function updateOrderStatus(orderId, status) {
137 try {
138 const response = await fetch(\`/api/orders/\${orderId}/status\`, {
139 method: 'PATCH',
140 headers: { 'Content-Type': 'application/json' },
27 const loadTemplates = async () => {
28 try {
29 const response = await fetch('/api/templates');
30 const result = await response.json();
31
62 const handleCreateProject = async (projectData: any) => {
63 try {
64 const response = await fetch('/api/projects', {
65 method: 'POST',
66 headers: { 'Content-Type': 'application/json' },
73 if (selectedTemplate) {
74 for (const taskTemplate of selectedTemplate.tasks) {
75 await fetch('/api/tasks', {
76 method: 'POST',
77 headers: { 'Content-Type': 'application/json' },
221
222 try {
223 const response = await fetch('/api/orders', {
224 method: 'POST',
225 headers: {
71 const handleStatusChange = async (taskId: string, newStatus: string) => {
72 try {
73 const response = await fetch(`/api/tasks/${taskId}/status`, {
74 method: 'PATCH',
75 headers: { 'Content-Type': 'application/json' },
90 const handlePriorityChange = async (taskId: string, newPriority: string) => {
91 try {
92 const response = await fetch(`/api/tasks/${taskId}/priority`, {
93 method: 'PATCH',
94 headers: { 'Content-Type': 'application/json' },
110 try {
111 setIsLoading(true);
112 const response = await fetch('/api/tasks', {
113 method: 'POST',
114 headers: { 'Content-Type': 'application/json' },
96 description: "JavaScript, frameworks and interactive sites",
97 duration: 3,
98 skills: ["JavaScript", "React basics", "API integration", "Modern frameworks"],
99 projects: ["Interactive website", "Web app", "E-commerce site", "Portfolio upgrade"]
100 },
14
15- `frontend/` - Customer-facing ordering interface
16- `backend/` - API endpoints and order management
17- `shared/` - Common types and utilities
18
19## Getting Started
20
21The main entry point is `backend/index.ts` which serves both the API and frontend files.
22
23## Database
27- JSON storage for order items
28
29## API Endpoints
30
31- `GET /` - Serves the main ordering page
32- `POST /api/orders` - Submit a new order
33- `GET /api/orders` - Get all orders (admin)
49 // Load projects, tasks, and stats in parallel
50 const [projectsRes, tasksRes, statsRes] = await Promise.all([
51 fetch('/api/projects'),
52 fetch('/api/tasks/my-tasks'),
53 fetch('/api/dashboard/stats')
54 ]);
55