Files
JayuCloud/JC-ArtList-Frontend/src/api/product.ts
T

134 lines
4.3 KiB
TypeScript

/**
* 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.
*/
import api from './index'
import type { IdType } from '@/utils/id'
/**
* 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.
*/
export interface ProductVO {
id: IdType
shopId: IdType | null
shopName?: string
name: string
title?: string
description: string
targetAudience?: string
precautions?: string
image: string
imageFileIds?: string
imageUrls?: string[]
price: number
estimatedTime: number
approximateDuration?: string
serviceDurationMinutes?: number
bookableArtists?: string
availableBookableArtistCount?: number
bookableArtistRestricted?: boolean
availableCoupons?: string
category: string
tags?: string
tagList?: string[]
tagInfos?: TagInfo[]
status: number
likeCount?: number
collectCount?: number
createTime: string
updateTime: string
}
/**
* 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 {
id: IdType
tagName: string
textColor?: string
bgColor?: string
borderColor?: string
}
/**
* 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.
*/
export interface ListProductsParams {
page: number
size: number
keyword?: string
tag?: string
tagIds?: string
}
/**
* 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.
*/
export interface CreateProductRequest {
name: string
description: string
image: string
price: number
estimatedTime: number
category: string
status: number
shopId: IdType | null
}
/**
* 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.
*/
export interface UpdateProductRequest {
name?: string
description?: string
image?: string
price?: number
estimatedTime?: number
category?: string
status?: number
shopId?: IdType | null
}
/**
* 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.
*/
export const productApi = {
getAllProducts: async (): Promise<ProductVO[]> => {
return await api.get<ProductVO[]>('/product/list/all') as unknown as ProductVO[]
},
getProductById: async (id: IdType): Promise<ProductVO> => {
return await api.get<ProductVO>(`/product/get/${id}`) as unknown as ProductVO
},
getProductsByTag: async (tag: string): Promise<ProductVO[]> => {
return await api.get<ProductVO[]>(`/product/list/tag/${tag}`) as unknown as ProductVO[]
},
likeProduct: async (productId: IdType): Promise<boolean> => {
return await api.post<boolean>(`/product-like/like/${productId}`) as unknown as boolean
},
unlikeProduct: async (productId: IdType): Promise<boolean> => {
return await api.post<boolean>(`/product-like/unlike/${productId}`) as unknown as boolean
},
searchProducts: async (keyword: string): Promise<ProductVO[]> => {
return await api.get<ProductVO[]>('/product/list/search', {
params: {
keyword: keyword
}
}) as unknown as ProductVO[]
},
getProductPage: async (params: ListProductsParams): Promise<{ list: ProductVO[]; total: number; page: number; size: number }> => {
return await api.get('/product/list/page', { params }) as unknown as { list: ProductVO[]; total: number; page: number; size: number }
}
}