Skip to content

[Feat/fetch record pagination]#62

Merged
ekgns33 merged 3 commits intomainfrom
feat/fetch-record-pagination
Apr 20, 2025
Merged

[Feat/fetch record pagination]#62
ekgns33 merged 3 commits intomainfrom
feat/fetch-record-pagination

Conversation

@ekgns33
Copy link
Copy Markdown
Contributor

@ekgns33 ekgns33 commented Apr 19, 2025

작업내역

notify

Summary by CodeRabbit

  • New Features

    • Added a new API endpoint for users to retrieve their personal running records with pagination support.
    • Introduced a simplified summary view for running records, including details like record ID, title, start time, distance, duration, and average pace.
  • Tests

    • Added an acceptance test to verify paginated retrieval of user records via the new API endpoint.

@ekgns33 ekgns33 self-assigned this Apr 19, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 19, 2025

Walkthrough

A new paginated API endpoint was introduced to allow users to retrieve their own running records in a simplified view. This involved adding a new controller method, extending the repository and service layers with pagination support, and introducing new DTO classes for the simplified record view and its response. The use case interface and its implementation were updated to support the new functionality. Additionally, an acceptance test was added to verify the paginated retrieval of user records through the new endpoint.

Changes

File(s) Change Summary
src/main/java/org/runimo/runimo/records/controller/RecordController.java Added a new GET API endpoint /api/v1/records/me for paginated retrieval of user's records.
src/main/java/org/runimo/runimo/records/repository/RecordRepository.java Added a method to fetch user's records with pagination and ordering by start time.
src/main/java/org/runimo/runimo/records/service/RecordFinder.java Added a method to retrieve paginated, simplified user records.
src/main/java/org/runimo/runimo/records/service/dto/RecordSimpleView.java Introduced a new DTO class for a summarized view of a running record.
src/main/java/org/runimo/runimo/records/service/dto/RecordSimpleViewResponse.java Introduced a new record DTO to encapsulate a list of simplified record views.
src/main/java/org/runimo/runimo/records/service/usecases/RecordQueryUsecase.java Added a method signature for paginated retrieval of user's simplified records.
src/main/java/org/runimo/runimo/records/service/usecases/RecordQueryUsecaseImpl.java Implemented the new use case method for paginated record retrieval.
src/test/java/org/runimo/runimo/records/api/RecordAcceptanceTest.java Added an acceptance test for the paginated user records endpoint.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller
    participant Usecase
    participant Service
    participant Repository

    Client->>Controller: GET /api/v1/records/me?page=X&size=Y
    Controller->>Usecase: getUserRecordSimpleView(userId, page, size)
    Usecase->>Service: findRecordSimpleViewByUserId(userId, page, size)
    Service->>Repository: findRecordByUserIdOrderByStartedAtDesc(userId, pageable)
    Repository-->>Service: List<RunningRecord>
    Service-->>Usecase: List<RecordSimpleView>
    Usecase-->>Controller: RecordSimpleViewResponse
    Controller-->>Client: SuccessResponse<RecordSimpleViewResponse>
Loading

Poem

In the meadow of code, a new path appears,
Where rabbits can hop through their running years.
With pages and sizes, their stories unfold,
Each record retrieved, each memory retold.
Now with a hop, a skip, and a test so bright,
Paginated records are just a GET away—oh what a delight!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a61e73b and ebb5146.

📒 Files selected for processing (2)
  • src/main/java/org/runimo/runimo/records/repository/RecordRepository.java (1 hunks)
  • src/main/java/org/runimo/runimo/records/service/RecordFinder.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/java/org/runimo/runimo/records/service/RecordFinder.java
  • src/main/java/org/runimo/runimo/records/repository/RecordRepository.java

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (4)
src/main/java/org/runimo/runimo/records/repository/RecordRepository.java (1)

46-46: Consider returning Page or Slice for better pagination support

The method returns a simple List which doesn't include pagination metadata (total elements, total pages, etc.). This makes it harder for clients to implement pagination controls.

Consider changing the return type to provide more comprehensive pagination information:

-List<RunningRecord> findRecordSimpleViewByUserIdOrderByStartedAtDesc(Long id, Pageable pageable);
+Page<RunningRecord> findRecordSimpleViewByUserIdOrderByStartedAtDesc(Long id, Pageable pageable);

Or if you prefer not to count the total number of records (for performance reasons):

