Move recipes ai-search to POST endpoint.

This commit is contained in:
Jesse Brault 2025-12-29 12:53:20 -06:00
parent 9f54c63c53
commit 0b62e06646

View File

@ -105,22 +105,26 @@ public class RecipeController {
@GetMapping @GetMapping
public ResponseEntity<Map<String, Object>> getRecipeInfoViews( public ResponseEntity<Map<String, Object>> getRecipeInfoViews(
Pageable pageable, Pageable pageable,
@AuthenticationPrincipal User user
) {
final Slice<RecipeInfoView> slice = this.recipeService.getInfoViewsViewableBy(pageable, user);
return ResponseEntity.ok(this.sliceViewService.getSliceView(slice));
}
@PostMapping
public ResponseEntity<Map<String, Object>> searchRecipes(
@RequestBody(required = false) RecipeSearchBody recipeSearchBody, @RequestBody(required = false) RecipeSearchBody recipeSearchBody,
@AuthenticationPrincipal User user @AuthenticationPrincipal User user
) { ) {
if (recipeSearchBody != null) { if (recipeSearchBody.getType() == RecipeSearchBody.Type.AI_PROMPT) {
if (recipeSearchBody.getType() == RecipeSearchBody.Type.AI_PROMPT) { final RecipeAiSearchSpec spec = this.objectMapper.convertValue(
final RecipeAiSearchSpec spec = this.objectMapper.convertValue( recipeSearchBody.getData(),
recipeSearchBody.getData(), RecipeAiSearchSpec.class RecipeAiSearchSpec.class
); );
final List<RecipeInfoView> results = this.recipeService.aiSearch(spec, user); final List<RecipeInfoView> results = this.recipeService.aiSearch(spec, user);
return ResponseEntity.ok(Map.of("results", results)); return ResponseEntity.ok(Map.of("results", results));
} else {
throw new IllegalArgumentException("Invalid recipeSearchBody type: " + recipeSearchBody.getType());
}
} else { } else {
final Slice<RecipeInfoView> slice = this.recipeService.getInfoViewsViewableBy(pageable, user); throw new IllegalArgumentException("Invalid recipeSearchBody type: " + recipeSearchBody.getType());
return ResponseEntity.ok(this.sliceViewService.getSliceView(slice));
} }
} }