Skip to content

[Feat/runimo stat] 러니모 통계 데이터 갱신 로직 추가, 알 종류 GRASSLAND 제거#57

Merged
jeeheaG merged 6 commits intomainfrom
feat/runimo-stat
Apr 17, 2025
Merged

[Feat/runimo stat] 러니모 통계 데이터 갱신 로직 추가, 알 종류 GRASSLAND 제거#57
jeeheaG merged 6 commits intomainfrom
feat/runimo-stat

Conversation

@jeeheaG
Copy link
Copy Markdown
Contributor

@jeeheaG jeeheaG commented Apr 16, 2025

[작업 내용]

  • 달리기 기록 save 시 러니모 통계 데이터 update 로직 추가
    : 메인화면에 러니모 데이터 보여주는 걸로 변경하는 작업은 다훈님이 이미 해두신 것 같더라구요! 고생하셨습니다
  • 알 종류 GRASSLAND 제거
    : 프론트 요청에 따라 EggType enum 클래스에서 GRASSLAND 항목을 주석처리했습니다.

Summary by CodeRabbit

  • New Features
    • Added the ability to update Runimo statistics, including total run count and distance, after a record is created.
  • Bug Fixes
    • Adjusted test expectations to reflect the updated number of Runimo groups.
  • Chores
    • Removed the "GRASSLAND" egg type from available options.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2025

Walkthrough

This update introduces a new service, RunimoService, responsible for updating statistics for a Runimo entity. The RecordCreateUsecaseImpl class is modified to use this service, enabling the update of a user's main Runimo statistics whenever a new record is created. The Runimo domain class gains a method to increment run counts and distances. Additionally, the GRASSLAND enum constant is removed from EggType, and a related test is updated to reflect the new expected data size. The test SQL data is also extended to include main_runimo_id and initial Runimo data.

Changes

File(s) Change Summary
src/main/java/org/runimo/runimo/runimo/service/RunimoService.java Added new RunimoService class with transactional logic to update Runimo statistics.
src/main/java/org/runimo/runimo/records/service/usecases/RecordCreateUsecaseImpl.java Injected RunimoService and added a call to update Runimo stats during record creation.
src/main/java/org/runimo/runimo/runimo/domain/Runimo.java Added updateStat(Long distanceInMeters) method to increment run count and total distance.
src/main/java/org/runimo/runimo/item/domain/EggType.java Commented out the GRASSLAND enum constant, effectively removing it from available values.
src/test/java/org/runimo/runimo/runimo/controller/RunimoControllerTest.java Updated test assertion to expect 2 elements in "runimo_groups" instead of 3.
src/test/resources/sql/user_item_test_data.sql Added main_runimo_id column in user inserts and inserted initial Runimo data for testing.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant RecordCreateUsecaseImpl
    participant UserStatService
    participant RunimoService
    participant RunimoRepository
    participant Runimo

    User->>RecordCreateUsecaseImpl: submit RecordCreateCommand
    RecordCreateUsecaseImpl->>UserStatService: updateUserStats(userId, distance)
    RecordCreateUsecaseImpl->>RunimoService: updateRunimoStat(mainRunimoId, distance)
    RunimoService->>RunimoRepository: findById(mainRunimoId)
    RunimoRepository-->>RunimoService: return Runimo
    RunimoService->>Runimo: updateStat(distance)
    RecordCreateUsecaseImpl->>RecordRepository: save(record)
Loading

Poem

Hopping through code with a joyful cheer,
Runimo stats now update when records appear!
The GRASSLAND egg has hopped away,
Only two groups in tests today.
With services new and methods bright,
This rabbit codes deep into the night!
🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 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 8bb8a72 and 6aef495.

📒 Files selected for processing (1)
  • src/main/java/org/runimo/runimo/records/service/usecases/RecordCreateUsecaseImpl.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/runimo/runimo/records/service/usecases/RecordCreateUsecaseImpl.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.

@jeeheaG jeeheaG self-assigned this Apr 16, 2025
@jeeheaG jeeheaG requested a review from ekgns33 April 16, 2025 13:48
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: 0

