Просмотр исходного кода

feat(api): add FoodRecommendController with index/history/by-family endpoints

Xiaogang Liao 2 месяцев назад
Родитель
Сommit
1da3a17229

+ 56 - 0
cfc-backend/src/main/java/com/etotem/cfc/controller/FoodRecommendController.java

@@ -0,0 +1,56 @@
+package com.etotem.cfc.controller;
+
+import com.etotem.cfc.common.Result;
+import com.etotem.cfc.entity.FoodRecommendIndex;
+import com.etotem.cfc.entity.FoodRecommendIdxLog;
+import com.etotem.cfc.service.FoodRecommendService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+
+@Tag(name = "食材推荐指数", description = "家庭成员食材推荐指数查询")
+@Slf4j
+@RestController
+@RequestMapping("/api/food/recommendation")
+public class FoodRecommendController {
+
+    @Resource
+    private FoodRecommendService foodRecommendService;
+
+    @Operation(summary = "获取用户食材推荐指数")
+    @PostMapping("/index")
+    public Result<List<FoodRecommendIndex>> getIndex(@RequestBody Map<String, Object> params) {
+        Long userId = params.get("userId") instanceof Number
+            ? ((Number) params.get("userId")).longValue()
+            : Long.parseLong(params.get("userId").toString());
+        List<FoodRecommendIndex> indices = foodRecommendService.getIndexByUser(userId);
+        return Result.success(indices);
+    }
+
+    @Operation(summary = "获取食材推荐指数变更历史")
+    @PostMapping("/history")
+    public Result<List<FoodRecommendIdxLog>> getHistory(@RequestBody Map<String, Object> params) {
+        Long userId = params.get("userId") instanceof Number
+            ? ((Number) params.get("userId")).longValue()
+            : Long.parseLong(params.get("userId").toString());
+        Long foodId = params.get("foodId") instanceof Number
+            ? ((Number) params.get("foodId")).longValue()
+            : Long.parseLong(params.get("foodId").toString());
+        List<FoodRecommendIdxLog> history = foodRecommendService.getIndexHistory(userId, foodId);
+        return Result.success(history);
+    }
+
+    @Operation(summary = "按家庭分组获取食材推荐指数")
+    @PostMapping("/by-family")
+    public Result<Map<Long, List<FoodRecommendIndex>>> getByFamily(@RequestBody Map<String, Object> params) {
+        Long familyId = params.get("familyId") instanceof Number
+            ? ((Number) params.get("familyId")).longValue()
+            : Long.parseLong(params.get("familyId").toString());
+        Map<Long, List<FoodRecommendIndex>> result = foodRecommendService.getByFamily(familyId);
+        return Result.success(result);
+    }
+}