From 879cb0a31d1b8b542f2fb49a7905f93a613e9395 Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn Date: Sat, 17 Aug 2024 17:41:45 +0900 Subject: [PATCH 01/15] =?UTF-8?q?chore:=20=EC=A0=95=EC=A0=81=20=EC=9E=84?= =?UTF-8?q?=ED=8F=AC=ED=8A=B8=20=EB=B0=8F=20=EC=9E=84=ED=8F=AC=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdschongik/gdsc/infra/github/client/GithubClient.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/infra/github/client/GithubClient.java b/src/main/java/com/gdschongik/gdsc/infra/github/client/GithubClient.java index d5b94a740..e876184df 100644 --- a/src/main/java/com/gdschongik/gdsc/infra/github/client/GithubClient.java +++ b/src/main/java/com/gdschongik/gdsc/infra/github/client/GithubClient.java @@ -1,13 +1,15 @@ package com.gdschongik.gdsc.infra.github.client; import static com.gdschongik.gdsc.global.common.constant.GithubConstant.*; +import static com.gdschongik.gdsc.global.exception.ErrorCode.*; import com.gdschongik.gdsc.global.exception.CustomException; -import com.gdschongik.gdsc.global.exception.ErrorCode; import com.gdschongik.gdsc.infra.github.dto.response.GithubAssignmentSubmissionResponse; import java.io.IOException; +import java.io.InputStream; import java.time.LocalDateTime; import java.time.ZoneId; +import java.util.Date; import lombok.RequiredArgsConstructor; import org.kohsuke.github.GHCommit; import org.kohsuke.github.GHContent; @@ -25,7 +27,7 @@ public GHRepository getRepository(String ownerRepo) { try { return github.getRepository(ownerRepo); } catch (IOException e) { - throw new CustomException(ErrorCode.GITHUB_REPOSITORY_NOT_FOUND); + throw new CustomException(GITHUB_REPOSITORY_NOT_FOUND); } } From 7cf3dba35c660a14008c52feefa8984196a3c02b Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn Date: Sat, 17 Aug 2024 17:42:31 +0900 Subject: [PATCH 02/15] =?UTF-8?q?refactor:=20=EA=B0=81=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=EC=97=90=20=EB=8C=80=EC=9D=91=EB=90=98=EB=8A=94=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=EB=A5=BC=20=ED=95=A0?= =?UTF-8?q?=EB=8B=B9=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/global/exception/ErrorCode.java | 3 + .../infra/github/client/GithubClient.java | 64 ++++++++++++------- 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java b/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java index 1ec0744ef..7c197be9f 100644 --- a/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java +++ b/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java @@ -158,6 +158,9 @@ public enum ErrorCode { // Github GITHUB_REPOSITORY_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 레포지토리입니다."), + GITHUB_CONTENT_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 파일입니다."), + GITHUB_FILE_READ_FAILED(HttpStatus.INTERNAL_SERVER_ERROR, "깃허브 파일 읽기에 실패했습니다."), + GITHUB_COMMIT_DATE_FETCH_FAILED(HttpStatus.INTERNAL_SERVER_ERROR, "깃허브 커밋 날짜 조회에 실패했습니다."), GITHUB_ASSIGNMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 과제 파일입니다."), ; diff --git a/src/main/java/com/gdschongik/gdsc/infra/github/client/GithubClient.java b/src/main/java/com/gdschongik/gdsc/infra/github/client/GithubClient.java index e876184df..34dd73f9c 100644 --- a/src/main/java/com/gdschongik/gdsc/infra/github/client/GithubClient.java +++ b/src/main/java/com/gdschongik/gdsc/infra/github/client/GithubClient.java @@ -32,30 +32,50 @@ public GHRepository getRepository(String ownerRepo) { } public GithubAssignmentSubmissionResponse getLatestAssignmentSubmission(String repo, int week) { + GHRepository ghRepository = getRepository(repo); + String assignmentPath = GITHUB_ASSIGNMENT_PATH.formatted(week); + + // GHContent#getSize() 의 경우 한글 문자열을 byte 단위로 계산하기 때문에, 직접 content를 읽어서 길이를 계산 + GHContent ghContent = getFileContent(ghRepository, assignmentPath); + String content = readFileContent(ghContent); + + GHCommit ghLatestCommit = ghRepository + .queryCommits() + .path(assignmentPath) + .list() + .withPageSize(1) + .iterator() + .next(); + + LocalDateTime committedAt = getCommitDate(ghLatestCommit) + .toInstant() + .atZone(ZoneId.systemDefault()) + .toLocalDateTime(); + + return new GithubAssignmentSubmissionResponse(ghLatestCommit.getSHA1(), content.length(), committedAt); + } + + private GHContent getFileContent(GHRepository ghRepository, String filePath) { + try { + return ghRepository.getFileContent(filePath); + } catch (IOException e) { + throw new CustomException(GITHUB_CONTENT_NOT_FOUND); + } + } + + private String readFileContent(GHContent ghContent) { + try (InputStream inputStream = ghContent.read()) { + return new String(inputStream.readAllBytes()); + } catch (IOException e) { + throw new CustomException(GITHUB_FILE_READ_FAILED); + } + } + + private Date getCommitDate(GHCommit ghLatestCommit) { try { - GHRepository ghRepository = getRepository(repo); - String assignmentPath = GITHUB_ASSIGNMENT_PATH.formatted(week); - - // GHContent#getSize() 의 경우 한글 문자열을 byte 단위로 계산하기 때문에, 직접 content를 읽어서 길이를 계산 - GHContent ghContent = ghRepository.getFileContent(assignmentPath); - String content = new String(ghContent.read().readAllBytes()); - - GHCommit ghLatestCommit = ghRepository - .queryCommits() - .path(assignmentPath) - .list() - .toList() - .get(0); - - LocalDateTime committedAt = ghLatestCommit - .getCommitDate() - .toInstant() - .atZone(ZoneId.systemDefault()) - .toLocalDateTime(); - - return new GithubAssignmentSubmissionResponse(ghLatestCommit.getSHA1(), content.length(), committedAt); + return ghLatestCommit.getCommitDate(); } catch (IOException e) { - throw new CustomException(ErrorCode.GITHUB_ASSIGNMENT_NOT_FOUND); + throw new CustomException(GITHUB_COMMIT_DATE_FETCH_FAILED); } } } From 9032b8fbce26cc7d5d9b19a9111cb74d1526486f Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn Date: Sat, 17 Aug 2024 18:04:18 +0900 Subject: [PATCH 03/15] =?UTF-8?q?feat:=20=EA=B3=BC=EC=A0=9C=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EB=B0=8F=20=EC=8B=A4=ED=8C=A8=20=EC=B2=98=EB=A6=AC?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../study/domain/AssignmentHistory.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java index 7c5d1edcb..bc35a03ce 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java @@ -14,6 +14,7 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import java.time.LocalDateTime; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -44,6 +45,8 @@ public class AssignmentHistory extends BaseEntity { private Long contentLength; + private LocalDateTime committedAt; + @Enumerated(EnumType.STRING) private AssignmentSubmissionStatus submissionStatus; @@ -74,7 +77,25 @@ public static AssignmentHistory create(StudyDetail studyDetail, Member member) { .build(); } + // 데이터 조회 로직 + public boolean isSubmitted() { return submissionStatus == SUCCESS || submissionStatus == FAILURE; } + + // 데이터 변경 로직 + + public void success(String submissionLink, String commitHash, Long contentLength, LocalDateTime committedAt) { + this.submissionLink = submissionLink; + this.commitHash = commitHash; + this.contentLength = contentLength; + this.submissionStatus = SUCCESS; + this.committedAt = committedAt; + } + + public void fail(SubmissionFailureType submissionFailureType) { + this.submissionStatus = FAILURE; + this.submissionFailureType = submissionFailureType; + this.committedAt = null; + } } From c1d548f7a1a5bde522e0233073049e0d1ccbbd18 Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn Date: Sun, 18 Aug 2024 01:55:22 +0900 Subject: [PATCH 04/15] =?UTF-8?q?feat:=20=EA=B3=BC=EC=A0=9C=20=ED=9C=B4?= =?UTF-8?q?=EA=B0=95=20=EC=83=81=ED=83=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/domain/study/domain/AssignmentSubmissionStatus.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentSubmissionStatus.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentSubmissionStatus.java index 3865abb98..6690c018a 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentSubmissionStatus.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentSubmissionStatus.java @@ -8,8 +8,7 @@ public enum AssignmentSubmissionStatus { PENDING("제출 전"), FAILURE("제출 실패"), - SUCCESS("제출 성공"), - CANCELLED("과제 휴강"); // TODO: 제거 및 DB에서 삭제 + SUCCESS("제출 성공"); private final String value; } From 6d2918dbbf0aeb8b1f3a68fe5568bc15be3a998a Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn Date: Sun, 18 Aug 2024 01:57:02 +0900 Subject: [PATCH 05/15] =?UTF-8?q?feat:=20=EC=A0=9C=EC=B6=9C=EC=83=81?= =?UTF-8?q?=ED=83=9C=EC=97=90=EC=84=9C=20PENDING=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/domain/study/domain/AssignmentSubmissionStatus.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentSubmissionStatus.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentSubmissionStatus.java index 6690c018a..2bc90a871 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentSubmissionStatus.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentSubmissionStatus.java @@ -6,7 +6,6 @@ @Getter @RequiredArgsConstructor public enum AssignmentSubmissionStatus { - PENDING("제출 전"), FAILURE("제출 실패"), SUCCESS("제출 성공"); From 2f55c92483aad90af900a376f63557679b2fe024 Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn Date: Sun, 18 Aug 2024 01:58:08 +0900 Subject: [PATCH 06/15] =?UTF-8?q?feat:=20=EC=83=9D=EC=84=B1=EC=9E=90?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=A0=9C=EC=B6=9C=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/domain/study/domain/AssignmentHistory.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java index bc35a03ce..c03c5f715 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java @@ -57,15 +57,9 @@ public class AssignmentHistory extends BaseEntity { private AssignmentHistory( StudyDetail studyDetail, Member member, - String submissionLink, - String commitHash, - Long contentLength, AssignmentSubmissionStatus submissionStatus) { this.studyDetail = studyDetail; this.member = member; - this.submissionLink = submissionLink; - this.commitHash = commitHash; - this.contentLength = contentLength; this.submissionStatus = submissionStatus; } From d7ee8fe0a210c2fafcfa1dfc026a2d53efae3798 Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn Date: Sun, 18 Aug 2024 01:58:53 +0900 Subject: [PATCH 07/15] =?UTF-8?q?feat:=20=EC=B4=88=EA=B8=B0=20=EC=A0=9C?= =?UTF-8?q?=EC=B6=9C=EC=83=81=ED=83=9C=EB=A5=BC=20FAILURE=EB=A1=9C=20?= =?UTF-8?q?=EC=8B=9C=EC=9E=91=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdschongik/gdsc/domain/study/domain/AssignmentHistory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java index c03c5f715..5a1ace040 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java @@ -67,7 +67,7 @@ public static AssignmentHistory create(StudyDetail studyDetail, Member member) { return AssignmentHistory.builder() .studyDetail(studyDetail) .member(member) - .submissionStatus(AssignmentSubmissionStatus.PENDING) + .submissionStatus(FAILURE) .build(); } From cd8e58c8e5965442b7eaf0a157eca76fda95f89d Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn Date: Sun, 18 Aug 2024 02:00:27 +0900 Subject: [PATCH 08/15] =?UTF-8?q?feat:=20=EC=B4=88=EA=B8=B0=20=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=EC=82=AC=EC=9C=A0=EB=A5=BC=20=EB=AF=B8=EC=A0=9C?= =?UTF-8?q?=EC=B6=9C=20=EC=83=81=ED=83=9C=EB=A1=9C=20=EC=A7=80=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/domain/study/domain/AssignmentHistory.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java index 5a1ace040..b909d0120 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java @@ -1,6 +1,7 @@ package com.gdschongik.gdsc.domain.study.domain; import static com.gdschongik.gdsc.domain.study.domain.AssignmentSubmissionStatus.*; +import static com.gdschongik.gdsc.domain.study.domain.SubmissionFailureType.*; import com.gdschongik.gdsc.domain.common.model.BaseEntity; import com.gdschongik.gdsc.domain.member.domain.Member; @@ -57,10 +58,12 @@ public class AssignmentHistory extends BaseEntity { private AssignmentHistory( StudyDetail studyDetail, Member member, - AssignmentSubmissionStatus submissionStatus) { + AssignmentSubmissionStatus submissionStatus, + SubmissionFailureType submissionFailureType) { this.studyDetail = studyDetail; this.member = member; this.submissionStatus = submissionStatus; + this.submissionFailureType = submissionFailureType; } public static AssignmentHistory create(StudyDetail studyDetail, Member member) { @@ -68,6 +71,7 @@ public static AssignmentHistory create(StudyDetail studyDetail, Member member) { .studyDetail(studyDetail) .member(member) .submissionStatus(FAILURE) + .submissionFailureType(NOT_SUBMITTED) .build(); } From b0bbce56f07e0f93b0b41301113647b979b7bb98 Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn Date: Sun, 18 Aug 2024 02:01:59 +0900 Subject: [PATCH 09/15] =?UTF-8?q?refactor:=20=EC=A0=9C=EC=B6=9C=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=EC=97=90=20?= =?UTF-8?q?=EC=8B=A4=ED=8C=A8=EC=82=AC=EC=9C=A0=EB=A5=BC=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdschongik/gdsc/domain/study/domain/AssignmentHistory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java index b909d0120..5f8996ba8 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java @@ -78,7 +78,7 @@ public static AssignmentHistory create(StudyDetail studyDetail, Member member) { // 데이터 조회 로직 public boolean isSubmitted() { - return submissionStatus == SUCCESS || submissionStatus == FAILURE; + return submissionFailureType != NOT_SUBMITTED; } // 데이터 변경 로직 From fa88bea3b4c12ae55e2cccb5734bec1ca4f8ccc0 Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn Date: Sun, 18 Aug 2024 02:12:06 +0900 Subject: [PATCH 10/15] =?UTF-8?q?docs:=20=ED=88=AC=EB=91=90=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/domain/study/domain/AssignmentSubmissionStatus.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentSubmissionStatus.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentSubmissionStatus.java index 2bc90a871..28fcf864a 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentSubmissionStatus.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentSubmissionStatus.java @@ -6,6 +6,7 @@ @Getter @RequiredArgsConstructor public enum AssignmentSubmissionStatus { + // TODO: 클라이언트 응답에는 PENDING 상태 필요하므로, 추후 응답용 enum 클래스 생성 구현 FAILURE("제출 실패"), SUCCESS("제출 성공"); From a87c67d15370d87a5b1286146cdd9b980f78dfaa Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn Date: Sun, 18 Aug 2024 02:14:38 +0900 Subject: [PATCH 11/15] =?UTF-8?q?refactor:=20=EC=88=9C=EC=84=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdschongik/gdsc/domain/study/domain/AssignmentHistory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java index 5f8996ba8..61b01f48f 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java @@ -87,8 +87,8 @@ public void success(String submissionLink, String commitHash, Long contentLength this.submissionLink = submissionLink; this.commitHash = commitHash; this.contentLength = contentLength; - this.submissionStatus = SUCCESS; this.committedAt = committedAt; + this.submissionStatus = SUCCESS; } public void fail(SubmissionFailureType submissionFailureType) { From f0ec9d8baf860ff95294ecc54727a698a303c57b Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn Date: Sun, 18 Aug 2024 02:15:06 +0900 Subject: [PATCH 12/15] =?UTF-8?q?feat:=20=EC=A0=9C=EC=B6=9C=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EC=8B=9C=20=EC=84=A4=EC=A0=95=ED=95=A0=20=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=EC=82=AC=EC=9C=A0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdschongik/gdsc/domain/study/domain/AssignmentHistory.java | 1 + .../gdsc/domain/study/domain/SubmissionFailureType.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java index 61b01f48f..476c1ae16 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java @@ -89,6 +89,7 @@ public void success(String submissionLink, String commitHash, Long contentLength this.contentLength = contentLength; this.committedAt = committedAt; this.submissionStatus = SUCCESS; + this.submissionFailureType = NONE; } public void fail(SubmissionFailureType submissionFailureType) { diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/SubmissionFailureType.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/SubmissionFailureType.java index 252b556e9..bd875f25f 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/SubmissionFailureType.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/SubmissionFailureType.java @@ -6,7 +6,8 @@ @Getter @RequiredArgsConstructor public enum SubmissionFailureType { - NOT_SUBMITTED("미제출"), + NONE("실패 없음"), // 제출상태 성공 시 사용 + NOT_SUBMITTED("미제출"), // 기본값 WORD_COUNT_INSUFFICIENT("글자수 부족"), LOCATION_UNIDENTIFIABLE("위치 확인불가"); From 2d721b7f5fea22894f2bf6a30193dafb5c784385 Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn Date: Sun, 18 Aug 2024 02:16:51 +0900 Subject: [PATCH 13/15] =?UTF-8?q?feat:=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/domain/study/domain/AssignmentHistory.java | 7 ++++++- .../com/gdschongik/gdsc/global/exception/ErrorCode.java | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java index 476c1ae16..eff90f441 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java @@ -5,6 +5,8 @@ import com.gdschongik.gdsc.domain.common.model.BaseEntity; import com.gdschongik.gdsc.domain.member.domain.Member; +import com.gdschongik.gdsc.global.exception.CustomException; + import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -93,8 +95,11 @@ public void success(String submissionLink, String commitHash, Long contentLength } public void fail(SubmissionFailureType submissionFailureType) { + if (submissionFailureType == NOT_SUBMITTED) { + throw new CustomException() + } + this.submissionStatus = FAILURE; this.submissionFailureType = submissionFailureType; - this.committedAt = null; } } diff --git a/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java b/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java index 7c197be9f..2147904ed 100644 --- a/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java +++ b/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java @@ -148,7 +148,6 @@ public enum ErrorCode { ORDER_FINAL_PAYMENT_AMOUNT_MISMATCH(HttpStatus.CONFLICT, "주문 최종결제금액은 주문총액에서 할인금액을 뺀 값이어야 합니다."), // Assignment - ASSIGNMENT_CAN_NOT_BE_UPDATED(HttpStatus.CONFLICT, "휴강인 과제는 수정할 수 없습니다."), ASSIGNMENT_DEADLINE_INVALID(HttpStatus.CONFLICT, "과제 마감 기한이 현재보다 빠릅니다."), ASSIGNMENT_STUDY_NOT_APPLIED(HttpStatus.CONFLICT, "해당 스터디에 대한 수강신청 기록이 존재하지 않습니다."), ASSIGNMENT_SUBMIT_NOT_STARTED(HttpStatus.CONFLICT, "아직 과제가 시작되지 않았습니다."), From 797d1d316dffbba063f2cf4f78c6e88a59b45e1d Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn Date: Sun, 18 Aug 2024 02:20:02 +0900 Subject: [PATCH 14/15] =?UTF-8?q?feat:=20=EC=8B=A4=ED=8C=A8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=8B=9C=20=EC=8B=A4=ED=8C=A8=EC=82=AC=EC=9C=A0=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=EB=A1=9C=EC=A7=81=20=EB=B0=8F=20=EA=B8=B0?= =?UTF-8?q?=EC=A1=B4=20=EC=A0=9C=EC=B6=9C=EC=A0=95=EB=B3=B4=20=EB=B9=84?= =?UTF-8?q?=EC=9A=B0=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/domain/study/domain/AssignmentHistory.java | 10 +++++++--- .../gdschongik/gdsc/global/exception/ErrorCode.java | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java index eff90f441..0316c6652 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistory.java @@ -2,11 +2,11 @@ import static com.gdschongik.gdsc.domain.study.domain.AssignmentSubmissionStatus.*; import static com.gdschongik.gdsc.domain.study.domain.SubmissionFailureType.*; +import static com.gdschongik.gdsc.global.exception.ErrorCode.*; import com.gdschongik.gdsc.domain.common.model.BaseEntity; import com.gdschongik.gdsc.domain.member.domain.Member; import com.gdschongik.gdsc.global.exception.CustomException; - import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -95,10 +95,14 @@ public void success(String submissionLink, String commitHash, Long contentLength } public void fail(SubmissionFailureType submissionFailureType) { - if (submissionFailureType == NOT_SUBMITTED) { - throw new CustomException() + if (submissionFailureType == NOT_SUBMITTED || submissionFailureType == NONE) { + throw new CustomException(ASSIGNMENT_INVALID_FAILURE_TYPE); } + this.submissionLink = null; + this.commitHash = null; + this.contentLength = null; + this.committedAt = null; this.submissionStatus = FAILURE; this.submissionFailureType = submissionFailureType; } diff --git a/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java b/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java index 2147904ed..47b6695fd 100644 --- a/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java +++ b/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java @@ -148,6 +148,7 @@ public enum ErrorCode { ORDER_FINAL_PAYMENT_AMOUNT_MISMATCH(HttpStatus.CONFLICT, "주문 최종결제금액은 주문총액에서 할인금액을 뺀 값이어야 합니다."), // Assignment + ASSIGNMENT_INVALID_FAILURE_TYPE(HttpStatus.CONFLICT, "유효하지 않은 제출 실패사유입니다."), ASSIGNMENT_DEADLINE_INVALID(HttpStatus.CONFLICT, "과제 마감 기한이 현재보다 빠릅니다."), ASSIGNMENT_STUDY_NOT_APPLIED(HttpStatus.CONFLICT, "해당 스터디에 대한 수강신청 기록이 존재하지 않습니다."), ASSIGNMENT_SUBMIT_NOT_STARTED(HttpStatus.CONFLICT, "아직 과제가 시작되지 않았습니다."), From 1f57ba6631b6df79b3f32a9138c7dfa0dd3c86b5 Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn Date: Sun, 18 Aug 2024 02:25:41 +0900 Subject: [PATCH 15/15] =?UTF-8?q?test:=20=EA=B3=BC=EC=A0=9C=20=ED=9E=88?= =?UTF-8?q?=EC=8A=A4=ED=86=A0=EB=A6=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../study/domain/AssignmentHistoryTest.java | 165 ++++++++++++++++++ .../global/common/constant/StudyConstant.java | 6 + 2 files changed, 171 insertions(+) create mode 100644 src/test/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistoryTest.java diff --git a/src/test/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistoryTest.java b/src/test/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistoryTest.java new file mode 100644 index 000000000..3c45e14d1 --- /dev/null +++ b/src/test/java/com/gdschongik/gdsc/domain/study/domain/AssignmentHistoryTest.java @@ -0,0 +1,165 @@ +package com.gdschongik.gdsc.domain.study.domain; + +import static com.gdschongik.gdsc.global.common.constant.StudyConstant.*; +import static com.gdschongik.gdsc.global.exception.ErrorCode.*; +import static org.assertj.core.api.Assertions.*; + +import com.gdschongik.gdsc.domain.member.domain.Member; +import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period; +import com.gdschongik.gdsc.global.exception.CustomException; +import com.gdschongik.gdsc.helper.FixtureHelper; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +class AssignmentHistoryTest { + + FixtureHelper fixtureHelper = new FixtureHelper(); + + private Member createMember(Long id) { + return fixtureHelper.createAssociateMember(id); + } + + private Study createStudyWithMentor(Long mentorId) { + Period period = Period.createPeriod(STUDY_START_DATETIME, STUDY_END_DATETIME); + Period applicationPeriod = + Period.createPeriod(STUDY_START_DATETIME.minusDays(7), STUDY_START_DATETIME.minusDays(1)); + return fixtureHelper.createStudyWithMentor(mentorId, period, applicationPeriod); + } + + private StudyDetail createStudyDetailWithAssignment(Study study) { + return fixtureHelper.createStudyDetailWithAssignment( + study, STUDY_DETAIL_START_DATETIME, STUDY_DETAIL_END_DATETIME, STUDY_ASSIGNMENT_DEADLINE_DATETIME); + } + + @Nested + class 빈_과제이력_생성할때 { + + @Test + void 제출상태는_FAILURE이다() { + // given + Member member = createMember(1L); + Study study = createStudyWithMentor(1L); + StudyDetail studyDetail = createStudyDetailWithAssignment(study); + + // when + AssignmentHistory assignmentHistory = AssignmentHistory.create(studyDetail, member); + + // then + assertThat(assignmentHistory.getSubmissionStatus()).isEqualTo(AssignmentSubmissionStatus.FAILURE); + } + + @Test + void 실패사유는_NOT_SUBMITTED이다() { + // given + Member member = createMember(1L); + Study study = createStudyWithMentor(1L); + StudyDetail studyDetail = createStudyDetailWithAssignment(study); + + // when + AssignmentHistory assignmentHistory = AssignmentHistory.create(studyDetail, member); + + // then + assertThat(assignmentHistory.getSubmissionFailureType()).isEqualTo(SubmissionFailureType.NOT_SUBMITTED); + } + } + + @Nested + class 과제이력_제출_성공할때 { + + @Test + void 제출상태는_SUCCESS이다() { + // given + Member member = createMember(1L); + Study study = createStudyWithMentor(1L); + StudyDetail studyDetail = createStudyDetailWithAssignment(study); + AssignmentHistory assignmentHistory = AssignmentHistory.create(studyDetail, member); + + // when + assignmentHistory.success(SUBMISSION_LINK, COMMIT_HASH, CONTENT_LENGTH, COMMITTED_AT); + } + + @Test + void 실패사유는_NONE이다() { + // given + Member member = createMember(1L); + Study study = createStudyWithMentor(1L); + StudyDetail studyDetail = createStudyDetailWithAssignment(study); + AssignmentHistory assignmentHistory = AssignmentHistory.create(studyDetail, member); + + // when + assignmentHistory.success(SUBMISSION_LINK, COMMIT_HASH, CONTENT_LENGTH, COMMITTED_AT); + + // then + assertThat(assignmentHistory.getSubmissionFailureType()).isEqualTo(SubmissionFailureType.NONE); + } + } + + @Nested + class 과제이력_제출_실패할때 { + + @Test + void 제출상태는_FAILURE이다() { + // given + Member member = createMember(1L); + Study study = createStudyWithMentor(1L); + StudyDetail studyDetail = createStudyDetailWithAssignment(study); + AssignmentHistory assignmentHistory = AssignmentHistory.create(studyDetail, member); + assignmentHistory.success(SUBMISSION_LINK, COMMIT_HASH, CONTENT_LENGTH, COMMITTED_AT); + + // when + assignmentHistory.fail(SubmissionFailureType.WORD_COUNT_INSUFFICIENT); + + // then + assertThat(assignmentHistory.getSubmissionStatus()).isEqualTo(AssignmentSubmissionStatus.FAILURE); + } + + @Test + void 실패사유는_NOT_SUBMITTED가_될수없다() { + // given + Member member = createMember(1L); + Study study = createStudyWithMentor(1L); + StudyDetail studyDetail = createStudyDetailWithAssignment(study); + AssignmentHistory assignmentHistory = AssignmentHistory.create(studyDetail, member); + assignmentHistory.success(SUBMISSION_LINK, COMMIT_HASH, CONTENT_LENGTH, COMMITTED_AT); + + // when, then + assertThatThrownBy(() -> assignmentHistory.fail(SubmissionFailureType.NOT_SUBMITTED)) + .isInstanceOf(CustomException.class) + .hasMessageContaining(ASSIGNMENT_INVALID_FAILURE_TYPE.getMessage()); + } + + @Test + void 실패사유는_NONE이_될수없다() { + // given + Member member = createMember(1L); + Study study = createStudyWithMentor(1L); + StudyDetail studyDetail = createStudyDetailWithAssignment(study); + AssignmentHistory assignmentHistory = AssignmentHistory.create(studyDetail, member); + assignmentHistory.success(SUBMISSION_LINK, COMMIT_HASH, CONTENT_LENGTH, COMMITTED_AT); + + // when, then + assertThatThrownBy(() -> assignmentHistory.fail(SubmissionFailureType.NONE)) + .isInstanceOf(CustomException.class) + .hasMessageContaining(ASSIGNMENT_INVALID_FAILURE_TYPE.getMessage()); + } + + @Test + void 기존_제출정보는_삭제된다() { + // given + Member member = createMember(1L); + Study study = createStudyWithMentor(1L); + StudyDetail studyDetail = createStudyDetailWithAssignment(study); + AssignmentHistory assignmentHistory = AssignmentHistory.create(studyDetail, member); + assignmentHistory.success(SUBMISSION_LINK, COMMIT_HASH, CONTENT_LENGTH, COMMITTED_AT); + + // when + assignmentHistory.fail(SubmissionFailureType.WORD_COUNT_INSUFFICIENT); + + // then + assertThat(assignmentHistory.getSubmissionLink()).isNull(); + assertThat(assignmentHistory.getCommitHash()).isNull(); + assertThat(assignmentHistory.getContentLength()).isNull(); + assertThat(assignmentHistory.getCommittedAt()).isNull(); + } + } +} diff --git a/src/test/java/com/gdschongik/gdsc/global/common/constant/StudyConstant.java b/src/test/java/com/gdschongik/gdsc/global/common/constant/StudyConstant.java index 0e9e26afc..031bf4fbd 100644 --- a/src/test/java/com/gdschongik/gdsc/global/common/constant/StudyConstant.java +++ b/src/test/java/com/gdschongik/gdsc/global/common/constant/StudyConstant.java @@ -31,4 +31,10 @@ private StudyConstant() {} public static final LocalDateTime STUDY_DETAIL_START_DATETIME = STUDY_START_DATETIME; public static final LocalDateTime STUDY_DETAIL_END_DATETIME = STUDY_DETAIL_START_DATETIME.plusWeeks(1); public static final LocalDateTime STUDY_ASSIGNMENT_DEADLINE_DATETIME = STUDY_DETAIL_END_DATETIME; + + // AssignmentHistory + public static final String SUBMISSION_LINK = "https://github.com/ownername/reponame/blob/main/week1/WIL.md"; + public static final String COMMIT_HASH = "aa11bb22cc33"; + public static final Long CONTENT_LENGTH = 2000L; + public static final LocalDateTime COMMITTED_AT = LocalDateTime.of(2024, 9, 8, 0, 0); }