-
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
Changes from 7 commits
0b6127d
5457f2a
d7cf68a
17b27b7
d16d8d5
5ed806d
f339f85
ff0c5d4
197df55
8ed9f0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,26 @@ | ||||||||||||||||
package com.gdschongik.gdsc.domain.studyv2.api; | ||||||||||||||||
|
||||||||||||||||
import com.gdschongik.gdsc.domain.studyv2.application.StudentAssignmentHistoryServiceV2; | ||||||||||||||||
import io.swagger.v3.oas.annotations.Operation; | ||||||||||||||||
import io.swagger.v3.oas.annotations.tags.Tag; | ||||||||||||||||
import lombok.RequiredArgsConstructor; | ||||||||||||||||
import org.springframework.http.ResponseEntity; | ||||||||||||||||
import org.springframework.web.bind.annotation.PostMapping; | ||||||||||||||||
import org.springframework.web.bind.annotation.RequestMapping; | ||||||||||||||||
import org.springframework.web.bind.annotation.RequestParam; | ||||||||||||||||
import org.springframework.web.bind.annotation.RestController; | ||||||||||||||||
|
||||||||||||||||
@Tag(name = "Student Assignment History V2", description = "학생 과제 제출이력 API입니다.") | ||||||||||||||||
@RestController | ||||||||||||||||
@RequestMapping("/v2/assignment-histories") | ||||||||||||||||
@RequiredArgsConstructor | ||||||||||||||||
public class StudentAssginmentHistoryControllerV2 { | ||||||||||||||||
|
||||||||||||||||
private final StudentAssignmentHistoryServiceV2 studentAssigmentHistoryServiceV2; | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||
|
||||||||||||||||
@Operation(summary = "내 과제 제출하기", description = "나의 과제를 제출합니다. 제출된 과제는 채점되어 제출내역에 반영됩니다.") | ||||||||||||||||
@PostMapping("/submit") | ||||||||||||||||
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 commentThe 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
Suggested change
🧰 Tools🪛 GitHub Actions: Check Style and Test to Develop[error] 25-25: missing return statement |
||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.gdschongik.gdsc.domain.studyv2.application; | ||
|
||
import static com.gdschongik.gdsc.global.exception.ErrorCode.*; | ||
|
||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.domain.study.domain.AssignmentSubmissionFetcher; | ||
import com.gdschongik.gdsc.domain.studyv2.dao.AssignmentHistoryV2Repository; | ||
import com.gdschongik.gdsc.domain.studyv2.dao.StudyHistoryV2Repository; | ||
import com.gdschongik.gdsc.domain.studyv2.dao.StudyV2Repository; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.AssignmentHistoryGraderV2; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.AssignmentHistoryV2; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.AssignmentHistoryValidatorV2; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.StudyHistoryV2; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.StudySessionV2; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.StudyV2; | ||
import com.gdschongik.gdsc.global.exception.CustomException; | ||
import com.gdschongik.gdsc.global.util.MemberUtil; | ||
import com.gdschongik.gdsc.infra.github.client.GithubClient; | ||
import jakarta.transaction.Transactional; | ||
import java.time.LocalDateTime; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class StudentAssignmentHistoryServiceV2 { | ||
|
||
private final MemberUtil memberUtil; | ||
private final GithubClient githubClient; | ||
private final StudyV2Repository studyV2Repository; | ||
private final StudyHistoryV2Repository studyHistoryV2Repository; | ||
private final AssignmentHistoryV2Repository assignmentHistoryV2Repository; | ||
private final AssignmentHistoryValidatorV2 assignmentHistoryValidatorV2; | ||
private final AssignmentHistoryGraderV2 assignmentHistoryGraderV2; | ||
|
||
@Transactional | ||
public void submitAssignment(Long studySessionId) { | ||
Member currentMember = memberUtil.getCurrentMember(); | ||
StudyV2 study = studyV2Repository | ||
.findFetchBySessionId(studySessionId) | ||
.orElseThrow(() -> new CustomException(STUDY_NOT_FOUND)); | ||
Optional<StudyHistoryV2> optionalStudyHistory = | ||
studyHistoryV2Repository.findByStudentAndStudy(currentMember, study); | ||
|
||
boolean isAppliedToStudy = optionalStudyHistory.isPresent(); | ||
StudySessionV2 studySession = study.getStudySession(studySessionId); | ||
LocalDateTime now = LocalDateTime.now(); | ||
|
||
assignmentHistoryValidatorV2.validateSubmitAvailable(isAppliedToStudy, studySession, now); | ||
|
||
String repositoryLink = | ||
optionalStudyHistory.map(StudyHistoryV2::getRepositoryLink).orElse(null); | ||
AssignmentSubmissionFetcher fetcher = | ||
githubClient.getLatestAssignmentSubmissionFetcher(repositoryLink, studySession.getPosition()); | ||
AssignmentHistoryV2 assignmentHistory = findOrCreate(currentMember, studySession); | ||
|
||
assignmentHistoryGraderV2.judge(fetcher, assignmentHistory); | ||
|
||
assignmentHistoryV2Repository.save(assignmentHistory); | ||
|
||
log.info( | ||
"[StudentAssignmentHistoryServiceV2] 과제 제출: studySessionId={}, studentId={}, submissionStatus={}, submissionFailureType={}", | ||
studySessionId, | ||
currentMember.getId(), | ||
assignmentHistory.getSubmissionStatus(), | ||
assignmentHistory.getSubmissionFailureType()); | ||
} | ||
|
||
private AssignmentHistoryV2 findOrCreate(Member student, StudySessionV2 studySession) { | ||
return assignmentHistoryV2Repository | ||
.findByMemberAndStudySession(student, studySession) | ||
.orElseGet(() -> AssignmentHistoryV2.create(studySession, student)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.gdschongik.gdsc.domain.studyv2.dao; | ||
|
||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.AssignmentHistoryV2; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.StudySessionV2; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface AssignmentHistoryV2Repository extends JpaRepository<AssignmentHistoryV2, Long> { | ||
Optional<AssignmentHistoryV2> findByMemberAndStudySession(Member member, StudySessionV2 studySession); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.gdschongik.gdsc.domain.studyv2.domain; | ||
|
||
import static com.gdschongik.gdsc.domain.study.domain.SubmissionFailureType.*; | ||
import static com.gdschongik.gdsc.global.exception.ErrorCode.*; | ||
|
||
import com.gdschongik.gdsc.domain.study.domain.AssignmentSubmission; | ||
import com.gdschongik.gdsc.domain.study.domain.AssignmentSubmissionFetcher; | ||
import com.gdschongik.gdsc.domain.study.domain.SubmissionFailureType; | ||
import com.gdschongik.gdsc.global.annotation.DomainService; | ||
import com.gdschongik.gdsc.global.exception.CustomException; | ||
import com.gdschongik.gdsc.global.exception.ErrorCode; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@DomainService | ||
public class AssignmentHistoryGraderV2 { | ||
|
||
private static final int MINIMUM_ASSIGNMENT_CONTENT_LENGTH = 300; | ||
|
||
public void judge(AssignmentSubmissionFetcher assignmentSubmissionFetcher, AssignmentHistoryV2 assignmentHistory) { | ||
try { | ||
AssignmentSubmission assignmentSubmission = assignmentSubmissionFetcher.fetch(); | ||
judgeAssignmentSubmission(assignmentSubmission, assignmentHistory); | ||
} catch (CustomException e) { | ||
SubmissionFailureType failureType = translateException(e); | ||
assignmentHistory.fail(failureType); | ||
} | ||
} | ||
|
||
private void judgeAssignmentSubmission( | ||
AssignmentSubmission assignmentSubmission, AssignmentHistoryV2 assignmentHistory) { | ||
if (assignmentSubmission.contentLength() < MINIMUM_ASSIGNMENT_CONTENT_LENGTH) { | ||
assignmentHistory.fail(WORD_COUNT_INSUFFICIENT); | ||
return; | ||
} | ||
|
||
assignmentHistory.success( | ||
assignmentSubmission.url(), | ||
assignmentSubmission.commitHash(), | ||
assignmentSubmission.contentLength(), | ||
assignmentSubmission.committedAt()); | ||
} | ||
|
||
private SubmissionFailureType translateException(CustomException e) { | ||
ErrorCode errorCode = e.getErrorCode(); | ||
|
||
if (errorCode == GITHUB_CONTENT_NOT_FOUND) { | ||
return LOCATION_UNIDENTIFIABLE; | ||
} | ||
|
||
log.warn("[AssignmentHistoryGrader] 과제 제출정보 조회 중 알 수 없는 오류 발생: {}", e.getMessage()); | ||
|
||
return UNKNOWN; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.gdschongik.gdsc.domain.studyv2.domain; | ||
|
||
import static com.gdschongik.gdsc.global.exception.ErrorCode.*; | ||
|
||
import com.gdschongik.gdsc.global.annotation.DomainService; | ||
import com.gdschongik.gdsc.global.exception.CustomException; | ||
import java.time.LocalDateTime; | ||
|
||
@DomainService | ||
public class AssignmentHistoryValidatorV2 { | ||
|
||
/** | ||
* 채점을 수행하기 전, 과제 제출이 가능한지 검증합니다. | ||
*/ | ||
public void validateSubmitAvailable(boolean isAppliedToStudy, StudySessionV2 studySession, LocalDateTime now) { | ||
if (!isAppliedToStudy) { | ||
throw new CustomException(ASSIGNMENT_STUDY_NOT_APPLIED); | ||
} | ||
|
||
studySession.validateAssignmentSubmittable(now); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
@@ -196,6 +197,18 @@ public static StudyV2 createAssignment( | |
.build(); | ||
} | ||
|
||
// 데이터 조회 로직 | ||
|
||
public Optional<StudySessionV2> getOptionalStudySession(Long studySessionId) { | ||
return studySessions.stream() | ||
.filter(session -> session.getId().equals(studySessionId)) | ||
.findFirst(); | ||
} | ||
|
||
public StudySessionV2 getStudySession(Long studySessionId) { | ||
return getOptionalStudySession(studySessionId).orElseThrow(() -> new CustomException(STUDY_SESSION_NOT_FOUND)); | ||
} | ||
|
||
// 데이터 변경 로직 | ||
|
||
public void update(StudyUpdateCommand command) { | ||
|
@@ -207,16 +220,14 @@ public void update(StudyUpdateCommand command) { | |
this.endTime = command.endTime(); | ||
|
||
command.studySessions().forEach(sessionCommand -> { | ||
getStudySession(sessionCommand.studySessionId()).update(sessionCommand); | ||
getStudySessionForUpdate(sessionCommand.studySessionId()).update(sessionCommand); | ||
}); | ||
|
||
validateLessonTimeOrderMatchesPosition(); | ||
} | ||
|
||
private StudySessionV2 getStudySession(Long studySessionId) { | ||
return studySessions.stream() | ||
.filter(session -> session.getId().equals(studySessionId)) | ||
.findFirst() | ||
private StudySessionV2 getStudySessionForUpdate(Long studySessionId) { | ||
return getOptionalStudySession(studySessionId) | ||
.orElseThrow(() -> new CustomException(STUDY_NOT_UPDATABLE_SESSION_NOT_FOUND)); | ||
} | ||
Comment on lines
+229
to
232
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
|
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'로 수정해야 합니다.
📝 Committable suggestion