package com.example.hangry; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.*; @RestController @RequestMapping("/api/ingredients") public class IngredientController { @Autowired private IngredientService ingredientService; // Globale Zutaten abrufen @GetMapping("/global") public List getGlobalIngredients() { return ingredientService.getGlobalIngredients(); } // Benutzerspezifische Zutaten abrufen @GetMapping("/user/{userId}") public List getUserIngredients(@PathVariable Long userId) { return ingredientService.getUserIngredients(userId); } // Neue globale Zutat hinzufügen @PostMapping("/global") public Ingredient addGlobalIngredient(@RequestBody Ingredient ingredient) { return ingredientService.addGlobalIngredient(ingredient); } // Neue benutzerspezifische Zutat hinzufügen @PostMapping("/user/{userId}") public ResponseEntity addUserIngredient(@PathVariable Long userId, @RequestBody Ingredient ingredient) { try { Ingredient newIngredient = ingredientService.addUserIngredient(userId, ingredient); return ResponseEntity.status(HttpStatus.CREATED).body(newIngredient); } catch (IllegalArgumentException e) { // Falls die Zutat bereits global existiert return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); } } }