MME-36 Add recipes/meta/count endpoint and fix counting bug.
This commit is contained in:
parent
ca926d9ada
commit
0d80c92850
@ -71,7 +71,7 @@ public interface RecipeRepository extends JpaRepository<Recipe, Integer> {
|
|||||||
|
|
||||||
int countByIsPublicIsTrue();
|
int countByIsPublicIsTrue();
|
||||||
|
|
||||||
@Query("SELECT count(r) FROM Recipe r WHERE ?1 MEMBER OF r.viewers OR r.isPublic IS TRUE")
|
@Query("SELECT count(r) FROM Recipe r WHERE ?1 = r.owner OR ?1 MEMBER OF r.viewers OR r.isPublic IS TRUE")
|
||||||
int countViewableBy(User viewer);
|
int countViewableBy(User viewer);
|
||||||
|
|
||||||
void deleteRecipeByOwnerUsernameAndSlug(String username, String slug);
|
void deleteRecipeByOwnerUsernameAndSlug(String username, String slug);
|
||||||
|
|||||||
@ -100,6 +100,17 @@ public class RecipesController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/meta/count")
|
||||||
|
public ResponseEntity<Map<String, Object>> getRecipeCount(@AuthenticationPrincipal User user) {
|
||||||
|
final int count;
|
||||||
|
if (user == null) {
|
||||||
|
count = this.recipeService.countPublicRecipes();
|
||||||
|
} else {
|
||||||
|
count = this.recipeService.countViewableBy(user);
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(Map.of("count", count));
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public ResponseEntity<Map<String, Object>> searchRecipes(
|
public ResponseEntity<Map<String, Object>> searchRecipes(
|
||||||
@RequestBody(required = false) RecipeSearchBody recipeSearchBody,
|
@RequestBody(required = false) RecipeSearchBody recipeSearchBody,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user