MME-34 Add recipe comments count endpoint.
This commit is contained in:
parent
1d98d226a7
commit
20865a1b5a
@ -190,6 +190,16 @@ public class RecipesController {
|
|||||||
return ResponseEntity.ok(this.sliceViewService.getSliceView(slice));
|
return ResponseEntity.ok(this.sliceViewService.getSliceView(slice));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{username}/{slug}/comments/count")
|
||||||
|
public ResponseEntity<Map<String, Object>> getCommentsCount(
|
||||||
|
@PathVariable String username,
|
||||||
|
@PathVariable String slug,
|
||||||
|
@Nullable @AuthenticationPrincipal User principal
|
||||||
|
) {
|
||||||
|
final int count = this.recipeCommentService.countComments(username, slug, principal);
|
||||||
|
return ResponseEntity.ok(Map.of("count", count));
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/{username}/{slug}/comments")
|
@PostMapping("/{username}/{slug}/comments")
|
||||||
public ResponseEntity<RecipeCommentView> addComment(
|
public ResponseEntity<RecipeCommentView> addComment(
|
||||||
@PathVariable String username,
|
@PathVariable String username,
|
||||||
|
|||||||
@ -10,5 +10,5 @@ public interface RecipeCommentService {
|
|||||||
Slice<RecipeCommentView> getComments(String recipeUsername, String recipeSlug, Pageable pageable, User viewer);
|
Slice<RecipeCommentView> getComments(String recipeUsername, String recipeSlug, Pageable pageable, User viewer);
|
||||||
RecipeComment update(Integer commentId, User viewer, RecipeCommentUpdateSpec spec) ;
|
RecipeComment update(Integer commentId, User viewer, RecipeCommentUpdateSpec spec) ;
|
||||||
void delete(Integer commentId, User modifier);
|
void delete(Integer commentId, User modifier);
|
||||||
int countComments(String recipeUsername, String recipeSlug);
|
int countComments(String recipeUsername, String recipeSlug, User viewer);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -106,7 +106,8 @@ public class RecipeCommentServiceImpl implements RecipeCommentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int countComments(String recipeUsername, String recipeSlug) {
|
@PreAuthorize("@recipeSecurity.isViewableBy(#recipeUsername, #recipeSlug, #viewer)")
|
||||||
|
public int countComments(String recipeUsername, String recipeSlug, User viewer) {
|
||||||
return this.recipeCommentRepository.countByUsernameAndSlug(recipeUsername, recipeSlug);
|
return this.recipeCommentRepository.countByUsernameAndSlug(recipeUsername, recipeSlug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user