-
Notifications
You must be signed in to change notification settings - Fork 1
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: 스터디 과제 제출하기 V2 API 구현 #938
Conversation
Warning Rate limit exceeded@uwoobeat has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 58 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough이번 PR은 학생 과제 제출 이력을 관리하기 위한 새로운 기능을 추가합니다. 주요 변경사항으로는 HTTP POST를 처리하는 Changes
Sequence Diagram(s)sequenceDiagram
participant U as 사용자
participant C as StudentAssginmentHistoryControllerV2
participant S as StudentAssignmentHistoryServiceV2
participant V as AssignmentHistoryValidatorV2
participant G as AssignmentHistoryGraderV2
participant R as AssignmentHistoryV2Repository
participant Repo as StudyV2RepositoryImpl
participant Util as MemberUtil
participant GH as GitHubClient
U->>C: POST /v2/assignment-histories/submit\n(studySessionId)
C->>S: submitAssignment(studySessionId)
S->>Util: 현재 사용자 조회
S->>Repo: findFetchBySessionId(studySessionId)
S->>V: validateSubmitAvailable(...)
V-->>S: 유효성 검증 결과
S->>GH: 과제 제출 데이터 조회
S->>G: judge(과제 제출 데이터, assignmentHistory)
G-->>S: 평가 결과 반영
S->>R: AssignmentHistoryV2 저장
S->>C: ResponseEntity 반환
C->>U: HTTP 응답 전송
Possibly related PRs
Suggested labels
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @uwoobeat, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request implements the V2 API for submitting study assignments. It includes a new controller, service, and repository interfaces to handle the submission process. The changes also involve validating the submission, fetching assignment data from GitHub, and grading the submission.
Highlights
- API Implementation: Implements the
/v2/assignment-histories/submit
endpoint for submitting study assignments. - Service Logic: Adds
StudentAssignmentHistoryServiceV2
to handle assignment submission logic, including validation, data fetching, and grading. - Data Access: Introduces
AssignmentHistoryV2Repository
and updatesStudyV2Repository
to support assignment submission. - Validation and Grading: Adds
AssignmentHistoryValidatorV2
for submission validation andAssignmentHistoryGraderV2
for grading assignments.
Changelog
Click here to see the changelog
- src/main/java/com/gdschongik/gdsc/domain/studyv2/api/StudentAssginmentHistoryControllerV2.java
- Created a new controller
StudentAssginmentHistoryControllerV2
to handle the assignment submission endpoint. - Added a
PostMapping
to/submit
that takesstudySessionId
as a request parameter. - The endpoint calls
studentAssigmentHistoryServiceV2.submitAssignment
to process the submission.
- Created a new controller
- src/main/java/com/gdschongik/gdsc/domain/studyv2/application/StudentAssignmentHistoryServiceV2.java
- Created a new service
StudentAssignmentHistoryServiceV2
to manage assignment submission logic. - The
submitAssignment
method retrieves the current member, study, and study session. - It validates if the student has applied to the study and if the submission is within the allowed time frame.
- Fetches assignment submission from GitHub using
GithubClient
. - Grades the assignment using
AssignmentHistoryGraderV2
and saves the assignment history.
- Created a new service
- src/main/java/com/gdschongik/gdsc/domain/studyv2/dao/AssignmentHistoryV2Repository.java
- Created a new repository interface
AssignmentHistoryV2Repository
to manageAssignmentHistoryV2
entities. - Added a method
findByMemberAndStudySession
to find assignment history by member and study session.
- Created a new repository interface
- src/main/java/com/gdschongik/gdsc/domain/studyv2/dao/StudyV2CustomRepository.java
- Added
findFetchBySessionId
method to fetch a StudyV2 object by study session ID.
- Added
- src/main/java/com/gdschongik/gdsc/domain/studyv2/dao/StudyV2RepositoryImpl.java
- Implemented
findFetchBySessionId
to fetch StudyV2 by session ID using a query that joins StudyV2 and StudySessionV2.
- Implemented
- src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/AssignmentHistoryGraderV2.java
- Created a new domain service
AssignmentHistoryGraderV2
to grade assignment submissions. - The
judge
method fetches the assignment submission and callsjudgeAssignmentSubmission
. - If any exception occurs during fetching, it translates the exception to a
SubmissionFailureType
and marks the assignment as failed. - The
judgeAssignmentSubmission
method checks if the content length is sufficient and marks the assignment as success or failure accordingly.
- Created a new domain service
- src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/AssignmentHistoryValidatorV2.java
- Created a new domain service
AssignmentHistoryValidatorV2
to validate assignment submissions. - The
validateSubmitAvailable
method checks if the student has applied to the study and if the submission is within the allowed time frame.
- Created a new domain service
- src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudySessionV2.java
- Added
validateAssignmentSubmittable
method to validate if the assignment can be submitted based on the current time and assignment period.
- Added
- src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyV2.java
- Added
getOptionalStudySession
andgetStudySession
methods to retrieve study sessions by ID. - Modified
getStudySession
to throw an exception if the study session is not found. - Added
getStudySessionForUpdate
to retrieve study sessions for update operations.
- Added
- src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java
- Added
STUDY_SESSION_NOT_FOUND
error code.
- Added
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Did you know?
The term 'API' was first used in the context of computing in the 1960s, referring to the interfaces between different software components.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request implements the API for submitting study assignments. Overall, the code is well-structured and addresses the intended functionality. However, there are a few areas that could be improved for better clarity and maintainability. I've provided specific feedback in the review comments below.
Summary of Findings
- Naming Convention: Consider renaming
StudentAssginmentHistoryControllerV2
toStudentAssignmentHistoryControllerV2
to correct the typo and improve readability. - Exception Handling: Ensure that all potential exceptions are properly handled and logged to provide better insights into application behavior.
- Code Clarity: Improve code clarity by adding comments to explain complex logic or non-obvious operations.
Assessment
The code introduces a new API endpoint for submitting study assignments, which is a valuable addition to the application. The implementation is generally sound, but I've identified a few areas for improvement, particularly around naming conventions, exception handling, and code clarity. Addressing these comments will enhance the overall quality and maintainability of the code. I recommend that the author address these comments and have others review and approve this code before merging.
private StudySessionV2 getStudySessionForUpdate(Long studySessionId) { | ||
return getOptionalStudySession(studySessionId) | ||
.orElseThrow(() -> new CustomException(STUDY_NOT_UPDATABLE_SESSION_NOT_FOUND)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Job Summary for GradleCheck Style and Test to Develop :: build-test
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (5)
src/main/java/com/gdschongik/gdsc/domain/studyv2/dao/AssignmentHistoryV2Repository.java (1)
1-11
: Repository 인터페이스가 잘 설계되었습니다.AssignmentHistoryV2Repository 인터페이스가 Spring Data JPA 규칙을 잘 따르고 있습니다. 회원과 스터디 세션으로 과제 이력을 조회하는 메서드가 명확하게 정의되어 있습니다.
한 가지 고려사항: 향후 확장성을 위해 특정 회원의 모든 과제 이력을 조회하는 메서드나, 특정 스터디 세션의 모든 과제 이력을 조회하는 메서드도 추가하는 것이 좋을 수 있습니다.
src/main/java/com/gdschongik/gdsc/domain/studyv2/application/StudentAssignmentHistoryServiceV2.java (1)
39-44
:@Transactional
범위 확인
submitAssignment
메서드 전체가 트랜잭션으로 보호되므로, 조회 및 저장 로직이 보장됩니다. 다만, 매우 긴 로직이나 외부 API를 다루는 경우라면 트랜잭션 범위를 축소하는 방안을 고려해 볼 수도 있습니다.src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/AssignmentHistoryGraderV2.java (3)
20-28
:judge
메서드의 예외 처리 범위
CustomException
만 처리하고 있어, 예상치 못한 예외가 발생할 경우 로깅 외 조치가 누락될 수 있습니다. 필요하다면 범용 예외 처리도 고려해보세요.
30-42
: 과제 내용 길이 최소 기준
과제 검증 로직에서MINIMUM_ASSIGNMENT_CONTENT_LENGTH
(300자)를 사용하고 있는데, 필요 시 향후 요구사항에 따라 설정값으로 분리하여 동적으로 관리해도 좋겠습니다.
44-54
:translateException
메서드의 예외 매핑 범위
GITHUB_CONTENT_NOT_FOUND
에 국한된 매핑 로직은 명확합니다. 향후 더 많은 예외가 발생할 가능성이 있다면, 해당 예외 코드들을 추가적으로 매핑할 수 있도록 확장성을 고려해보세요.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
src/main/java/com/gdschongik/gdsc/domain/studyv2/api/StudentAssginmentHistoryControllerV2.java
(1 hunks)src/main/java/com/gdschongik/gdsc/domain/studyv2/application/StudentAssignmentHistoryServiceV2.java
(1 hunks)src/main/java/com/gdschongik/gdsc/domain/studyv2/dao/AssignmentHistoryV2Repository.java
(1 hunks)src/main/java/com/gdschongik/gdsc/domain/studyv2/dao/StudyV2CustomRepository.java
(1 hunks)src/main/java/com/gdschongik/gdsc/domain/studyv2/dao/StudyV2RepositoryImpl.java
(1 hunks)src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/AssignmentHistoryGraderV2.java
(1 hunks)src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/AssignmentHistoryValidatorV2.java
(1 hunks)src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudySessionV2.java
(2 hunks)src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyV2.java
(3 hunks)src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java
(1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Check Style and Test to Develop
src/main/java/com/gdschongik/gdsc/domain/studyv2/api/StudentAssginmentHistoryControllerV2.java
[error] 25-25: missing return statement
🔇 Additional comments (11)
src/main/java/com/gdschongik/gdsc/domain/studyv2/dao/StudyV2CustomRepository.java (1)
10-10
: 이 구현은 좋아 보입니다!세션 ID로 스터디를 조회하는 메서드가 추가되었습니다. 기존의
findFetchById
메서드와 동일한 패턴을 따르고 있어 일관성이 유지되었습니다.src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java (1)
108-108
: ErrorCode 추가가 적절합니다.스터디 회차를 찾을 수 없는 경우에 대한 오류 코드가 논리적인 위치에 추가되었습니다. 메시지가 명확하고 기존 오류 코드 스타일과 일치합니다.
src/main/java/com/gdschongik/gdsc/domain/studyv2/dao/StudyV2RepositoryImpl.java (1)
26-34
: 구현이 깔끔합니다.세션 ID로 StudyV2를 조회하는 메서드가 잘 구현되었습니다.
fetchJoin
을 사용하여 N+1 쿼리 문제를 방지하고 있으며,any()
메서드를 통해 컬렉션 내의
세션 ID를 효과적으로 필터링하고 있습니다.src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudySessionV2.java (1)
113-125
: 과제 제출 가능 여부 검증 로직이 잘 구현되었습니다.validateAssignmentSubmittable 메서드가 과제 제출 기간 관련 검증을 적절하게 수행하고 있습니다. 과제 기간이 설정되어 있는지, 현재 시간이 과제 제출 시작일 이전인지, 그리고 마감일을 지났는지 확인하는 로직이 각각의 에러 코드와 함께 올바르게 구현되었습니다.
src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyV2.java (2)
202-210
: 스터디 세션 조회 메서드가 적절히 개선되었습니다.Optional을 활용한 getOptionalStudySession 메서드와 예외 처리가 포함된 getStudySession 메서드가 추가되어 스터디 세션 조회 로직이 더 명확해졌습니다. 이 방식은 클라이언트 코드에서 다양한 상황에 맞게 활용할 수 있는 유연성을 제공합니다.
229-232
: 메서드 이름 변경으로 목적이 명확해졌습니다.기존 getStudySession 메서드를 getStudySessionForUpdate로 이름을 변경하고 목적에 맞는 예외 메시지를 사용하도록 수정한 것이 좋습니다. 이렇게 하면 업데이트 목적으로 세션을 조회할 때와 일반 조회 시의 차이가 명확해집니다.
src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/AssignmentHistoryValidatorV2.java (1)
9-22
: 과제 제출 가능 여부에 대한 검증 도메인 서비스가 잘 설계되었습니다.과제를 제출하기 전 필요한 두 가지 검증(스터디 신청 여부, 과제 제출 기간)을 잘 캡슐화하여 구현했습니다. 도메인 서비스로 분리함으로써 단일 책임 원칙을 잘 준수하고 있습니다.
src/main/java/com/gdschongik/gdsc/domain/studyv2/application/StudentAssignmentHistoryServiceV2.java (4)
31-38
: 필드 주입 대신 생성자 주입이 잘 적용되었습니다.
스프링 DI를 위해@RequiredArgsConstructor
를 사용하는 것은 유지보수성과 테스트 용이성 측면에서 적절합니다.
49-52
:study.getStudySession
호출 시 세션 미존재 시나리오 명시
studySessionId
에 해당하는 세션이 없을 경우 예외가 발생하거나null
이 반환될 가능성에 대한 에러 핸들링을 별도로 두는 것이 안전해 보입니다.
54-57
:repositoryLink
가null
일 때 처리 로직 권장
optionalStudyHistory
가 존재하지 않아repositoryLink
가null
인 상태로githubClient.getLatestAssignmentSubmissionFetcher
를 호출할 경우 예외가 발생할 여지는 없는지 확인이 필요합니다. 필요하다면 예외 처리를 명시적으로 추가해주세요.
72-76
:findOrCreate
메서드 구현
없는 경우에 새 엔티티를 생성하는 방식으로 잘 설계되어 있습니다. 엔티티 생성 시점이 명확하여 도메인 로직의 일관성을 보장합니다.
@RequiredArgsConstructor | ||
public class StudentAssginmentHistoryControllerV2 { | ||
|
||
private final StudentAssignmentHistoryServiceV2 studentAssigmentHistoryServiceV2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
필드 이름 오타를 수정해주세요.
'studentAssigmentHistoryServiceV2'에 오타가 있습니다. 'Assigment'를 'Assignment'로 수정해야 합니다.
- private final StudentAssignmentHistoryServiceV2 studentAssigmentHistoryServiceV2;
+ private final StudentAssignmentHistoryServiceV2 studentAssignmentHistoryServiceV2;
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
private final StudentAssignmentHistoryServiceV2 studentAssigmentHistoryServiceV2; | |
private final StudentAssignmentHistoryServiceV2 studentAssignmentHistoryServiceV2; |
@RestController | ||
@RequestMapping("/v2/assignment-histories") | ||
@RequiredArgsConstructor | ||
public class StudentAssginmentHistoryControllerV2 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
클래스 이름 오타를 수정해주세요.
'StudentAssginmentHistoryControllerV2'에 오타가 있습니다. 'Assginment'를 'Assignment'로 수정해야 합니다.
-public class StudentAssginmentHistoryControllerV2 {
+public class StudentAssignmentHistoryControllerV2 {
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
public class StudentAssginmentHistoryControllerV2 { | |
public class StudentAssignmentHistoryControllerV2 { |
public ResponseEntity<Void> submitMyAssignment(@RequestParam(name = "studySessionId") Long studySessionId) { | ||
studentAssigmentHistoryServiceV2.submitAssignment(studySessionId); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
반환값이 누락되었습니다.
submitMyAssignment 메서드는 ResponseEntity를 반환하도록 선언되었지만, 실제 반환 문이 없습니다. 파이프라인 오류의 원인이 되고 있습니다.
public ResponseEntity<Void> submitMyAssignment(@RequestParam(name = "studySessionId") Long studySessionId) {
studentAssigmentHistoryServiceV2.submitAssignment(studySessionId);
+ return ResponseEntity.ok().build();
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
public ResponseEntity<Void> submitMyAssignment(@RequestParam(name = "studySessionId") Long studySessionId) { | |
studentAssigmentHistoryServiceV2.submitAssignment(studySessionId); | |
} | |
public ResponseEntity<Void> submitMyAssignment(@RequestParam(name = "studySessionId") Long studySessionId) { | |
studentAssigmentHistoryServiceV2.submitAssignment(studySessionId); | |
return ResponseEntity.ok().build(); | |
} |
🧰 Tools
🪛 GitHub Actions: Check Style and Test to Develop
[error] 25-25: missing return statement
Job Summary for GradleCheck Style and Test to Develop :: build-test
|
Job Summary for GradleCheck Style and Test to Develop :: build-test
|
Job Summary for GradleCheck Style and Test to Develop :: build-test
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
🌱 관련 이슈
📌 작업 내용 및 특이사항
📝 참고사항
📚 기타
Summary by CodeRabbit