🧹 Nitpick comments (2)
src/main/java/org/runimo/runimo/runimo/service/RunimoService.java (2)

18-24: Consider adding parameter validation and logging

The method is functionally correct, but consider these enhancements:

  1. Add validation to ensure distanceInMeters is not negative
  2. Add logging to track when these statistics are updated and by how much
@Transactional
public void updateRunimoStat(Long runimoId, Long distanceInMeters) {
+    if (distanceInMeters < 0) {
+        throw new IllegalArgumentException("Distance cannot be negative");
+    }
+    
    Runimo runimo = runimoRepository.findById(runimoId)
        .orElseThrow(() -> RunimoException.of(RunimoHttpResponseCode.RUNIMO_NOT_FOUND));

    runimo.updateStat(distanceInMeters);
+    // Consider adding logging: log.info("Updated stats for Runimo {}: added {} meters", runimoId, distanceInMeters);
}

19-19: Consider using primitive type for distance parameter

Since distanceInMeters is unlikely to be null in normal operations, consider using the primitive long type instead of Long to avoid potential null pointer exceptions and improve performance slightly.

- public void updateRunimoStat(Long runimoId, Long distanceInMeters) {
+ public void updateRunimoStat(Long runimoId, long distanceInMeters) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a838b17 and 0ab2689.

📒 Files selected for processing (5)
  • src/main/java/org/runimo/runimo/item/domain/EggType.java (1 hunks)
  • src/main/java/org/runimo/runimo/records/service/usecases/RecordCreateUsecaseImpl.java (2 hunks)
  • src/main/java/org/runimo/runimo/runimo/domain/Runimo.java (1 hunks)
  • src/main/java/org/runimo/runimo/runimo/service/RunimoService.java (1 hunks)
  • src/test/java/org/runimo/runimo/runimo/controller/RunimoControllerTest.java (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/main/java/org/runimo/runimo/records/service/usecases/RecordCreateUsecaseImpl.java (1)
src/main/java/org/runimo/runimo/runimo/service/usecase/RunimoUsecaseImpl.java (1)
  • Transactional (23-62)
🔇 Additional comments (5)
src/main/java/org/runimo/runimo/item/domain/EggType.java (1)

11-12: Clean removal of GRASSLAND egg type

The GRASSLAND egg type has been properly removed by commenting it out and adding a semicolon to maintain valid enum syntax. This aligns with the PR objective to remove this egg type following frontend requirements.

src/test/java/org/runimo/runimo/runimo/controller/RunimoControllerTest.java (1)

95-95: Test expectation correctly updated

The test expectation has been properly adjusted to expect 2 runimo groups instead of 3, which is consistent with the removal of the GRASSLAND egg type from the EggType enum.

src/main/java/org/runimo/runimo/runimo/domain/Runimo.java (1)

44-47: Concise implementation for updating Runimo statistics

The new updateStat method provides a clean way to increment the run count and accumulate distance metrics for a Runimo entity. This implementation correctly supports the PR objective to update Runimo statistical data when running records are saved.

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

8-8: Properly integrated Runimo statistics update

The Runimo statistics update has been correctly integrated into the record creation flow. The code now updates both user statistics and Runimo statistics when a new running record is created, which ensures the Runimo data displayed on the main screen reflects the latest running records as stated in the PR objectives.

Also applies to: 22-22, 30-30

src/main/java/org/runimo/runimo/runimo/service/RunimoService.java (1)

1-26: Well-structured service implementation - looks good!

The RunimoService is well-designed with appropriate transaction management and error handling. The implementation correctly updates Runimo statistics when a new running record is saved, which aligns with the PR objectives.

Copy link
Copy Markdown
Contributor

@ekgns33 ekgns33 left a comment

Choose a reason for hiding this comment

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

감사합니다! 고생하셨어용

@jeeheaG jeeheaG merged commit 536cef1 into main Apr 17, 2025
2 checks passed
@ekgns33 ekgns33 deleted the feat/runimo-stat branch April 17, 2025 12:32
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