From b7f96448d41fd198e9615248beeb39082491c836 Mon Sep 17 00:00:00 2001 From: bender Date: Mon, 9 Mar 2026 08:19:44 +0000 Subject: [PATCH] Update src/lib/api/product.ts --- src/lib/api/product.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/lib/api/product.ts b/src/lib/api/product.ts index 3e93c15..5941d50 100644 --- a/src/lib/api/product.ts +++ b/src/lib/api/product.ts @@ -1,6 +1,14 @@ -export const fetchProducts = async () => { +export interface Product { + id: string; + name: string; + price: number; + description?: string; + imageSrc?: string; + category?: string; +} + +export const fetchProducts = async (): Promise => { try { - // Fetch products from API const response = await fetch("/api/products"); const data = await response.json(); return data; @@ -10,9 +18,8 @@ export const fetchProducts = async () => { } }; -export const fetchProductDetail = async (id: string) => { +export const fetchProduct = async (id: string): Promise => { try { - // Fetch single product from API const response = await fetch(`/api/products/${id}`); const data = await response.json(); return data; @@ -21,3 +28,7 @@ export const fetchProductDetail = async (id: string) => { return null; } }; + +export const fetchProductDetail = async (id: string): Promise => { + return fetchProduct(id); +};