wishlist
This commit is contained in:
84
services/wishlistApi .ts
Normal file
84
services/wishlistApi .ts
Normal 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();
|
||||
Reference in New Issue
Block a user