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
public ResponseEntity<Map<String, Object>> getRecipeInfoViews(
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,
@AuthenticationPrincipal User user
) {
if (recipeSearchBody != null) {
if (recipeSearchBody.getType() == RecipeSearchBody.Type.AI_PROMPT) {
final RecipeAiSearchSpec spec = this.objectMapper.convertValue(
recipeSearchBody.getData(), RecipeAiSearchSpec.class
);
final List<RecipeInfoView> results = this.recipeService.aiSearch(spec, user);
return ResponseEntity.ok(Map.of("results", results));
} else {
throw new IllegalArgumentException("Invalid recipeSearchBody type: " + recipeSearchBody.getType());
}
if (recipeSearchBody.getType() == RecipeSearchBody.Type.AI_PROMPT) {
final RecipeAiSearchSpec spec = this.objectMapper.convertValue(
recipeSearchBody.getData(),
RecipeAiSearchSpec.class
);
final List<RecipeInfoView> results = this.recipeService.aiSearch(spec, user);
return ResponseEntity.ok(Map.of("results", results));
} else {
final Slice<RecipeInfoView> slice = this.recipeService.getInfoViewsViewableBy(pageable, user);
return ResponseEntity.ok(this.sliceViewService.getSliceView(slice));
throw new IllegalArgumentException("Invalid recipeSearchBody type: " + recipeSearchBody.getType());
}
}