feat(server/logging): endpoint calls logging
This commit is contained in:
parent
841fe75fad
commit
9787584d97
1 changed files with 8 additions and 0 deletions
|
|
@ -24,16 +24,19 @@ import server.service.RecipeService;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class RecipeController {
|
||||
private static final Logger logger = Logger.getLogger(RecipeController.class.getName());
|
||||
private final SimpMessagingTemplate messagingTemplate;
|
||||
private final RecipeService recipeService;
|
||||
|
||||
public RecipeController(RecipeService recipeService, SimpMessagingTemplate messagingTemplate) {
|
||||
this.recipeService = recipeService;
|
||||
this.messagingTemplate = messagingTemplate;
|
||||
logger.info("Initialized controller.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -46,6 +49,7 @@ public class RecipeController {
|
|||
*/
|
||||
@GetMapping("/recipe/{id}")
|
||||
public ResponseEntity<Recipe> getRecipe(@PathVariable Long id) {
|
||||
logger.info("GET /recipe/" + id + " called.");
|
||||
return recipeService.findById(id)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElseGet(() -> ResponseEntity.notFound().build());
|
||||
|
|
@ -60,6 +64,7 @@ public class RecipeController {
|
|||
*/
|
||||
@GetMapping("/recipes")
|
||||
public ResponseEntity<List<Recipe>> getRecipes(@RequestParam Optional<Integer> limit) {
|
||||
logger.info("GET /recipes called.");
|
||||
return ResponseEntity.ok(
|
||||
// Choose the right overload. One has a limit, other doesn't.
|
||||
limit.map(recipeService::findAll).orElseGet(recipeService::findAll)
|
||||
|
|
@ -76,6 +81,7 @@ public class RecipeController {
|
|||
*/
|
||||
@PostMapping("/recipe/{id}")
|
||||
public ResponseEntity<Recipe> updateRecipe(@PathVariable Long id, @RequestBody Recipe recipe) {
|
||||
logger.info("POST /recipe/" + id + " called.");
|
||||
return recipeService.update(id, recipe)
|
||||
.map(saved -> {
|
||||
messagingTemplate.convertAndSend(Topics.RECIPES, new UpdateRecipeMessage(saved)); // Send to WS.
|
||||
|
|
@ -96,6 +102,7 @@ public class RecipeController {
|
|||
*/
|
||||
@PutMapping("/recipe/new")
|
||||
public ResponseEntity<Recipe> createRecipe(@RequestBody Recipe recipe) {
|
||||
logger.info("POST /recipe/new called.");
|
||||
return recipeService.create(recipe)
|
||||
.map(saved -> {
|
||||
messagingTemplate.convertAndSend(Topics.RECIPES, new CreateRecipeMessage(saved)); // Send to WS.
|
||||
|
|
@ -114,6 +121,7 @@ public class RecipeController {
|
|||
*/
|
||||
@DeleteMapping("/recipe/{id}")
|
||||
public ResponseEntity<Boolean> deleteRecipe(@PathVariable Long id) {
|
||||
logger.info("DELETE /recipe/" + id + " called.");
|
||||
if (!recipeService.delete(id)) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue