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