Skip to content

add some count API #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

add some count API #5

wants to merge 1 commit into from

Conversation

giangle-mfv
Copy link
Owner

@giangle-mfv giangle-mfv commented Jul 4, 2024

  1. Why this PR is needed
    This PR is needed to add new functionality to the blog application. It introduces two new endpoints to the PostController that allow users to count the total number of posts and the number of posts in a specific category. This is part of the task: https://moneyforwardvietnam.atlassian.net/browse/SCI-

  2. What I did in this PR

    • Added two new methods to the PostService interface: countAllPost() and countPostByCategory(Long categoryId).
    • Implemented these methods in the PostServiceImpl class.
    • Added two new endpoints to the PostController: GET /count and GET /category/{id}/count. These endpoints call the new methods in the PostService.
  3. How to check

    • Start the application and make a GET request to /count to get the total number of posts.
    • Make a GET request to /category/{id}/count to get the number of posts in a specific category.
  4. Checklist

    • Pass all current unit-test
    • I have performed a self-review and test of my code
    • Check sql generated (if have) to ensure perf issue
    • Do you have any new properties? If then you need to create properties on: task_definition_app.json, task_definition_app_beta.json and AWS paramStore
    • If this is PR to STG/PROD plz prepare liquibase script

Copy link

gitstream-cm bot commented Jul 4, 2024

This PR is missing a Jira ticket reference in the title or description.
Please add a Jira ticket reference to the title or description of this PR.

Copy link

gitstream-cm bot commented Jul 4, 2024

🥷 Code experts: no user matched threshold 10

See details

src/main/java/com/springboot/blog/controller/PostController.java

Knowledge based on git-blame:

src/main/java/com/springboot/blog/service/PostService.java

Knowledge based on git-blame:

src/main/java/com/springboot/blog/service/impl/PostServiceImpl.java

Knowledge based on git-blame:

To learn more about /:\ gitStream - Visit our Docs

@@ -66,6 +66,20 @@ public PostResponse getAllPosts(
return postService.getAllPosts(pageNo, pageSize, sortBy, sortDir);
}

@Operation(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The summary and description in the @Operation annotation are incorrect. They should describe the actual functionality of the method, which is to count all posts.

)
// get post by id
@GetMapping("/count")
public int countAllPost() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider returning a ResponseEntity instead of a raw integer. This would allow you to include HTTP status codes and potentially other information in the response.

@@ -129,4 +143,9 @@
List<PostDto> postDtos = postService.getPostsByCategory(categoryId);
return ResponseEntity.ok(postDtos);
}

@GetMapping("/category/{id}/count")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider wrapping the returned integer in a ResponseEntity for consistency with the other endpoints in your controller.

@@ -129,4 +143,9 @@
List<PostDto> postDtos = postService.getPostsByCategory(categoryId);
return ResponseEntity.ok(postDtos);
}

@GetMapping("/category/{id}/count")
public int countPostsByCategory(@PathVariable("id") Long categoryId){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add @Valid annotation to validate the categoryId path variable.

@@ -118,6 +118,16 @@ public List<PostDto> getPostsByCategory(Long categoryId) {
.collect(Collectors.toList());
}

@Override
public int countAllPost() {
return 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The countAllPost() method currently returns 0. Please implement the logic to return the actual count of all posts.


@Override
public int countPostByCategory(Long categoryId) {
return 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The countPostByCategory(Long categoryId) method currently returns 0. Please implement the logic to return the actual count of posts in the specified category.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant