Skip to content
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

feat: 출결번호가 네 자리 수가 되도록 String 타입으로 수정 #858

Merged
merged 2 commits into from
Jan 30, 2025

Conversation

uwoobeat
Copy link
Member

@uwoobeat uwoobeat commented Jan 30, 2025

🌱 관련 이슈

📌 작업 내용 및 특이사항

📝 참고사항

📚 기타

Summary by CodeRabbit

  • 변경 사항
    • 출석 번호 생성 및 관리 방식 변경
    • 출석 번호의 데이터 타입을 정수(Integer)에서 문자열(String)로 수정
    • 랜덤 및 고정 출석 번호 생성기의 반환 타입 변경
    • 스터디 세션의 출석 번호 필드 타입 업데이트

@uwoobeat uwoobeat requested a review from a team as a code owner January 30, 2025 11:06
Copy link

coderabbitai bot commented Jan 30, 2025

개요

Walkthrough

이 풀 리퀘스트는 출석 번호 생성 및 관리 로직을 정수(int)에서 문자열(String) 타입으로 변경하는 작업을 포함합니다. 주요 변경 사항은 AttendanceNumberGenerator 인터페이스, RandomAttendanceNumberGenerator, StudySessionV2 클래스의 메서드 및 필드 시그니처를 수정하여 출석 번호를 네 자리 문자열로 표현하도록 합니다.

Changes

파일 변경 요약
src/.../AttendanceNumberGenerator.java generate() 메서드 반환 타입 intString 변경
src/.../RandomAttendanceNumberGenerator.java generate() 메서드 반환 타입 및 구현 intString으로 수정
src/.../StudySessionV2.java lessonAttendanceNumber 필드 및 관련 메서드 IntegerString으로 변경
src/.../StudyFactoryTest.java 테스트 코드의 FixedAttendanceNumberGenerator 메서드 및 어서션 업데이트

연결된 이슈에 대한 평가

