This commit is contained in:
2025-11-19 14:34:05 +07:00
parent 08b352f686
commit 3cd2a53a0e
6 changed files with 1107 additions and 14 deletions

84
services/wishlistApi .ts Normal file
View File

@@ -0,0 +1,84 @@
import api from './api';
export interface WishlistProduct {
id: number;
productId: number;
productName: string;
productImage: string;
price: number;
description: string;
addedAt: string;
}
export interface WishlistResponse {
success: boolean;
message: string;
data?: WishlistProduct;
}
export interface WishlistListResponse {
success: boolean;
message: string;
data?: {
wishlists: WishlistProduct[];
totalPages: number;
totalElements: number;
currentPage: number;
pageSize: number;
};
}
export interface WishlistCountResponse {
success: boolean;
message: string;
data?: number;
}
class WishlistApi {
/**
* Thêm sản phẩm vào danh sách ưu thích
*/
async addToWishlist(productId: number): Promise<WishlistResponse> {
return api.post<WishlistResponse>(
'/v1/wishlists/add',
{ productId },
{ requireAuth: true }
);
}
/**
* Xóa sản phẩm khỏi danh sách ưu thích
*/
async removeFromWishlist(productId: number): Promise<WishlistResponse> {
return api.delete<WishlistResponse>(
`/v1/wishlists/remove/${productId}`,
{ requireAuth: true }
);
}
/**
* Lấy danh sách sản phẩm ưu thích
*/
async getWishlists(
page: number = 0,
size: number = 10,
sortBy: string = 'createdAt'
): Promise<WishlistListResponse> {
return api.get<WishlistListResponse>(
`/v1/wishlists?page=${page}&size=${size}&sortBy=${sortBy}`,
{ requireAuth: true }
);
}
/**
* Lấy số lượng sản phẩm ưu thích
*/
async getWishlistCount(): Promise<WishlistCountResponse> {
return api.get<WishlistCountResponse>(
'/v1/wishlists/count',
{ requireAuth: true }
);
}
}
export const wishlistApi = new WishlistApi();