-List<RunningRecord> findRecordSimpleViewByUserIdOrderByStartedAtDesc(Long id, Pageable pageable);
+Slice<RunningRecord> findRecordSimpleViewByUserIdOrderByStartedAtDesc(Long id, Pageable pageable);
src/main/java/org/runimo/runimo/records/service/usecases/RecordQueryUsecase.java (1)

18-18: Consider encapsulating pagination parameters

The method exposes raw pagination parameters at the interface level. This approach works but is less flexible than using a more structured parameter object.

Consider using a PageRequest or custom request DTO to encapsulate pagination parameters:

-RecordSimpleViewResponse getUserRecordSimpleView(Long id, int page, int size);
+RecordSimpleViewResponse getUserRecordSimpleView(Long id, Pageable pageable);

Or with a request DTO:

-RecordSimpleViewResponse getUserRecordSimpleView(Long id, int page, int size);
+RecordSimpleViewResponse getUserRecordSimpleView(UserRecordRequest request);

Where UserRecordRequest could include additional filtering options in the future.

src/main/java/org/runimo/runimo/records/service/RecordFinder.java (1)

60-68: Consider explicitly specifying the sort order in the Pageable object.

While the repository method name suggests ordering by startedAt descending, it would be more maintainable to explicitly include the sort order in the Pageable object rather than relying on the method name convention.

-        Pageable pageable = PageRequest.of(page, size);
+        Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "startedAt"));
src/main/java/org/runimo/runimo/records/service/dto/RecordSimpleView.java (1)

11-21: Fix spelling error and add schema documentation to all fields.

There's a spelling error in the field name and inconsistent use of OpenAPI schema annotations.

  1. The field averagePaceInMiliseconds should be averagePaceInMilliseconds (with double "l")
  2. For consistency, add @Schema annotations with descriptions to all fields, not just the ID field
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f3c4f3 and a61e73b.

📒 Files selected for processing (8)
  • src/main/java/org/runimo/runimo/records/controller/RecordController.java (2 hunks)
  • src/main/java/org/runimo/runimo/records/repository/RecordRepository.java (1 hunks)
  • src/main/java/org/runimo/runimo/records/service/RecordFinder.java (2 hunks)
  • src/main/java/org/runimo/runimo/records/service/dto/RecordSimpleView.java (1 hunks)
  • src/main/java/org/runimo/runimo/records/service/dto/RecordSimpleViewResponse.java (1 hunks)
  • src/main/java/org/runimo/runimo/records/service/usecases/RecordQueryUsecase.java (2 hunks)
  • src/main/java/org/runimo/runimo/records/service/usecases/RecordQueryUsecaseImpl.java (2 hunks)
  • src/test/java/org/runimo/runimo/records/api/RecordAcceptanceTest.java (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/main/java/org/runimo/runimo/records/service/dto/RecordSimpleViewResponse.java (1)
src/main/java/org/runimo/runimo/records/service/dto/RecordSimpleView.java (1)
  • Schema (11-45)
src/main/java/org/runimo/runimo/records/controller/RecordController.java (1)
src/main/java/org/runimo/runimo/records/service/dto/RecordSimpleView.java (1)
  • Schema (11-45)
🔇 Additional comments (4)
src/test/java/org/runimo/runimo/records/api/RecordAcceptanceTest.java (1)

266-283: Test implementation looks good.

The test properly verifies the pagination functionality of the new endpoint by:

  1. Setting up test data with the SQL script
  2. Authenticating with a proper token
  3. Making a request with appropriate pagination parameters (page=0, size=5)
  4. Verifying the correct HTTP status and response body

The test covers the core functionality of the new paginated endpoint.

src/main/java/org/runimo/runimo/records/controller/RecordController.java (1)

142-157: Controller implementation is clean and well-structured.

The endpoint is properly annotated with OpenAPI documentation, has sensible defaults for pagination parameters, and correctly uses the service layer. The implementation is solid.

src/main/java/org/runimo/runimo/records/service/dto/RecordSimpleView.java (2)

23-33: Builder implementation is good.

The private constructor with the Builder pattern is a good approach for creating immutable DTOs.


35-44: Static factory method implementation is clean.

The static factory method for converting domain entities to DTOs is well-implemented, using the builder pattern effectively to create a clear mapping.

Comment thread src/main/java/org/runimo/runimo/records/repository/RecordRepository.java Outdated
@ekgns33 ekgns33 merged commit b2fcfee into main Apr 20, 2025
3 checks passed
@ekgns33 ekgns33 deleted the feat/fetch-record-pagination branch April 20, 2025 13:44
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