목표 해결 여부 설명
출결번호를 네 자리 문자열로 변경 [#856] -

가능성 있는 관련 PR

제안된 라벨

✨ feature

제안된 리뷰어

  • Sangwook02
  • kckc0608

토끼의 시

🐰 출석번호야 안녕
정수에서 문자열로 변신
네 자리 수 반짝반짝
코드의 마법 펼치네! 🌟

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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. (Beta)
  • @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.

@uwoobeat uwoobeat assigned uwoobeat and unassigned uwoobeat Jan 30, 2025
Copy link

Job Summary for Gradle

Check Style and Test to Develop :: build-test
Gradle Root Project Requested Tasks Gradle Version Build Outcome Build Scan®
gdsc check 8.5 Build Scan published

Copy link

@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

🔭 Outside diff range comments (1)
src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudySessionV2.java (1)

출석번호 유효성 검증 및 메서드 반환 타입 수정이 필요합니다.

  1. createEmpty 메서드에 제안된 유효성 검증 로직 추가가 필요합니다.
  2. 메서드가 void 대신 생성된 객체를 반환하도록 수정이 필요합니다.

수정 제안:

-    public static void createEmpty(Integer position, String lessonAttendanceNumber, StudyV2 studyV2) {
+    public static StudySessionV2 createEmpty(Integer position, String lessonAttendanceNumber, StudyV2 studyV2) {
+        if (lessonAttendanceNumber == null || !lessonAttendanceNumber.matches("^\\d{4}$")) {
+            throw new IllegalArgumentException("출석번호는 네 자리 숫자여야 합니다");
+        }
-        StudySessionV2.builder()
+        return StudySessionV2.builder()
                .position(position)
                .lessonAttendanceNumber(lessonAttendanceNumber)
                .studyV2(studyV2)
                .build();
    }
🔗 Analysis chain

Line range hint 95-100: createEmpty 메서드에 유효성 검증이 필요합니다.

출석번호가 null이거나 잘못된 형식일 경우를 처리하는 검증 로직이 필요합니다.

다음과 같은 검증 로직 추가를 제안합니다:

    public static void createEmpty(Integer position, String lessonAttendanceNumber, StudyV2 studyV2) {
+       if (lessonAttendanceNumber == null || !lessonAttendanceNumber.matches("^\\d{4}$")) {
+           throw new IllegalArgumentException("출석번호는 네 자리 숫자여야 합니다");
+       }
        StudySessionV2.builder()
                .position(position)
                .lessonAttendanceNumber(lessonAttendanceNumber)
                .studyV2(studyV2)
                .build();
    }
🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Search for lessonAttendanceNumber usage and validation
echo "=== Searching for lessonAttendanceNumber usage ==="
rg "lessonAttendanceNumber" -t java -A 2 -B 2

echo -e "\n=== Searching for validation patterns in StudySessionV2 ==="
ast-grep --pattern 'if ($_ == null || !$_.matches($_)) { throw new IllegalArgumentException($_); }'

echo -e "\n=== Searching for createEmpty usage ==="
rg "createEmpty" -t java -A 2 -B 2

Length of output: 4203


Script:

#!/bin/bash
# Search for attendanceNumberGenerator implementation
echo "=== Searching for AttendanceNumberGenerator ==="
rg "AttendanceNumberGenerator" -t java -A 5 -B 5

echo -e "\n=== Searching for generate() method implementations ==="
ast-grep --pattern 'generate() {
  $$$
}'

Length of output: 8144

🧹 Nitpick comments (2)
src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/RandomAttendanceNumberGenerator.java (1)

16-20: 출석번호 형식을 일관되게 유지하도록 개선이 필요합니다.

현재 구현은 네 자리 수를 보장하지만, 형식의 일관성을 위해 String.format을 사용하는 것이 좋습니다.

다음과 같이 수정을 제안합니다:

    public String generate() {
-       return String.valueOf(SecureRandom.getInstanceStrong()
+       return String.format("%04d", SecureRandom.getInstanceStrong()
                .ints(MIN_ORIGIN, MAX_BOUND)
                .findFirst()
                .orElseThrow());
    }
src/test/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyFactoryTest.java (1)

18-21: 테스트 케이스 보완이 필요합니다.

현재는 고정된 "0000" 값만 테스트하고 있습니다. 다양한 케이스에 대한 테스트가 필요합니다.

다음과 같은 테스트 케이스 추가를 제안합니다:

@Test
void 출석번호_형식이_올바른지_검증한다() {
    // given
    StudySessionV2 session = StudySessionV2.builder()
            .position(1)
            .lessonAttendanceNumber("1234")
            .studyV2(study)
            .build();

    // then
    assertThat(session.getLessonAttendanceNumber()).matches("^\\d{4}$");
}

@Test
void 잘못된_출석번호_형식은_예외를_발생시킨다() {
    assertThatThrownBy(() -> {
        StudySessionV2.builder()
                .position(1)
                .lessonAttendanceNumber("123")  // 3자리 숫자
                .studyV2(study)
                .build();
    }).isInstanceOf(IllegalArgumentException.class);
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 64acab1 and 257998a.

📒 Files selected for processing (4)
  • src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/AttendanceNumberGenerator.java (1 hunks)
  • src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/RandomAttendanceNumberGenerator.java (1 hunks)
  • src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudySessionV2.java (3 hunks)
  • src/test/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyFactoryTest.java (2 hunks)
🔇 Additional comments (1)
src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/AttendanceNumberGenerator.java (1)

4-4: 반환 타입 변경이 적절합니다.

출석번호를 네 자리 수로 표현하기 위한 String 타입으로의 변경이 적절합니다.

@@ -42,7 +42,7 @@ public class StudySessionV2 extends BaseEntity {
// 수업 관련 필드

@Comment("수업 출석 번호")
private Integer lessonAttendanceNumber;
private String lessonAttendanceNumber;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

출석번호 유효성 검증이 필요합니다.

출석번호가 항상 네 자리 문자열 형식을 유지하도록 유효성 검증이 필요합니다.

다음과 같은 검증 로직 추가를 제안합니다:

@Pattern(regexp = "^\\d{4}$", message = "출석번호는 네 자리 숫자여야 합니다")
private String lessonAttendanceNumber;

Copy link
Member

@Sangwook02 Sangwook02 left a comment

Choose a reason for hiding this comment

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

lgtm

@uwoobeat uwoobeat merged commit dd3d474 into develop Jan 30, 2025
1 check passed
@uwoobeat uwoobeat deleted the feature/856-attendance-number-string-type branch January 30, 2025 11:44
kckc0608

This comment was marked as duplicate.

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

Successfully merging this pull request may close these issues.

✨ 출결번호가 네 자리 수가 되도록 String 타입으로 수정
3 participants