Files
JayuCloud/YumiNail-Frontend/src/api/product.ts
T

125 lines
3.9 KiB
TypeScript
Raw Normal View History

/**
* Front-end API wrapper for this module.
* Call guide: import the named API object, then call the matching method from a Vue page or composable.
*/
2026-02-24 09:59:22 +08:00
import api from './index'
2026-03-27 14:55:41 +08:00
import type { IdType } from '@/utils/id'
2026-02-24 09:59:22 +08:00
2026-05-23 18:44:57 +08:00
/**
* Purpose: ProductVO supports product.ts by holding or executing the product vo page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-24 09:59:22 +08:00
export interface ProductVO {
2026-03-27 14:55:41 +08:00
id: IdType
shopId: IdType | null
shopName?: string
2026-02-25 10:37:16 +08:00
name: string
title?: string
2026-02-24 09:59:22 +08:00
description: string
2026-02-25 10:37:16 +08:00
image: string
imageFileIds?: string
imageUrls?: string[]
2026-02-24 09:59:22 +08:00
price: number
2026-02-25 10:37:16 +08:00
estimatedTime: number
approximateDuration?: string
bookableArtists?: string
availableBookableArtistCount?: number
bookableArtistRestricted?: boolean
availableCoupons?: string
2026-02-25 10:37:16 +08:00
category: string
tags?: string
tagList?: string[]
tagInfos?: TagInfo[]
2026-02-25 10:37:16 +08:00
status: number
likeCount?: number
collectCount?: number
2026-02-24 09:59:22 +08:00
createTime: string
updateTime: string
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: TagInfo supports product.ts by holding or executing the tag info page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
export interface TagInfo {
2026-03-27 14:55:41 +08:00
id: IdType
tagName: string
textColor?: string
bgColor?: string
borderColor?: string
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: ListProductsParams supports product.ts by holding or executing the list products params page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-25 10:37:16 +08:00
export interface ListProductsParams {
page: number
size: number
keyword?: string
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: CreateProductRequest supports product.ts by holding or executing the create product request page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-25 10:37:16 +08:00
export interface CreateProductRequest {
name: string
2026-02-24 09:59:22 +08:00
description: string
2026-02-25 10:37:16 +08:00
image: string
2026-02-24 09:59:22 +08:00
price: number
2026-02-25 10:37:16 +08:00
estimatedTime: number
category: string
status: number
2026-03-27 14:55:41 +08:00
shopId: IdType | null
2026-02-25 10:37:16 +08:00
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: UpdateProductRequest supports product.ts by holding or executing the update product request page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-25 10:37:16 +08:00
export interface UpdateProductRequest {
name?: string
description?: string
image?: string
price?: number
estimatedTime?: number
category?: string
status?: number
2026-03-27 14:55:41 +08:00
shopId?: IdType | null
2026-02-24 09:59:22 +08:00
}
/**
* productApi groups all API calls for this page domain.
* Call guide: pass the typed payload or identifier into the method below, and use the returned Promise in the page script.
*/
2026-02-24 09:59:22 +08:00
export const productApi = {
2026-03-05 16:28:05 +08:00
getAllProducts: async (): Promise<ProductVO[]> => {
2026-03-10 23:23:15 +08:00
return await api.get<ProductVO[]>('/product/list/all') as unknown as ProductVO[]
2026-02-24 09:59:22 +08:00
},
2026-03-27 14:55:41 +08:00
getProductById: async (id: IdType): Promise<ProductVO> => {
2026-03-10 23:23:15 +08:00
return await api.get<ProductVO>(`/product/get/${id}`) as unknown as ProductVO
2026-02-24 09:59:22 +08:00
},
2026-03-05 16:28:05 +08:00
getProductsByTag: async (tag: string): Promise<ProductVO[]> => {
2026-03-10 23:23:15 +08:00
return await api.get<ProductVO[]>(`/product/list/tag/${tag}`) as unknown as ProductVO[]
2026-03-05 15:15:59 +08:00
},
2026-03-27 14:55:41 +08:00
likeProduct: async (productId: IdType): Promise<boolean> => {
return await api.post<boolean>(`/product-like/like/${productId}`) as unknown as boolean
2026-03-05 15:15:59 +08:00
},
2026-03-27 14:55:41 +08:00
unlikeProduct: async (productId: IdType): Promise<boolean> => {
return await api.post<boolean>(`/product-like/unlike/${productId}`) as unknown as boolean
2026-03-05 16:02:34 +08:00
},
2026-03-05 16:28:05 +08:00
searchProducts: async (keyword: string): Promise<ProductVO[]> => {
return await api.get<ProductVO[]>('/product/list/search', {
2026-03-05 16:02:34 +08:00
params: {
keyword: keyword
}
2026-03-10 23:23:15 +08:00
}) as unknown as ProductVO[]
2026-02-24 09:59:22 +08:00
}
2026-02-25 10:37:16 +08:00
}