Skip to content

[Feat/set default title]#65

Merged
ekgns33 merged 2 commits intomainfrom
feat/set-default-title
Apr 22, 2025
Merged

[Feat/set default title]#65
ekgns33 merged 2 commits intomainfrom
feat/set-default-title

Conversation

@ekgns33
Copy link
Copy Markdown
Contributor

@ekgns33 ekgns33 commented Apr 22, 2025

작업 내역

  • 사용자가 제목을 입력하지 않으면 시간대에 따라 기본 제목을 설정하는 기능 구현

  • DefaultTitle Enum으로 정의

  • 테스트코드 작성

Summary by CodeRabbit

  • New Features

    • Automatically assigns a default title to running records based on the start time if no title is provided.
  • Tests

    • Added unit tests to verify that default titles are correctly set according to the time of day when creating a running record.

@ekgns33 ekgns33 requested a review from jeeheaG April 22, 2025 10:50
@ekgns33 ekgns33 self-assigned this Apr 22, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2025

Walkthrough

A new enum, DefaultTitle, has been introduced to categorize times of day and provide corresponding default titles in Korean. The RunningRecord class now automatically assigns a default title based on the start time if none is provided during object creation. Unit tests have been added to verify that the correct default titles are set depending on the start time, ensuring the new logic is properly integrated and functions as expected.

Changes

File(s) Change Summary
src/main/java/org/runimo/runimo/records/domain/DefaultTitle.java Introduced new enum DefaultTitle with time-based constants and logic to select a title based on time of day.
src/main/java/org/runimo/runimo/records/domain/RunningRecord.java Added logic to automatically set a default title if none is provided, using the new DefaultTitle enum.
src/test/java/org/runimo/runimo/records/domain/RunningRecordTest.java Added unit tests for default title assignment logic in RunningRecord.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RunningRecord
    participant DefaultTitle

    Client->>RunningRecord: Create instance (title not provided)
    RunningRecord->>DefaultTitle: fromTime(startedAt)
    DefaultTitle-->>RunningRecord: Return appropriate title
    RunningRecord-->>Client: Instance with default title set
Loading

Poem

In the morning or at midnight’s call,
A title appears, no need to stall.
From code to test, the logic is tight—
Default titles set just right.
Now every run, at any hour,
Gets a fitting name with gentle power.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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: 1

🧹 Nitpick comments (4)
src/main/java/org/runimo/runimo/records/domain/DefaultTitle.java (1)

6-31: Well-structured enum implementation for default titles based on time of day

This is a clean implementation of an enum that provides default Korean titles based on the time of day. The time ranges are properly defined without gaps or overlaps.

Consider adding JavaDoc comments to document the purpose of this enum and its methods:

 @Getter
+/**
+ * Provides default titles for running records based on the time of day.
+ * The titles are in Korean and correspond to morning, afternoon, night and midnight runs.
+ */
 public enum DefaultTitle {
     MORNING("개운한 아침런"),
     AFTERNOON("활기찬 오후런"),
     NIGHT("두근두근 저녁런"),
     MIDNIGHT("고요한 심야런");

     private final String title;

     DefaultTitle(String title) {
         this.title = title;
     }

+    /**
+     * Determines the appropriate default title based on the time of day.
+     * @param time The time to evaluate
+     * @return The corresponding DefaultTitle enum constant
+     */
     public static DefaultTitle fromTime(LocalDateTime time) {
+        if (time == null) {
+            throw new IllegalArgumentException("Time cannot be null");
+        }
         int hour = time.getHour();
         if (hour < 6) {
             return MIDNIGHT;
         } else if (hour < 12) {
             return MORNING;
         } else if (hour < 18) {
             return AFTERNOON;
         } else {
             return NIGHT;
         }
     }
 }
src/test/java/org/runimo/runimo/records/domain/RunningRecordTest.java (3)

14-26: Effective test for default title assignment

