-
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: 과제 제출하기 채점 로직 구현 #649
Merged
Merged
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e4926e5
feat: 미사용 에러코드 제거
uwoobeat 3fac1f8
refactor: 과제 길이를 integer로 수정
uwoobeat e3486b8
feat: VO Supplier를 응답하도록 변경
uwoobeat 09bbeb2
feat: 제출 실패사유에 알수없음 추가
uwoobeat 5f5a3b6
feat: 과제 채점 로직 구현
uwoobeat c2c7946
refactor: 항상 LocalDateTime을 반환하도록 변경
uwoobeat 5c7d03a
refactor: 과제 최소길이를 상수로 추출
uwoobeat da15ced
feat: 함수형 인터페이스인 AssignmentSubmissionFetcher 추가
uwoobeat ce96d02
refactor: 패키지 위치 변경
uwoobeat df4f53a
docs: 투두 추가
uwoobeat c5e37c6
fix: 지연 평가 작동하도록 로직 분리
uwoobeat 9ffeeeb
feat: 클로저가 되지 않도록 수정
uwoobeat ca13976
feat: 예외 시그니처 추가
uwoobeat c39181e
feat: 변경된 과제정보 페치 방식 반영
uwoobeat 0fb75ea
docs: 구현 관련 주석 추가
uwoobeat 4ee8f72
feat: 깃허브 요청 과정에서 발생한 예외는 전부 UNKNOWN으로 변환
uwoobeat 63d3604
feat: 과제 길이 상수 integer로 변경
uwoobeat 1e45fc1
feat: 과제 채점 로직 반영
uwoobeat c49e06a
feat: 과제 제출 컨트롤러 추가
uwoobeat b3f8896
test: 과제 채점기 테스트 추가
uwoobeat aff1d23
Merge branch 'develop' into feature/640-assignment-judge
uwoobeat f2ab6a7
feat: 스터디 상수 추가
uwoobeat 367489f
docs: 투두 추가
uwoobeat 755ca8f
test: GithubClient 모킹
uwoobeat 467b348
feat: 과제 발행 유틸 메서드 추가
uwoobeat c112f89
test: 과제 제출 통합 테스트 추가
uwoobeat 02c821e
Merge branch 'develop' into feature/640-assignment-judge
uwoobeat 61afa7f
docs: 주요 로그 추가
uwoobeat 0a4da1b
refactor: private 상수로 변경
uwoobeat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistoryGrader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.gdschongik.gdsc.domain.study.domain; | ||
|
||
import static com.gdschongik.gdsc.domain.study.domain.SubmissionFailureType.*; | ||
import static com.gdschongik.gdsc.global.exception.ErrorCode.*; | ||
|
||
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 AssignmentHistoryGrader { | ||
|
||
public static final int MINIMUM_ASSIGNMENT_CONTENT_LENGTH = 300; | ||
|
||
public void judge(AssignmentSubmissionFetcher assignmentSubmissionFetcher, AssignmentHistory assignmentHistory) { | ||
try { | ||
AssignmentSubmission assignmentSubmission = assignmentSubmissionFetcher.fetch(); | ||
judgeAssignmentSubmission(assignmentSubmission, assignmentHistory); | ||
} catch (CustomException e) { | ||
SubmissionFailureType failureType = translateException(e); | ||
assignmentHistory.fail(failureType); | ||
} | ||
} | ||
|
||
private void judgeAssignmentSubmission( | ||
AssignmentSubmission assignmentSubmission, AssignmentHistory 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; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentSubmission.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.gdschongik.gdsc.domain.study.domain; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record AssignmentSubmission(String url, String commitHash, Integer contentLength, LocalDateTime committedAt) {} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentSubmissionFetchExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.gdschongik.gdsc.domain.study.domain; | ||
|
||
import com.gdschongik.gdsc.global.exception.CustomException; | ||
|
||
@FunctionalInterface | ||
public interface AssignmentSubmissionFetchExecutor { | ||
AssignmentSubmission execute(String repo, int week) throws CustomException; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentSubmissionFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.gdschongik.gdsc.domain.study.domain; | ||
|
||
import com.gdschongik.gdsc.global.exception.CustomException; | ||
|
||
public record AssignmentSubmissionFetcher(String repo, int week, AssignmentSubmissionFetchExecutor fetchExecutor) { | ||
public AssignmentSubmission fetch() throws CustomException { | ||
return fetchExecutor.execute(repo, week); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
...ava/com/gdschongik/gdsc/infra/github/dto/response/GithubAssignmentSubmissionResponse.java
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
...est/java/com/gdschongik/gdsc/domain/study/application/StudentStudyHistoryServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.gdschongik.gdsc.domain.study.application; | ||
|
||
import static com.gdschongik.gdsc.global.common.constant.StudyConstant.*; | ||
import static org.assertj.core.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.domain.member.domain.MemberRole; | ||
import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period; | ||
import com.gdschongik.gdsc.domain.study.dao.AssignmentHistoryRepository; | ||
import com.gdschongik.gdsc.domain.study.dao.StudyHistoryRepository; | ||
import com.gdschongik.gdsc.domain.study.domain.AssignmentHistory; | ||
import com.gdschongik.gdsc.domain.study.domain.AssignmentSubmission; | ||
import com.gdschongik.gdsc.domain.study.domain.AssignmentSubmissionFetcher; | ||
import com.gdschongik.gdsc.domain.study.domain.AssignmentSubmissionStatus; | ||
import com.gdschongik.gdsc.domain.study.domain.Study; | ||
import com.gdschongik.gdsc.domain.study.domain.StudyDetail; | ||
import com.gdschongik.gdsc.domain.study.domain.StudyHistory; | ||
import com.gdschongik.gdsc.helper.IntegrationTest; | ||
import java.time.LocalDateTime; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
class StudentStudyHistoryServiceTest extends IntegrationTest { | ||
|
||
@Autowired | ||
private StudentStudyHistoryService studentStudyHistoryService; | ||
|
||
@Autowired | ||
private StudyHistoryRepository studyHistoryRepository; | ||
|
||
@Autowired | ||
private AssignmentHistoryRepository assignmentHistoryRepository; | ||
|
||
private void setCurrentTime(LocalDateTime now) { | ||
try (MockedStatic<LocalDateTime> mock = Mockito.mockStatic(LocalDateTime.class, Mockito.CALLS_REAL_METHODS)) { | ||
mock.when(LocalDateTime::now).thenReturn(now); | ||
} | ||
} | ||
|
||
@Nested | ||
class 과제_제출할때 { | ||
|
||
@Test | ||
void 성공한다() { | ||
// given | ||
Member mentor = createAssociateMember(); | ||
// TODO: LocalDateTime.now() 관련 테스트 정책 논의 필요 | ||
LocalDateTime now = LocalDateTime.now(); // 통합 테스트에서는 LocalDateTime.now()를 사용해야 함 | ||
Study study = createStudy( | ||
mentor, | ||
Period.createPeriod(now.minusWeeks(1), now.plusWeeks(7)), // 스터디 기간: 1주 전 ~ 7주 후 | ||
Period.createPeriod(now.minusWeeks(2), now.minusWeeks(1))); // 수강신청 기간: 2주 전 ~ 1주 전 | ||
StudyDetail studyDetail = | ||
createStudyDetail(study, now.minusDays(6), now.plusDays(1)); // 1주차 기간: 6일 전 ~ 1일 후 | ||
publishAssignment(studyDetail); | ||
|
||
Member student = createRegularMember(); | ||
logoutAndReloginAs(student.getId(), MemberRole.REGULAR); | ||
|
||
// 수강신청 valiadtion 로직이 LocalDateTime.now() 기준으로 동작하기 때문에 직접 수강신청 생성 | ||
StudyHistory studyHistory = StudyHistory.create(student, study); | ||
studyHistory.updateRepositoryLink(REPOSITORY_LINK); | ||
studyHistoryRepository.save(studyHistory); | ||
|
||
// 제출정보 조회 fetcher stubbing | ||
AssignmentSubmissionFetcher mockFetcher = mock(AssignmentSubmissionFetcher.class); | ||
when(mockFetcher.fetch()) | ||
.thenReturn(new AssignmentSubmission(REPOSITORY_LINK, COMMIT_HASH, 500, COMMITTED_AT)); | ||
when(githubClient.getLatestAssignmentSubmissionFetcher(anyString(), anyInt())) | ||
.thenReturn(mockFetcher); | ||
|
||
// when | ||
studentStudyHistoryService.submitAssignment(studyDetail.getId()); | ||
|
||
// then | ||
AssignmentHistory assignmentHistory = | ||
assignmentHistoryRepository.findById(1L).orElseThrow(); | ||
assertThat(assignmentHistory.getSubmissionStatus()).isEqualTo(AssignmentSubmissionStatus.SUCCESS); | ||
assertThat(assignmentHistory.getSubmissionLink()).isEqualTo(REPOSITORY_LINK); | ||
assertThat(assignmentHistory.getCommitHash()).isEqualTo(COMMIT_HASH); | ||
assertThat(assignmentHistory.getContentLength()).isEqualTo(500); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
클래스 내에서만 사용되는 것 같은데 public이어야 할 필요가 있을까요?