Update src/lib/api/product.ts

This commit is contained in:
2026-03-11 19:34:32 +00:00
parent d72002cc2a
commit 696d96576f

View File

@@ -1,42 +1,10 @@
'use client';
interface Product {
export interface Product {
id: string;
name: string;
price: number;
category: string;
price: string;
description?: string;
}
interface ApiResponse<T> {
success: boolean;
data?: T;
message?: string;
export async function fetchProductList(): Promise<Product[]> {
return [];
}
export const fetchProductList = async (): Promise<ApiResponse<Product[]>> => {
try {
const response = await fetch('/api/products');
if (!response.ok) {
return { success: false, message: 'Failed to fetch products' };
}
const data = await response.json();
return { success: true, data };
} catch (err) {
return { success: false, message: 'Failed to fetch products' };
}
};
export const fetchProductById = async (
productId: string
): Promise<ApiResponse<Product>> => {
try {
const response = await fetch(`/api/products/${productId}`);
if (!response.ok) {
return { success: false, message: 'Product not found' };
}
const data = await response.json();
return { success: true, data };
} catch (err) {
return { success: false, message: 'Product not found' };
}
};