Update src/lib/api/product.ts
This commit is contained in:
@@ -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' };
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user