MME-34 Add recipe comments count endpoint.

This commit is contained in:
Jesse Brault 2026-02-20 18:16:59 -06:00
parent 1d98d226a7
commit 20865a1b5a
3 changed files with 13 additions and 2 deletions

View File

@ -190,6 +190,16 @@ public class RecipesController {
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")
public ResponseEntity<RecipeCommentView> addComment(
@PathVariable String username,

View File

@ -10,5 +10,5 @@ public interface RecipeCommentService {
Slice<RecipeCommentView> getComments(String recipeUsername, String recipeSlug, Pageable pageable, User viewer);
RecipeComment update(Integer commentId, User viewer, RecipeCommentUpdateSpec spec) ;
void delete(Integer commentId, User modifier);
int countComments(String recipeUsername, String recipeSlug);
int countComments(String recipeUsername, String recipeSlug, User viewer);
}

View File

@ -106,7 +106,8 @@ public class RecipeCommentServiceImpl implements RecipeCommentService {
}
@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);
}