Update src/lib/api/product.ts

This commit is contained in:
2026-03-09 08:19:44 +00:00
parent a23de14922
commit b7f96448d4

View File

@@ -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<Product[]> => {
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<Product | null> => {
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<Product | null> => {
return fetchProduct(id);
};