feat: 增强食物库功能,支持自定义食物的创建与删除,优化用户体验
This commit is contained in:
@@ -6,6 +6,20 @@ import type {
|
||||
} from '@/types/food';
|
||||
import { api } from './api';
|
||||
|
||||
export interface CreateCustomFoodDto {
|
||||
name: string;
|
||||
description?: string;
|
||||
caloriesPer100g?: number;
|
||||
proteinPer100g?: number;
|
||||
carbohydratePer100g?: number;
|
||||
fatPer100g?: number;
|
||||
fiberPer100g?: number;
|
||||
sugarPer100g?: number;
|
||||
sodiumPer100g?: number;
|
||||
additionalNutrition?: Record<string, any>;
|
||||
imageUrl?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 食物库 API 服务
|
||||
*/
|
||||
@@ -39,6 +53,20 @@ export class FoodLibraryApi {
|
||||
const { id } = params;
|
||||
return api.get<FoodItemDto>(`${this.BASE_PATH}/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建自定义食物
|
||||
*/
|
||||
static async createCustomFood(data: CreateCustomFoodDto): Promise<FoodItemDto> {
|
||||
return api.post<FoodItemDto>(`${this.BASE_PATH}/custom`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除自定义食物
|
||||
*/
|
||||
static async deleteCustomFood(id: number): Promise<void> {
|
||||
return api.delete(`${this.BASE_PATH}/custom/${id}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 导出便捷方法
|
||||
@@ -46,4 +74,6 @@ export const foodLibraryApi = {
|
||||
getFoodLibrary: () => FoodLibraryApi.getFoodLibrary(),
|
||||
searchFoods: (keyword: string) => FoodLibraryApi.searchFoods({ keyword }),
|
||||
getFoodById: (id: number) => FoodLibraryApi.getFoodById({ id }),
|
||||
createCustomFood: (data: CreateCustomFoodDto) => FoodLibraryApi.createCustomFood(data),
|
||||
deleteCustomFood: (id: number) => FoodLibraryApi.deleteCustomFood(id),
|
||||
};
|
||||
Reference in New Issue
Block a user