Hangry/src/main/java/com/example/hangry/GroupRecipeController.java
2025-02-12 11:49:46 +01:00

33 lines
1.0 KiB
Java

package com.example.hangry;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Set;
@RestController
@RequestMapping("/api/group-recipes")
@CrossOrigin(origins = "*")
public class GroupRecipeController {
private final GroupRecipeService groupRecipeService;
public GroupRecipeController(GroupRecipeService groupRecipeService) {
this.groupRecipeService = groupRecipeService;
}
@PostMapping("/{groupId}/share/{recipeId}")
public ResponseEntity<String> shareRecipe(@PathVariable Long groupId, @PathVariable Long recipeId) {
boolean shared = groupRecipeService.shareRecipeWithGroup(groupId, recipeId);
return shared ? ResponseEntity.ok("Rezept geteilt") : ResponseEntity.badRequest().body("Fehler beim Teilen");
}
@GetMapping("/{groupId}")
public ResponseEntity<Set<Recipe>> getGroupRecipes(@PathVariable Long groupId) {
return ResponseEntity.ok(groupRecipeService.getGroupRecipes(groupId));
}
}