From c27955d3615ee21e81ecdca2313700e387384e48 Mon Sep 17 00:00:00 2001 From: Coffee Date: Thu, 4 Jul 2024 13:12:03 +0700 Subject: [PATCH] add some count API --- .../blog/controller/PostController.java | 19 +++++++++++++++++++ .../springboot/blog/service/PostService.java | 5 +++++ .../blog/service/impl/PostServiceImpl.java | 10 ++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/main/java/com/springboot/blog/controller/PostController.java b/src/main/java/com/springboot/blog/controller/PostController.java index e9558b68..f8c3658a 100644 --- a/src/main/java/com/springboot/blog/controller/PostController.java +++ b/src/main/java/com/springboot/blog/controller/PostController.java @@ -66,6 +66,20 @@ public PostResponse getAllPosts( return postService.getAllPosts(pageNo, pageSize, sortBy, sortDir); } + @Operation( + summary = "Get Post By Id REST API", + description = "Get Post By Id REST API is used to get single post from the database" + ) + @ApiResponse( + responseCode = "200", + description = "Http Status 200 SUCCESS" + ) + // get post by id + @GetMapping("/count") + public int countAllPost() { + return postService.countAllPost(); + } + @Operation( summary = "Get Post By Id REST API", description = "Get Post By Id REST API is used to get single post from the database" @@ -129,4 +143,9 @@ public ResponseEntity> getPostsByCategory(@PathVariable("id") Long List postDtos = postService.getPostsByCategory(categoryId); return ResponseEntity.ok(postDtos); } + + @GetMapping("/category/{id}/count") + public int countPostsByCategory(@PathVariable("id") Long categoryId){ + return postService.countPostByCategory(categoryId); + } } diff --git a/src/main/java/com/springboot/blog/service/PostService.java b/src/main/java/com/springboot/blog/service/PostService.java index 10749d29..cce91f9b 100644 --- a/src/main/java/com/springboot/blog/service/PostService.java +++ b/src/main/java/com/springboot/blog/service/PostService.java @@ -17,4 +17,9 @@ public interface PostService { void deletePostById(long id); List getPostsByCategory(Long categoryId); + + int countAllPost(); + + int countPostByCategory(Long categoryId); + } diff --git a/src/main/java/com/springboot/blog/service/impl/PostServiceImpl.java b/src/main/java/com/springboot/blog/service/impl/PostServiceImpl.java index 866ee5bc..ef00263b 100644 --- a/src/main/java/com/springboot/blog/service/impl/PostServiceImpl.java +++ b/src/main/java/com/springboot/blog/service/impl/PostServiceImpl.java @@ -118,6 +118,16 @@ public List getPostsByCategory(Long categoryId) { .collect(Collectors.toList()); } + @Override + public int countAllPost() { + return 0; + } + + @Override + public int countPostByCategory(Long categoryId) { + return 0; + } + // convert Entity into DTO private PostDto mapToDTO(Post post){ PostDto postDto = mapper.map(post, PostDto.class);