|
|
@@ -16,8 +16,11 @@ public class DietRecommendationController {
|
|
|
|
|
|
@PostMapping("/today")
|
|
|
public Result<Map> getTodayRecommendation(
|
|
|
- @RequestAttribute("familyId") Long familyId,
|
|
|
+ @RequestAttribute(value = "familyId", required = false) Long familyId,
|
|
|
@RequestBody(required = false) Map<String, String> request) {
|
|
|
+ if (familyId == null) {
|
|
|
+ return Result.noFamily("请先创建或加入家庭");
|
|
|
+ }
|
|
|
String date = (request != null) ? request.get("date") : null;
|
|
|
if (date == null || date.isEmpty()) {
|
|
|
return Result.error("date不能为空");
|
|
|
@@ -27,30 +30,42 @@ public class DietRecommendationController {
|
|
|
|
|
|
@PostMapping("/generate")
|
|
|
public Result<Map> generateRecommendation(
|
|
|
- @RequestAttribute("familyId") Long familyId,
|
|
|
+ @RequestAttribute(value = "familyId", required = false) Long familyId,
|
|
|
@RequestBody Map<String, String> request) {
|
|
|
+ if (familyId == null) {
|
|
|
+ return Result.noFamily("请先创建或加入家庭");
|
|
|
+ }
|
|
|
return Result.success(dietRecommendationService.generateRecommendation(familyId, request));
|
|
|
}
|
|
|
|
|
|
@PostMapping("/update")
|
|
|
public Result<Void> updateRecommendation(
|
|
|
- @RequestAttribute("familyId") Long familyId,
|
|
|
+ @RequestAttribute(value = "familyId", required = false) Long familyId,
|
|
|
@RequestBody Map<String, Object> request) {
|
|
|
+ if (familyId == null) {
|
|
|
+ return Result.noFamily("请先创建或加入家庭");
|
|
|
+ }
|
|
|
dietRecommendationService.updateRecommendation(familyId, request);
|
|
|
return Result.success(null);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/regenerate")
|
|
|
public Result<Map> regenerateRecommendation(
|
|
|
- @RequestAttribute("familyId") Long familyId,
|
|
|
+ @RequestAttribute(value = "familyId", required = false) Long familyId,
|
|
|
@RequestBody Map<String, Object> request) {
|
|
|
+ if (familyId == null) {
|
|
|
+ return Result.noFamily("请先创建或加入家庭");
|
|
|
+ }
|
|
|
return Result.success(dietRecommendationService.regenerateRecommendation(familyId, request));
|
|
|
}
|
|
|
|
|
|
@PostMapping("/complete")
|
|
|
public Result<Void> completeRecommendation(
|
|
|
- @RequestAttribute("familyId") Long familyId,
|
|
|
+ @RequestAttribute(value = "familyId", required = false) Long familyId,
|
|
|
@RequestBody Map<String, Object> request) {
|
|
|
+ if (familyId == null) {
|
|
|
+ return Result.noFamily("请先创建或加入家庭");
|
|
|
+ }
|
|
|
dietRecommendationService.completeRecommendation(familyId, request);
|
|
|
return Result.success(null);
|
|
|
}
|