package com.recipeapp.recipe; import com.recipeapp.recipe.dto.*; import jakarta.validation.Valid; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.security.Principal; import java.util.List; import java.util.UUID; @RestController @RequestMapping("/v1/ingredients") public class IngredientController { private final RecipeService recipeService; private final HouseholdResolver householdResolver; public IngredientController(RecipeService recipeService, HouseholdResolver householdResolver) { this.recipeService = recipeService; this.householdResolver = householdResolver; } @GetMapping public List searchIngredients( Principal principal, @RequestParam(required = false) String search, @RequestParam(required = false) Boolean isStaple) { UUID householdId = householdResolver.resolve(principal.getName()); return recipeService.searchIngredients(householdId, search, isStaple); } @PatchMapping("/{id}") public IngredientResponse patchIngredient( Principal principal, @PathVariable UUID id, @Valid @RequestBody IngredientPatchRequest request) { UUID householdId = householdResolver.resolve(principal.getName()); return recipeService.patchIngredient(householdId, id, request); } }