Skip to content

Commit

Permalink
add some count API
Browse files Browse the repository at this point in the history
  • Loading branch information
giangle-mfv committed Jul 4, 2024
1 parent 5ecf097 commit c27955d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/com/springboot/blog/controller/PostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -129,4 +143,9 @@ public ResponseEntity<List<PostDto>> getPostsByCategory(@PathVariable("id") Long
List<PostDto> postDtos = postService.getPostsByCategory(categoryId);
return ResponseEntity.ok(postDtos);
}

@GetMapping("/category/{id}/count")
public int countPostsByCategory(@PathVariable("id") Long categoryId){
return postService.countPostByCategory(categoryId);
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/springboot/blog/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public interface PostService {
void deletePostById(long id);

List<PostDto> getPostsByCategory(Long categoryId);

int countAllPost();

int countPostByCategory(Long categoryId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ public List<PostDto> 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);
Expand Down

0 comments on commit c27955d

Please sign in to comment.