Skip to content

Conversation

@ekgns33
Copy link
Contributor

@ekgns33 ekgns33 commented Apr 30, 2025

작업내역

  • 통계 데이터를 조회할때, 간략한 합산정보를 추가로 반환합니다.
  • 쿼리를 수정했습니다.
  • 매핑 로직을 작성했습니다.

*Breaking Change

  • RecordRepository 의 기간 통계 쿼리를 변경했습니다. 기존에는 SQL의 GROUPBY를 활용했습니다. 추가적인 요구사항에 따라 JPQL로 작성하려다보니 DB종속적인 함수를 사용해야했습니다. 따라서 애플리케이션에서 조립하는 방식으로 변경했습니다.

select (r.startedAt, r.endAt, r.distance) from Record where user_id = :userId 와 같이 필요한 기록 데이터만 쿼리하여 매핑했습니다. 매핑함수는 RecordFinder.class에 정의되어있으며 O(n) - 1 loop 로 매핑하도록 작성했습니다.

Summary by CodeRabbit

  • New Features
    • Added summary statistics (total time, run count, and total distance) to weekly and monthly running statistics responses.
  • Enhancements
    • Daily running statistics now provide more detailed metrics, including time and run count, alongside distance.
    • Updated data structures to include detailed timestamps and raw distance per record for improved accuracy.
  • Bug Fixes
    • Updated API response field names for clarity (e.g., distance_in_meters).
  • Tests
    • Improved test coverage to validate new summary statistics and updated response structures.

@ekgns33 ekgns33 requested a review from jeeheaG April 30, 2025 11:39
@ekgns33 ekgns33 self-assigned this Apr 30, 2025
@coderabbitai
Copy link

coderabbitai bot commented Apr 30, 2025

Walkthrough

This change refactors the way running record statistics are aggregated and presented in the application. The repository and service layers now retrieve raw record statistics with timestamps and distances, then aggregate these into daily summaries within the service. The DailyStat data structure is expanded to include additional fields for time and running count, and a new SimpleStat class is introduced to provide overall summary statistics. API response objects for weekly and monthly statistics now include both detailed daily stats and the new summary statistics. Corresponding tests and DTOs are updated to match the revised data structures and response formats.

Changes

File(s) Change Summary
src/main/java/org/runimo/runimo/records/repository/RecordRepository.java Updated repository method: replaced daily distance aggregation with retrieval of raw record stats, changed method name and return type to use new DTO.
src/main/java/org/runimo/runimo/records/service/RecordFinder.java Refactored to use new repository method and introduced helper to aggregate raw stats into daily summaries.
src/main/java/org/runimo/runimo/records/service/dto/DailyStat.java Refactored from a record to a class; added fields for time, running count, and distance; added aggregation methods and static factory.
src/main/java/org/runimo/runimo/records/service/dto/RecordStatDto.java Introduced new DTO to encapsulate raw record statistics (start/end time, distance).
src/main/java/org/runimo/runimo/records/service/dto/SimpleStat.java Added new class to aggregate and summarize total time, count, and distance from daily stats.
src/main/java/org/runimo/runimo/records/service/dto/WeeklyRecordStatResponse.java
src/main/java/org/runimo/runimo/records/service/usecases/dtos/MonthlyRecordStatResponse.java
Added a new field for SimpleStat summary in weekly and monthly response records.
src/main/java/org/runimo/runimo/records/service/usecases/RecordQueryUsecaseImpl.java Updated logic to aggregate daily stats into SimpleStat and include it in responses for weekly and monthly queries.
src/test/java/org/runimo/runimo/records/api/RecordAcceptanceTest.java Updated test assertions for new JSON field names and added checks for summary statistics in API responses.
src/test/java/org/runimo/runimo/records/service/usecases/RecordQueryUsecaseImplTest.java Updated test construction and assertions to match new DailyStat and SimpleStat structures and aggregation logic.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller
    participant RecordQueryUsecaseImpl
    participant RecordFinder
    participant RecordRepository
    participant DB

    Client->>Controller: Request weekly/monthly stats
    Controller->>RecordQueryUsecaseImpl: getUserWeekly/MonthlyRecordStat(query)
    RecordQueryUsecaseImpl->>RecordFinder: findDailyStatByUserIdBetween(userId, from, to)
    RecordFinder->>RecordRepository: findRecordStatByUserIdAndBetween(userId, from, to)
    RecordRepository->>DB: Query raw record stats
    DB-->>RecordRepository: List<RecordStatDto>
    RecordRepository-->>RecordFinder: List<RecordStatDto>
    RecordFinder->>RecordFinder: mapToDailyStatList(List<RecordStatDto>)
    RecordFinder-->>RecordQueryUsecaseImpl: List<DailyStat>
    RecordQueryUsecaseImpl->>SimpleStat: from(List<DailyStat>)
    SimpleStat-->>RecordQueryUsecaseImpl: SimpleStat
    RecordQueryUsecaseImpl-->>Controller: Response (SimpleStat + List<DailyStat>)
    Controller-->>Client: JSON response (simple_stat, daily_stats)
Loading

Poem

In fields of code where data runs,
We gather stats beneath the sun.
From daily logs to weekly sums,
Now SimpleStat and DailyStat come!
Timestamps, counts, and meters tallied,
In tests and DTOs, all rallied.
Hop, hop, hooray—our records shine,
Aggregated, clear, and fine! 🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fd4a605 and e40da5a.

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

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

🪧 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.

Support

Need help? Join our Discord community for assistance with any issues or questions.

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 sequence diagram to generate a sequence diagram of the changes in 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.

@ekgns33
Copy link
Contributor Author

ekgns33 commented Apr 30, 2025

/gemini-review

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Gemini AI Code Reviewer Comments

@@ -33,14 +33,15 @@ Slice<RunningRecord> findFirstRunOfWeek(

Choose a reason for hiding this comment

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

The query now fetches startedAt, endAt, and totalDistance.amount which are then processed in the application layer. Consider the performance implications of fetching all this data and processing it in Java code, especially for users with a large number of records. Ensure that database indexes are properly configured for the userId and startedAt fields to optimize query performance. Also, ensure that the data being fetched is not excessively large. If the number of records is very large, consider pagination or other techniques to reduce the amount of data being transferred.

@JsonIgnore
private Long runningCount;
private Long distanceInMeters;

Choose a reason for hiding this comment

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

The addData method modifies the state of the DailyStat object. Ensure that this behavior is intended and thread-safe if this object is used in a multi-threaded environment.

Copy link
Contributor

@jeeheaG jeeheaG left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!

@ekgns33 ekgns33 merged commit 7ddfe46 into main May 1, 2025
3 checks passed
@ekgns33 ekgns33 deleted the feat/mypage-simple-stat branch May 1, 2025 05:04
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.

2 participants