This test verifies that a default title is assigned when one is not provided, which is the primary functionality being added.

Consider enhancing this test to verify the specific title that was set, not just that it's non-null:

 @Test
 void 제목을_입력하지_않으면_기본_제목_설정() {
+    // Given
     RunningRecord runningRecordWithoutTitle = RunningRecord.builder()
         .userId(1L)
         .startedAt(LocalDateTime.now())
         .endAt(LocalDateTime.now().plusHours(1))
         .isRewarded(false)
         .totalDistance(new Distance(1000L))
         .pacePerKm(null)
         .build();

+    // Then
     assertNotNull(runningRecordWithoutTitle.getTitle());
+    
+    // Verify the title matches one of the expected default titles based on time
+    LocalDateTime startTime = runningRecordWithoutTitle.getStartedAt();
+    String expectedTitle = DefaultTitle.fromTime(startTime).getTitle();
+    assertEquals(expectedTitle, runningRecordWithoutTitle.getTitle());
 }

29-51: Well-structured parameterized test for time-based default titles

This test effectively verifies that different default titles are set based on the time of day, covering all four time categories. The test data is clear and comprehensive.

Consider these small improvements for better test structure:

 @ParameterizedTest(name = "{0}시에 달리면 {1} 제목이 설정됨")
 @CsvSource({
     "2020-01-01T07:00:00, 개운한 아침런",
     "2020-01-01T13:00:00, 활기찬 오후런",
     "2020-01-01T19:00:00, 두근두근 저녁런",
     "2020-01-01T01:00:00, 고요한 심야런"
 })
 void 기본_제목_설정시_시간에_따라_제목이_달라진다(String dateTimeStr, String expectedTitle) {
     // given
     LocalDateTime runAt = LocalDateTime.parse(dateTimeStr);

+    // when
     RunningRecord runningRecordWithoutTitle = RunningRecord.builder()
         .userId(1L)
         .startedAt(runAt)
         .endAt(runAt.plusHours(1))
         .isRewarded(false)
         .totalDistance(new Distance(1000L))
         .pacePerKm(null)
         .build();

     // then
     assertEquals(expectedTitle, runningRecordWithoutTitle.getTitle());
 }

12-52: Consider adding a test to verify that user-provided titles are preserved

The current tests verify that default titles are set when none is provided, but there's no test to verify that explicitly provided titles are preserved.

Add a test to verify that user-provided titles are not overridden:

@Test
void 제목을_입력하면_기본_제목으로_변경되지_않음() {
    // Given
    String userProvidedTitle = "My Custom Title";
    
    // When
    RunningRecord runningRecord = RunningRecord.builder()
        .userId(1L)
        .title(userProvidedTitle)
        .startedAt(LocalDateTime.now())
        .endAt(LocalDateTime.now().plusHours(1))
        .isRewarded(false)
        .totalDistance(new Distance(1000L))
        .pacePerKm(null)
        .build();

    // Then
    assertEquals(userProvidedTitle, runningRecord.getTitle());
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b2fcfee and 2cb9143.

📒 Files selected for processing (3)
  • src/main/java/org/runimo/runimo/records/domain/DefaultTitle.java (1 hunks)
  • src/main/java/org/runimo/runimo/records/domain/RunningRecord.java (2 hunks)
  • src/test/java/org/runimo/runimo/records/domain/RunningRecordTest.java (1 hunks)
🔇 Additional comments (1)
src/main/java/org/runimo/runimo/records/domain/RunningRecord.java (1)

58-58: Good placement of default title setting logic

The call to setTitleIfNull() is properly placed at the end of the constructor, ensuring all necessary fields are initialized before using them.

Comment thread src/main/java/org/runimo/runimo/records/domain/RunningRecord.java
@ekgns33 ekgns33 merged commit 7d50f11 into main Apr 22, 2025
3 checks passed
@ekgns33 ekgns33 deleted the feat/set-default-title branch April 22, 2025 11:03
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