Skip to content

Commit

Permalink
Fixed version v.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pocemucka committed May 14, 2024
1 parent f5bfef9 commit 9da08fc
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ public ResponseEntity<?> getBookmarks(@PathVariable Integer recipeId) {


@PostMapping("/recipes/{recipeId}/comments")
public ResponseEntity<?> addComment(@PathVariable Integer recipeId, @RequestBody String username, @RequestBody String comment) {
public ResponseEntity<?> addComment(@PathVariable Integer recipeId, @RequestBody String comment) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null || authentication.getPrincipal().equals("anonymousUser")) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Authentication required.");
}

String username = authentication.getName(); // Assuming the username can be obtained like this

boolean savedComment = recipeService.addComment(recipeId, username, comment);
if (savedComment != false) {
return ResponseEntity.status(HttpStatus.CREATED).body(savedComment);
Expand Down

0 comments on commit 9da08fc

Please sign in to comment.