fix: 修复 VoiceController Map.of 兼容性 + ExploreController 参数不匹配
- VoiceController: Map.of() -> Collections.singletonMap() 兼容 Java 8 - ExploreController: 补齐 takeoutService.roll() 缺失的 taste/priceRange/allergies 参数 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package com.chowbox.controller;
|
||||
|
||||
import com.chowbox.model.ApiResponse;
|
||||
import com.chowbox.model.FridgeMatchResult;
|
||||
import com.chowbox.service.FridgeService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/fridge")
|
||||
public class FridgeController {
|
||||
|
||||
@Autowired
|
||||
private FridgeService fridgeService;
|
||||
|
||||
@PostMapping("/match")
|
||||
public ApiResponse<List<FridgeMatchResult>> match(@RequestBody Map<String, Object> body) {
|
||||
Object ingObj = body.get("ingredients");
|
||||
log.info("Fridge match request: ingredients type={}, value={}", ingObj != null ? ingObj.getClass().getSimpleName() : "null", ingObj);
|
||||
|
||||
List<String> ingredients = new ArrayList<>();
|
||||
if (ingObj instanceof List) {
|
||||
for (Object item : (List<?>) ingObj) {
|
||||
if (item != null) ingredients.add(item.toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (ingredients.isEmpty()) {
|
||||
return ApiResponse.fail(400, "请输入至少一种食材");
|
||||
}
|
||||
|
||||
// 接收前端自定义常备调料
|
||||
List<String> staples = new ArrayList<>();
|
||||
Object stapleObj = body.get("staples");
|
||||
if (stapleObj instanceof List) {
|
||||
for (Object item : (List<?>) stapleObj) {
|
||||
if (item != null) staples.add(item.toString());
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Fridge match: parsed ingredients={}, staples={}", ingredients, staples);
|
||||
List<FridgeMatchResult> results = fridgeService.matchRecipes(ingredients, staples);
|
||||
log.info("Fridge match: {} results", results.size());
|
||||
return ApiResponse.ok(results);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user