chore: initial import

This commit is contained in:
2025-11-09 00:26:00 -06:00
commit 67fb60e6ca
76 changed files with 3925 additions and 0 deletions

48
frontend/lib/api.js Normal file
View File

@@ -0,0 +1,48 @@
const API_BASE = process.env.NEXT_PUBLIC_API_URL?.replace(/\/$/, '') || 'http://localhost:8000';
async function request(path, init = {}) {
const response = await fetch(`${API_BASE}${path}`, {
headers: {
'Content-Type': 'application/json',
...(init.headers || {}),
},
...init,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`Request failed: ${response.status} ${text}`);
}
return response.json();
}
export function buildMediaUrl(path) {
if (!path) return null;
if (path.startsWith('http')) return path;
return `${API_BASE}${path}`;
}
export async function fetchProducts() {
return request('/api/commerce/products/');
}
export async function fetchProduct(slug) {
if (!slug) throw new Error('Product slug is required');
return request(`/api/commerce/products/${slug}/`);
}
export async function fetchCategories() {
return request('/api/commerce/categories/');
}
export async function fetchDeliveryZones() {
return request('/api/commerce/delivery-zones/');
}
export async function submitOrder(payload) {
return request('/api/commerce/orders/', {
method: 'POST',
body: JSON.stringify(payload),
});
}