From 1b7e1b685ab5f9a06e726a856d08987fc9f442ae Mon Sep 17 00:00:00 2001 From: Haneul Lee Date: Fri, 2 Aug 2024 16:57:47 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20=EA=B8=B0=ED=9A=8D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=97=90=20=EC=9D=98=ED=95=9C=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B4=88=EA=B8=B0=ED=99=94=20(#188)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/develup/api/MemberApi.java | 2 +- .../src/main/java/develup/api/MissionApi.java | 42 ---- .../src/main/java/develup/api/PairApi.java | 33 --- .../main/java/develup/api/SubmissionApi.java | 53 ----- .../develup/api/exception/ExceptionType.java | 7 +- .../application/mission/MissionResponse.java | 33 --- .../application/mission/MissionService.java | 42 ---- .../submission/CreateSubmissionRequest.java | 16 -- .../submission/MyMissionResponse.java | 23 -- .../application/submission/PairService.java | 107 ---------- .../submission/SubmissionResponse.java | 22 -- .../submission/SubmissionService.java | 80 ------- .../java/develup/domain/mission/Language.java | 6 - .../java/develup/domain/mission/Mission.java | 72 ------- .../domain/mission/MissionRepository.java | 6 - .../develup/domain/submission/MyMission.java | 48 ----- .../java/develup/domain/submission/Pair.java | 115 ---------- .../domain/submission/PairRepository.java | 24 --- .../develup/domain/submission/PairStatus.java | 30 --- .../develup/domain/submission/Submission.java | 97 --------- .../submission/SubmissionRepository.java | 31 --- backend/src/main/resources/data.sql | 42 ---- .../test/java/develup/api/MemberApiTest.java | 2 +- .../mission/MissionServiceTest.java | 111 ---------- .../submission/PairServiceTest.java | 199 ------------------ .../submission/SubmissionServiceTest.java | 120 ----------- .../domain/submission/PairRepositoryTest.java | 33 --- .../develup/domain/submission/PairTest.java | 83 -------- .../submission/SubmissionRepositoryTest.java | 79 ------- .../domain/submission/SubmissionTest.java | 54 ----- .../develup/support/data/MissionTestData.java | 67 ------ .../develup/support/data/PairTestData.java | 57 ----- .../support/data/SubmissionTestData.java | 60 ------ backend/src/test/resources/mymissions.sql | 50 ----- 34 files changed, 3 insertions(+), 1843 deletions(-) delete mode 100644 backend/src/main/java/develup/api/MissionApi.java delete mode 100644 backend/src/main/java/develup/api/PairApi.java delete mode 100644 backend/src/main/java/develup/api/SubmissionApi.java delete mode 100644 backend/src/main/java/develup/application/mission/MissionResponse.java delete mode 100644 backend/src/main/java/develup/application/mission/MissionService.java delete mode 100644 backend/src/main/java/develup/application/submission/CreateSubmissionRequest.java delete mode 100644 backend/src/main/java/develup/application/submission/MyMissionResponse.java delete mode 100644 backend/src/main/java/develup/application/submission/PairService.java delete mode 100644 backend/src/main/java/develup/application/submission/SubmissionResponse.java delete mode 100644 backend/src/main/java/develup/application/submission/SubmissionService.java delete mode 100644 backend/src/main/java/develup/domain/mission/Language.java delete mode 100644 backend/src/main/java/develup/domain/mission/Mission.java delete mode 100644 backend/src/main/java/develup/domain/mission/MissionRepository.java delete mode 100644 backend/src/main/java/develup/domain/submission/MyMission.java delete mode 100644 backend/src/main/java/develup/domain/submission/Pair.java delete mode 100644 backend/src/main/java/develup/domain/submission/PairRepository.java delete mode 100644 backend/src/main/java/develup/domain/submission/PairStatus.java delete mode 100644 backend/src/main/java/develup/domain/submission/Submission.java delete mode 100644 backend/src/main/java/develup/domain/submission/SubmissionRepository.java delete mode 100644 backend/src/test/java/develup/application/mission/MissionServiceTest.java delete mode 100644 backend/src/test/java/develup/application/submission/PairServiceTest.java delete mode 100644 backend/src/test/java/develup/application/submission/SubmissionServiceTest.java delete mode 100644 backend/src/test/java/develup/domain/submission/PairRepositoryTest.java delete mode 100644 backend/src/test/java/develup/domain/submission/PairTest.java delete mode 100644 backend/src/test/java/develup/domain/submission/SubmissionRepositoryTest.java delete mode 100644 backend/src/test/java/develup/domain/submission/SubmissionTest.java delete mode 100644 backend/src/test/java/develup/support/data/MissionTestData.java delete mode 100644 backend/src/test/java/develup/support/data/PairTestData.java delete mode 100644 backend/src/test/java/develup/support/data/SubmissionTestData.java delete mode 100644 backend/src/test/resources/mymissions.sql diff --git a/backend/src/main/java/develup/api/MemberApi.java b/backend/src/main/java/develup/api/MemberApi.java index e3e6cd8c..215e0ebe 100644 --- a/backend/src/main/java/develup/api/MemberApi.java +++ b/backend/src/main/java/develup/api/MemberApi.java @@ -21,7 +21,7 @@ public MemberApi(MemberService memberService) { this.memberService = memberService; } - @GetMapping("/member/mine") + @GetMapping("/members/mine") @Operation(summary = "내 정보 조회 API", description = "'token' 쿠키를 이용해서 내 정보를 조회합니다.") public ResponseEntity> getMyInfo(@Auth Accessor accessor) { MemberResponse response = memberService.getMemberById(accessor.id()); diff --git a/backend/src/main/java/develup/api/MissionApi.java b/backend/src/main/java/develup/api/MissionApi.java deleted file mode 100644 index 6742743f..00000000 --- a/backend/src/main/java/develup/api/MissionApi.java +++ /dev/null @@ -1,42 +0,0 @@ -package develup.api; - -import java.util.List; -import develup.api.auth.Auth; -import develup.api.common.ApiResponse; -import develup.application.auth.Accessor; -import develup.application.mission.MissionResponse; -import develup.application.mission.MissionService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@Tag(name = "미션 API") -class MissionApi { - - private final MissionService missionService; - - public MissionApi(MissionService missionService) { - this.missionService = missionService; - } - - @GetMapping("/missions") - @Operation(summary = "미션 목록 조회 API", description = "미션 목록을 조회합니다.") - public ResponseEntity>> getMissions() { - return ResponseEntity.ok(new ApiResponse<>(missionService.getMissions())); - } - - @GetMapping("/missions/{missionId}") - @Operation(summary = "미션 단건 조회 API", description = "미션 단건을 조회합니다. (제출된 미션 여부를 포함)") - public ResponseEntity> getMission( - @Auth(required = false) Accessor accessor, - @PathVariable Long missionId - ) { - MissionResponse response = missionService.getMissionById(accessor, missionId); - - return ResponseEntity.ok(new ApiResponse<>(response)); - } -} diff --git a/backend/src/main/java/develup/api/PairApi.java b/backend/src/main/java/develup/api/PairApi.java deleted file mode 100644 index 7a6302c8..00000000 --- a/backend/src/main/java/develup/api/PairApi.java +++ /dev/null @@ -1,33 +0,0 @@ -package develup.api; - -import develup.api.auth.Auth; -import develup.api.common.ApiResponse; -import develup.application.auth.Accessor; -import develup.application.submission.MyMissionResponse; -import develup.application.submission.PairService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@Tag(name = "페어 API") -public class PairApi { - - private final PairService pairService; - - public PairApi(PairService pairService) { - this.pairService = pairService; - } - - @PostMapping("/pair-review/{submissionId}") - @Operation(summary = "코드 리뷰 완료 API", description = "코드 리뷰를 완료한 뒤 변경된 페어 매칭 정보를 반환한다.") - public ResponseEntity> completeReview( - @Auth Accessor accessor, - @PathVariable Long submissionId - ) { - return ResponseEntity.ok(new ApiResponse<>(pairService.completeReview(accessor.id(), submissionId))); - } -} diff --git a/backend/src/main/java/develup/api/SubmissionApi.java b/backend/src/main/java/develup/api/SubmissionApi.java deleted file mode 100644 index 4819c17b..00000000 --- a/backend/src/main/java/develup/api/SubmissionApi.java +++ /dev/null @@ -1,53 +0,0 @@ -package develup.api; - -import java.net.URI; -import java.util.List; -import develup.api.auth.Auth; -import develup.api.common.ApiResponse; -import develup.application.auth.Accessor; -import develup.application.submission.CreateSubmissionRequest; -import develup.application.submission.MyMissionResponse; -import develup.application.submission.SubmissionResponse; -import develup.application.submission.SubmissionService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@Tag(name = "제출 API") -class SubmissionApi { - - private final SubmissionService submissionService; - - public SubmissionApi(SubmissionService submissionService) { - this.submissionService = submissionService; - } - - @GetMapping("/submissions") - @Operation(summary = "내 제출 목록 조회 API", description = "내 제출 목록을 조회합니다.") - public ResponseEntity>> getMyMissions(@Auth Accessor accessor) { - return ResponseEntity.ok(new ApiResponse<>(submissionService.getMyMissions(accessor.id()))); - } - - @PostMapping("/submissions") - @Operation(summary = "미션 제출 API", description = "미션을 제출합니다.") - public ResponseEntity> postSubmission( - @Auth Accessor accessor, - @RequestBody CreateSubmissionRequest request - ) { - SubmissionResponse response = submissionService.submit(accessor.id(), request); - - return ResponseEntity.created(URI.create("/submissions/" + response.id())) - .body(new ApiResponse<>(response)); - } - - @GetMapping("/submissions/now") - @Operation(summary = "최근 진행 중인 미션 단건 조회 API", description = "최근 진행 중인 미션을 단건 조회합니다.") - public ResponseEntity> getMyMission(@Auth Accessor accessor) { - return ResponseEntity.ok(new ApiResponse<>(submissionService.getMyMission(accessor.id()))); - } -} diff --git a/backend/src/main/java/develup/api/exception/ExceptionType.java b/backend/src/main/java/develup/api/exception/ExceptionType.java index f3706201..3fbc5c09 100644 --- a/backend/src/main/java/develup/api/exception/ExceptionType.java +++ b/backend/src/main/java/develup/api/exception/ExceptionType.java @@ -10,12 +10,7 @@ public enum ExceptionType { TOKEN_NOT_FOUND(HttpStatus.UNAUTHORIZED, "토큰이 존재하지 않습니다."), TOKEN_EXPIRED(HttpStatus.UNAUTHORIZED, "토큰이 만료되었습니다."), INVALID_TOKEN(HttpStatus.UNAUTHORIZED, "유효하지 않는 토큰입니다."), - SAME_SUBMISSION_PAIR(HttpStatus.BAD_REQUEST, "같은 제출끼리 페어가 될 수 없습니다."), - MISSION_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 미션입니다."), - MATCH_SUBMISSION_NOT_FOUND(HttpStatus.BAD_REQUEST, "매칭할 제출이 존재하지 않습니다."), - SUBMISSION_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 제출입니다."), - ALREADY_MATCHED_SUBMISSION(HttpStatus.BAD_REQUEST, "이미 매칭된 제출입니다."), - ALREADY_REVIEWED(HttpStatus.CONFLICT, "이미 리뷰를 완료했습니다."), + ; private final HttpStatus status; diff --git a/backend/src/main/java/develup/application/mission/MissionResponse.java b/backend/src/main/java/develup/application/mission/MissionResponse.java deleted file mode 100644 index 8a0b2f3e..00000000 --- a/backend/src/main/java/develup/application/mission/MissionResponse.java +++ /dev/null @@ -1,33 +0,0 @@ -package develup.application.mission; - -import develup.domain.mission.Language; -import develup.domain.mission.Mission; - -public record MissionResponse( - Long id, - String title, - Language language, - String description, - String thumbnail, - String url, - boolean isSubmitted, - String submittedPrUrl -) { - - public static MissionResponse from(Mission mission) { - return of(mission, false, null); - } - - public static MissionResponse of(Mission mission, boolean isSubmitted, String submittedPrUrl) { - return new MissionResponse( - mission.getId(), - mission.getTitle(), - mission.getLanguage(), - mission.getDescription(), - mission.getThumbnail(), - mission.getUrl(), - isSubmitted, - submittedPrUrl - ); - } -} diff --git a/backend/src/main/java/develup/application/mission/MissionService.java b/backend/src/main/java/develup/application/mission/MissionService.java deleted file mode 100644 index 2127c374..00000000 --- a/backend/src/main/java/develup/application/mission/MissionService.java +++ /dev/null @@ -1,42 +0,0 @@ -package develup.application.mission; - -import java.util.List; -import develup.api.exception.DevelupException; -import develup.api.exception.ExceptionType; -import develup.application.auth.Accessor; -import develup.domain.mission.Mission; -import develup.domain.mission.MissionRepository; -import develup.domain.submission.SubmissionRepository; -import org.springframework.stereotype.Service; - -@Service -public class MissionService { - - private final MissionRepository missionRepository; - private final SubmissionRepository submissionRepository; - - public MissionService(MissionRepository missionRepository, SubmissionRepository submissionRepository) { - this.missionRepository = missionRepository; - this.submissionRepository = submissionRepository; - } - - public List getMissions() { - return missionRepository.findAll() - .stream() - .map(MissionResponse::from) - .toList(); - } - - public MissionResponse getMissionById(Accessor accessor, Long missionId) { - Mission mission = missionRepository.findById(missionId) - .orElseThrow(() -> new DevelupException(ExceptionType.MISSION_NOT_FOUND)); - - if (accessor.isGuest()) { - return MissionResponse.from(mission); - } - - return submissionRepository.findFirstByMember_IdAndMission_IdOrderByIdDesc(accessor.id(), missionId) - .map(it -> MissionResponse.of(mission, true, it.getUrl())) - .orElseGet(() -> MissionResponse.from(mission)); - } -} diff --git a/backend/src/main/java/develup/application/submission/CreateSubmissionRequest.java b/backend/src/main/java/develup/application/submission/CreateSubmissionRequest.java deleted file mode 100644 index ac5102d0..00000000 --- a/backend/src/main/java/develup/application/submission/CreateSubmissionRequest.java +++ /dev/null @@ -1,16 +0,0 @@ -package develup.application.submission; - -import develup.domain.member.Member; -import develup.domain.mission.Mission; -import develup.domain.submission.Submission; - -public record CreateSubmissionRequest( - Long missionId, - String url, - String comment -) { - - public Submission toSubmission(Member member, Mission mission) { - return new Submission(url, comment, member, mission); - } -} diff --git a/backend/src/main/java/develup/application/submission/MyMissionResponse.java b/backend/src/main/java/develup/application/submission/MyMissionResponse.java deleted file mode 100644 index 24b12d9a..00000000 --- a/backend/src/main/java/develup/application/submission/MyMissionResponse.java +++ /dev/null @@ -1,23 +0,0 @@ -package develup.application.submission; - -import develup.application.mission.MissionResponse; -import develup.domain.submission.MyMission; - -public record MyMissionResponse( - Long id, - MissionResponse mission, - String myPrLink, - String pairPrLink, - String status -) { - - public static MyMissionResponse from(MyMission myMission) { - return new MyMissionResponse( - myMission.getId(), - MissionResponse.from(myMission.getMission()), - myMission.getMyPrLink(), - myMission.getPairPrLink(), - myMission.getStatusDescription() - ); - } -} diff --git a/backend/src/main/java/develup/application/submission/PairService.java b/backend/src/main/java/develup/application/submission/PairService.java deleted file mode 100644 index 08daa4bc..00000000 --- a/backend/src/main/java/develup/application/submission/PairService.java +++ /dev/null @@ -1,107 +0,0 @@ -package develup.application.submission; - -import java.util.List; -import java.util.Optional; -import develup.api.exception.DevelupException; -import develup.api.exception.ExceptionType; -import develup.domain.submission.MyMission; -import develup.domain.submission.Pair; -import develup.domain.submission.PairRepository; -import develup.domain.submission.PairStatus; -import develup.domain.submission.Submission; -import develup.domain.submission.SubmissionRepository; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@Transactional -public class PairService { - - private final SubmissionRepository submissionRepository; - private final PairRepository pairRepository; - - public PairService(SubmissionRepository submissionRepository, PairRepository pairRepository) { - this.submissionRepository = submissionRepository; - this.pairRepository = pairRepository; - } - - public MyMissionResponse completeReview(Long memberId, Long submissionId) { - Pair main = pairRepository.findByMain_Id(submissionId) - .orElseThrow(() -> new DevelupException(ExceptionType.SUBMISSION_NOT_FOUND)); - Pair other = pairRepository.findByMain_Id(main.getOtherId()) - .orElseThrow(() -> new DevelupException(ExceptionType.SUBMISSION_NOT_FOUND)); - - validateSubmissionOwner(memberId, main); - main.completeReview(other); - - pairRepository.save(main); - pairRepository.save(other); - - MyMission myMission = createMyMission(main); - return MyMissionResponse.from(myMission); - } - - private void validateSubmissionOwner(Long memberId, Pair main) { - if (!main.isMainOwnerId(memberId)) { - throw new DevelupException(ExceptionType.FORBIDDEN); - } - } - - private MyMission createMyMission(Pair main) { - Submission mainSubmission = main.getMain(); - Submission otherSubMission = main.getOther(); - return new MyMission( - mainSubmission.getId(), - mainSubmission.getMission(), - mainSubmission.getUrl(), - otherSubMission.getUrl(), - main.getStatus() - ); - } - - public boolean canMatch(Submission submission) { - return findCanMatchSubmission(submission).isPresent(); - } - - public void match(Submission submission) { - validateSubmitted(submission); - validateAlreadyMatched(submission); - matchWithOtherSubmission(submission); - } - - private void validateSubmitted(Submission submission) { - boolean isSubmitted = submissionRepository.existsById(submission.getId()); - - if (!isSubmitted) { - throw new DevelupException(ExceptionType.SUBMISSION_NOT_FOUND); - } - } - - private void validateAlreadyMatched(Submission submission) { - List nonMatchedSubmissions = submissionRepository - .findNonMatchedSubmissions(submission.getMission()); - - if (!nonMatchedSubmissions.contains(submission)) { - throw new DevelupException(ExceptionType.ALREADY_MATCHED_SUBMISSION); - } - } - - private void matchWithOtherSubmission(Submission submission) { - Submission other = findCanMatchSubmission(submission) - .orElseThrow(() -> new DevelupException(ExceptionType.MATCH_SUBMISSION_NOT_FOUND)); - Pair mainPair = new Pair(submission, other, PairStatus.MATCHED); - Pair otherPair = new Pair(other, submission, PairStatus.MATCHED); - - pairRepository.save(mainPair); - pairRepository.save(otherPair); - } - - private Optional findCanMatchSubmission(Submission submission) { - List nonMatchedSubmissions = submissionRepository - .findNonMatchedSubmissions(submission.getMission()); - - return nonMatchedSubmissions.stream() - .filter(it -> it.isNotSameOwner(submission)) - .findFirst(); - } -} diff --git a/backend/src/main/java/develup/application/submission/SubmissionResponse.java b/backend/src/main/java/develup/application/submission/SubmissionResponse.java deleted file mode 100644 index 6371d611..00000000 --- a/backend/src/main/java/develup/application/submission/SubmissionResponse.java +++ /dev/null @@ -1,22 +0,0 @@ -package develup.application.submission; - -import develup.domain.submission.Submission; - -public record SubmissionResponse( - Long id, - Long memberId, - Long missionId, - String url, - String comment -) { - - public static SubmissionResponse from(Submission submission) { - return new SubmissionResponse( - submission.getId(), - submission.getMemberId(), - submission.getMissionId(), - submission.getUrl(), - submission.getComment() - ); - } -} diff --git a/backend/src/main/java/develup/application/submission/SubmissionService.java b/backend/src/main/java/develup/application/submission/SubmissionService.java deleted file mode 100644 index 0b566feb..00000000 --- a/backend/src/main/java/develup/application/submission/SubmissionService.java +++ /dev/null @@ -1,80 +0,0 @@ -package develup.application.submission; - -import java.util.List; -import develup.api.exception.DevelupException; -import develup.api.exception.ExceptionType; -import develup.domain.member.Member; -import develup.domain.member.MemberRepository; -import develup.domain.mission.Mission; -import develup.domain.mission.MissionRepository; -import develup.domain.submission.MyMission; -import develup.domain.submission.PairRepository; -import develup.domain.submission.Submission; -import develup.domain.submission.SubmissionRepository; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@Transactional -public class SubmissionService { - - private final MissionRepository missionRepository; - private final SubmissionRepository submissionRepository; - private final MemberRepository memberRepository; - private final PairRepository pairRepository; - private final PairService pairService; - - public SubmissionService( - MissionRepository missionRepository, - SubmissionRepository submissionRepository, - MemberRepository memberRepository, - PairRepository pairRepository, - PairService pairService - ) { - this.missionRepository = missionRepository; - this.submissionRepository = submissionRepository; - this.memberRepository = memberRepository; - this.pairRepository = pairRepository; - this.pairService = pairService; - } - - public SubmissionResponse submit(Long memberId, CreateSubmissionRequest request) { - Mission mission = missionRepository.findById(request.missionId()) - .orElseThrow(() -> new DevelupException(ExceptionType.MISSION_NOT_FOUND)); - Member member = memberRepository.findById(memberId) - .orElseThrow(() -> new DevelupException(ExceptionType.MEMBER_NOT_FOUND)); - - Submission newSubmission = submissionRepository.save(request.toSubmission(member, mission)); - tryMatch(newSubmission); - - return SubmissionResponse.from(newSubmission); - } - - private void tryMatch(Submission newSubmission) { - if (pairService.canMatch(newSubmission)) { - pairService.match(newSubmission); - } - } - - public List getMyMissions(Long memberId) { - List submissions = submissionRepository.findAllByMember_IdOrderByIdDesc(memberId); - - return submissions.stream() - .map(this::findMyMission) - .map(MyMissionResponse::from) - .toList(); - } - - public MyMissionResponse getMyMission(Long memberId) { - return submissionRepository.findFirstByMember_IdOrderByIdDesc(memberId) - .map(this::findMyMission) - .filter(MyMission::isNotFinished) - .map(MyMissionResponse::from) - .orElse(null); - } - - private MyMission findMyMission(Submission submission) { - return pairRepository.findMyMissionBySubmission(submission) - .orElseGet(() -> MyMission.waitPairMatching(submission)); - } -} diff --git a/backend/src/main/java/develup/domain/mission/Language.java b/backend/src/main/java/develup/domain/mission/Language.java deleted file mode 100644 index cbeee472..00000000 --- a/backend/src/main/java/develup/domain/mission/Language.java +++ /dev/null @@ -1,6 +0,0 @@ -package develup.domain.mission; - -public enum Language { - - JAVA, JAVASCRIPT -} diff --git a/backend/src/main/java/develup/domain/mission/Mission.java b/backend/src/main/java/develup/domain/mission/Mission.java deleted file mode 100644 index 7d0941b0..00000000 --- a/backend/src/main/java/develup/domain/mission/Mission.java +++ /dev/null @@ -1,72 +0,0 @@ -package develup.domain.mission; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; - -@Entity -public class Mission { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(nullable = false) - private String title; - - @Column(nullable = false) - @Enumerated(EnumType.STRING) - private Language language; - - @Column(nullable = false, columnDefinition = "text") - private String description; - - @Column(nullable = false, columnDefinition = "text") - private String thumbnail; - - @Column(nullable = false) - private String url; - - protected Mission() { - } - - public Mission(String title, Language language, String description, String thumbnail, String url) { - this(null, title, language, description, thumbnail, url); - } - - public Mission(Long id, String title, Language language, String description, String thumbnail, String url) { - this.title = title; - this.language = language; - this.description = description; - this.thumbnail = thumbnail; - this.url = url; - } - - public Long getId() { - return id; - } - - public String getTitle() { - return title; - } - - public Language getLanguage() { - return language; - } - - public String getDescription() { - return description; - } - - public String getThumbnail() { - return thumbnail; - } - - public String getUrl() { - return url; - } -} diff --git a/backend/src/main/java/develup/domain/mission/MissionRepository.java b/backend/src/main/java/develup/domain/mission/MissionRepository.java deleted file mode 100644 index 9a6722aa..00000000 --- a/backend/src/main/java/develup/domain/mission/MissionRepository.java +++ /dev/null @@ -1,6 +0,0 @@ -package develup.domain.mission; - -import org.springframework.data.jpa.repository.JpaRepository; - -public interface MissionRepository extends JpaRepository { -} diff --git a/backend/src/main/java/develup/domain/submission/MyMission.java b/backend/src/main/java/develup/domain/submission/MyMission.java deleted file mode 100644 index 322f6afe..00000000 --- a/backend/src/main/java/develup/domain/submission/MyMission.java +++ /dev/null @@ -1,48 +0,0 @@ -package develup.domain.submission; - -import develup.domain.mission.Mission; - -public class MyMission { - - private final Long id; - private final Mission mission; - private final String myPrLink; - private final String pairPrLink; - private final PairStatus status; - - public MyMission(Long id, Mission mission, String myPrLink, String pairPrLink, PairStatus status) { - this.id = id; - this.mission = mission; - this.myPrLink = myPrLink; - this.pairPrLink = pairPrLink; - this.status = status; - } - - public static MyMission waitPairMatching(Submission submission) { - return new MyMission(submission.getId(), submission.getMission(), submission.getUrl(), null, PairStatus.WAITING); - } - - public boolean isNotFinished() { - return status != PairStatus.ALL_FINISHED; - } - - public Long getId() { - return id; - } - - public Mission getMission() { - return mission; - } - - public String getMyPrLink() { - return myPrLink; - } - - public String getPairPrLink() { - return pairPrLink; - } - - public String getStatusDescription() { - return status.getDescription(); - } -} diff --git a/backend/src/main/java/develup/domain/submission/Pair.java b/backend/src/main/java/develup/domain/submission/Pair.java deleted file mode 100644 index b9e41367..00000000 --- a/backend/src/main/java/develup/domain/submission/Pair.java +++ /dev/null @@ -1,115 +0,0 @@ -package develup.domain.submission; - -import java.util.Objects; -import develup.api.exception.DevelupException; -import develup.api.exception.ExceptionType; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.OneToOne; - -@Entity -public class Pair { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @OneToOne - @JoinColumn(name = "main_submission", nullable = false) - private Submission main; - - @OneToOne - @JoinColumn(name = "pair_submission", nullable = false) - private Submission other; - - @Column(nullable = false) - @Enumerated(EnumType.STRING) - private PairStatus status; - - protected Pair() { - } - - public Pair(Long id, Submission main, Submission other, PairStatus status) { - this(main, other, status); - this.id = id; - } - - public Pair(Submission main, Submission other, PairStatus status) { - if (main.equals(other)) { - throw new DevelupException(ExceptionType.SAME_SUBMISSION_PAIR); - } - - this.main = main; - this.other = other; - this.status = status; - } - - public void completeReview(Pair other) { - validatePairStatus(); - validateOtherPairStatus(other); - changePairStatus(); - changeOtherPairStatus(other); - } - - private void validatePairStatus() { - if (status != PairStatus.MATCHED && status != PairStatus.PARTNER_REVIEW_COMPLETED) { - throw new DevelupException(ExceptionType.ALREADY_REVIEWED); - } - } - - private void validateOtherPairStatus(Pair other) { - if (other.status != PairStatus.MATCHED && other.status != PairStatus.MY_REVIEW_COMPLETED) { - throw new DevelupException(ExceptionType.ALREADY_REVIEWED); - } - } - - private void changePairStatus() { - if (status == PairStatus.MATCHED) { - status = PairStatus.MY_REVIEW_COMPLETED; - return; - } - if (status == PairStatus.PARTNER_REVIEW_COMPLETED) { - status = PairStatus.ALL_FINISHED; - } - } - - private void changeOtherPairStatus(Pair other) { - if (other.status == PairStatus.MATCHED) { - other.status = PairStatus.PARTNER_REVIEW_COMPLETED; - return; - } - if (other.status == PairStatus.MY_REVIEW_COMPLETED) { - other.status = PairStatus.ALL_FINISHED; - } - } - - public boolean isMainOwnerId(Long expectedOwnerId) { - return Objects.equals(main.getMember().getId(), expectedOwnerId); - } - - public Long getId() { - return id; - } - - public Submission getMain() { - return main; - } - - public Submission getOther() { - return other; - } - - public Long getOtherId() { - return other.getId(); - } - - public PairStatus getStatus() { - return status; - } -} diff --git a/backend/src/main/java/develup/domain/submission/PairRepository.java b/backend/src/main/java/develup/domain/submission/PairRepository.java deleted file mode 100644 index 4e8f5735..00000000 --- a/backend/src/main/java/develup/domain/submission/PairRepository.java +++ /dev/null @@ -1,24 +0,0 @@ -package develup.domain.submission; - -import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; - -public interface PairRepository extends JpaRepository { - - @Query(""" - SELECT new develup.domain.submission.MyMission( - p.main.id, - p.main.mission, - p.main.url, - p.other.url, - p.status - ) - FROM Pair p - WHERE - p.main = :submission - """) - Optional findMyMissionBySubmission(Submission submission); - - Optional findByMain_Id(Long mainId); -} diff --git a/backend/src/main/java/develup/domain/submission/PairStatus.java b/backend/src/main/java/develup/domain/submission/PairStatus.java deleted file mode 100644 index 11b21356..00000000 --- a/backend/src/main/java/develup/domain/submission/PairStatus.java +++ /dev/null @@ -1,30 +0,0 @@ -package develup.domain.submission; - -public enum PairStatus { - - WAITING("매칭 대기"), - MATCHED("매칭 됨"), - MY_REVIEW_COMPLETED("내가 리뷰 완료"), - PARTNER_REVIEW_COMPLETED("상대가 리뷰 완료"), - ALL_FINISHED("완료"); - - private final String description; - - PairStatus(String description) { - this.description = description; - } - - public PairStatus toOtherStatus() { - return switch (this) { - case MATCHED -> MATCHED; - case WAITING -> WAITING; - case ALL_FINISHED -> ALL_FINISHED; - case MY_REVIEW_COMPLETED -> PARTNER_REVIEW_COMPLETED; - case PARTNER_REVIEW_COMPLETED -> MY_REVIEW_COMPLETED; - }; - } - - public String getDescription() { - return description; - } -} diff --git a/backend/src/main/java/develup/domain/submission/Submission.java b/backend/src/main/java/develup/domain/submission/Submission.java deleted file mode 100644 index 036c211c..00000000 --- a/backend/src/main/java/develup/domain/submission/Submission.java +++ /dev/null @@ -1,97 +0,0 @@ -package develup.domain.submission; - -import java.util.Objects; -import develup.domain.member.Member; -import develup.domain.mission.Mission; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; - -@Entity -public class Submission { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(nullable = false) - private String url; - - private String comment; - - @ManyToOne - @JoinColumn(nullable = false) - private Member member; - - @ManyToOne - @JoinColumn(nullable = false) - private Mission mission; - - protected Submission() { - } - - public Submission(String url, String comment, Member member, Mission mission) { - this(null, url, comment, member, mission); - } - - public Submission(Long id, String url, String comment, Member member, Mission mission) { - this.id = id; - this.url = url; - this.comment = comment; - this.member = member; - this.mission = mission; - } - - public boolean isNotSameOwner(Submission other) { - return !this.member.equals(other.member); - } - - public Long getId() { - return id; - } - - public String getUrl() { - return url; - } - - public String getComment() { - return comment; - } - - public Member getMember() { - return member; - } - - public Mission getMission() { - return mission; - } - - public Long getMemberId() { - return member.getId(); - } - - public Long getMissionId() { - return mission.getId(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof Submission submission)) { - return false; - } - - return this.getId() != null && Objects.equals(getId(), submission.getId()); - } - - @Override - public int hashCode() { - return Objects.hash(getId()); - } -} diff --git a/backend/src/main/java/develup/domain/submission/SubmissionRepository.java b/backend/src/main/java/develup/domain/submission/SubmissionRepository.java deleted file mode 100644 index 5d4aecbf..00000000 --- a/backend/src/main/java/develup/domain/submission/SubmissionRepository.java +++ /dev/null @@ -1,31 +0,0 @@ -package develup.domain.submission; - -import java.util.List; -import java.util.Optional; -import develup.domain.mission.Mission; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; - -public interface SubmissionRepository extends JpaRepository { - - List findAllByMember_IdOrderByIdDesc(Long id); - - @Query(""" - SELECT s - FROM Submission s - WHERE - s.mission = :mission AND - NOT EXISTS ( - SELECT 1 - FROM Pair p - WHERE - p.main = s OR - p.other = s - ) - """) - List findNonMatchedSubmissions(Mission mission); - - Optional findFirstByMember_IdOrderByIdDesc(Long id); - - Optional findFirstByMember_IdAndMission_IdOrderByIdDesc(Long memberId, Long missionId); -} diff --git a/backend/src/main/resources/data.sql b/backend/src/main/resources/data.sql index a6a30132..78507db4 100644 --- a/backend/src/main/resources/data.sql +++ b/backend/src/main/resources/data.sql @@ -1,18 +1,3 @@ -INSERT INTO mission (title, language, description, thumbnail, url) -VALUES ('루터회관 흡연 단속', 'JAVA', 'https://raw.githubusercontent.com/develup-mission/java-smoking/main/README.md', - 'https://raw.githubusercontent.com/develup-mission/docs/main/image/java-smoking.png', - 'https://github.com/develup-mission/java-smoking'); - -INSERT INTO mission (title, language, description, thumbnail, url) -VALUES ('단어 퍼즐 게임', 'JAVA', 'https://raw.githubusercontent.com/develup-mission/java-word-puzzle/main/README.md', - 'https://raw.githubusercontent.com/develup-mission/docs/main/image/java-guessing-number.png', - 'https://github.com/develup-mission/java-word-puzzle'); - -INSERT INTO mission (title, language, description, thumbnail, url) -VALUES ('숫자 추리 게임', 'JAVA', 'https://raw.githubusercontent.com/develup-mission/java-guessing-number/main/README.md', - 'https://raw.githubusercontent.com/develup-mission/docs/main/image/java-word-puzzle.png', - 'https://github.com/develup-mission/java-guessing-number'); - INSERT INTO member (email, provider, social_id, name, image_url) VALUES ('test1@gmail.com', 'GITHUB', '1234', '구름', 'www.naver.com'); @@ -21,30 +6,3 @@ VALUES ('test1@gmail.com', 'GITHUB', '1234', '리브', 'www.naver.com'); INSERT INTO member (email, provider, social_id, name, image_url) VALUES ('test1@gmail.com', 'GITHUB', '1234', '아톰', 'www.naver.com'); - -INSERT INTO submission (member_id, mission_id, url, comment) -VALUES (1, 1, 'https://github.com/develup-mission/java-smoking/pull/1', '코멘트 1'); - -INSERT INTO submission (member_id, mission_id, url, comment) -VALUES (2, 1, 'https://github.com/develup-mission/java-smoking/pull/2', '코멘트 2'); - -INSERT INTO submission (member_id, mission_id, url, comment) -VALUES (1, 2, 'https://github.com/develup-mission/java-word-puzzle/pull/1', '코멘트 3'); - -INSERT INTO submission (member_id, mission_id, url, comment) -VALUES (2, 2, 'https://github.com/develup-mission/java-word-puzzle/pull/2', '코멘트 4'); - -INSERT INTO submission (member_id, mission_id, url, comment) -VALUES (1, 3, 'https://github.com/develup-mission/java-guessing-number/pull/1', '코멘트 5'); - -INSERT INTO pair (main_submission, pair_submission, status) -VALUES (1, 2, 'ALL_FINISHED'); - -INSERT INTO pair (main_submission, pair_submission, status) -VALUES (2, 1, 'ALL_FINISHED'); - -INSERT INTO pair (main_submission, pair_submission, status) -VALUES (3, 4, 'MY_REVIEW_COMPLETED'); - -INSERT INTO pair (main_submission, pair_submission, status) -VALUES (4, 3, 'PARTNER_REVIEW_COMPLETED'); diff --git a/backend/src/test/java/develup/api/MemberApiTest.java b/backend/src/test/java/develup/api/MemberApiTest.java index 47bb15e5..0e21fae7 100644 --- a/backend/src/test/java/develup/api/MemberApiTest.java +++ b/backend/src/test/java/develup/api/MemberApiTest.java @@ -39,7 +39,7 @@ void getMyInfo() throws Exception { .willReturn(response); mockMvc.perform( - get("/member/mine") + get("/members/mine") .cookie(new Cookie("token", "mock_token")) ) .andDo(print()) diff --git a/backend/src/test/java/develup/application/mission/MissionServiceTest.java b/backend/src/test/java/develup/application/mission/MissionServiceTest.java deleted file mode 100644 index a76be727..00000000 --- a/backend/src/test/java/develup/application/mission/MissionServiceTest.java +++ /dev/null @@ -1,111 +0,0 @@ -package develup.application.mission; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import java.util.List; -import develup.api.exception.DevelupException; -import develup.application.auth.Accessor; -import develup.domain.member.Member; -import develup.domain.member.MemberRepository; -import develup.domain.mission.Mission; -import develup.domain.mission.MissionRepository; -import develup.domain.submission.Submission; -import develup.domain.submission.SubmissionRepository; -import develup.support.IntegrationTestSupport; -import develup.support.data.MemberTestData; -import develup.support.data.MissionTestData; -import develup.support.data.SubmissionTestData; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -class MissionServiceTest extends IntegrationTestSupport { - - @Autowired - private MissionService missionService; - - @Autowired - private MissionRepository missionRepository; - - @Autowired - private MemberRepository memberRepository; - - @Autowired - private SubmissionRepository submissionRepository; - - @Test - @DisplayName("모든 미션을 조회한다.") - void getMissions() { - createMission(); - createMission(); - - List missions = missionService.getMissions(); - - assertThat(missions).hasSize(2); - } - - @Test - @DisplayName("로그인하지 않은 사용자가 미션 식별자로 미션 단건을 조회한다.") - void getMissionByIdWhenGuest() { - Mission mission = createMission(); - - MissionResponse response = missionService.getMissionById(Accessor.GUEST, mission.getId()); - - assertThat(response).isEqualTo(MissionResponse.from(mission)); - } - - @Test - @DisplayName("로그인한 멤버가 제출하지 않은 미션을 미션 식별자로 미션 단건을 조회한다.") - void getMissionByIdWhenNotSubmitted() { - Mission mission = createMission(); - Member member = createMember(); - Accessor accessor = new Accessor(member.getId()); - - MissionResponse response = missionService.getMissionById(accessor, mission.getId()); - - assertThat(response).isEqualTo(MissionResponse.from(mission)); - } - - @Test - @DisplayName("로그인한 멤버가 제출한 미션을 미션 식별자로 미션 단건을 조회한다.") - void getMissionByIdWhenSubmitted() { - Mission mission = createMission(); - Member member = createMember(); - Submission submission = createSubmission(mission, member); - Accessor accessor = new Accessor(member.getId()); - - MissionResponse response = missionService.getMissionById(accessor, mission.getId()); - - assertThat(response).isEqualTo(MissionResponse.of(mission, true, submission.getUrl())); - } - - @Test - @DisplayName("존재하지 않는 미션 식별자로 미션 조회시 예외가 발생한다.") - void getMissionByUndefinedId() { - assertThatThrownBy(() -> missionService.getMissionById(Accessor.GUEST, -1L)) - .isInstanceOf(DevelupException.class) - .hasMessage("존재하지 않는 미션입니다."); - } - - private Member createMember() { - Member member = MemberTestData.defaultMember().build(); - - return memberRepository.save(member); - } - - private Mission createMission() { - Mission mission = MissionTestData.defaultMission().build(); - - return missionRepository.save(mission); - } - - private Submission createSubmission(Mission mission, Member member) { - Submission submission = SubmissionTestData.defaultSubmission() - .withMember(member) - .withMission(mission) - .build(); - - return submissionRepository.save(submission); - } -} diff --git a/backend/src/test/java/develup/application/submission/PairServiceTest.java b/backend/src/test/java/develup/application/submission/PairServiceTest.java deleted file mode 100644 index af730e14..00000000 --- a/backend/src/test/java/develup/application/submission/PairServiceTest.java +++ /dev/null @@ -1,199 +0,0 @@ -package develup.application.submission; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import java.util.List; -import develup.api.exception.DevelupException; -import develup.domain.member.Member; -import develup.domain.member.MemberRepository; -import develup.domain.mission.Mission; -import develup.domain.mission.MissionRepository; -import develup.domain.submission.Pair; -import develup.domain.submission.PairRepository; -import develup.domain.submission.PairStatus; -import develup.domain.submission.Submission; -import develup.domain.submission.SubmissionRepository; -import develup.support.IntegrationTestSupport; -import develup.support.data.MemberTestData; -import develup.support.data.MissionTestData; -import develup.support.data.PairTestData; -import develup.support.data.SubmissionTestData; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -class PairServiceTest extends IntegrationTestSupport { - - @Autowired - private PairService pairService; - - @Autowired - private MissionRepository missionRepository; - - @Autowired - private SubmissionRepository submissionRepository; - - @Autowired - private MemberRepository memberRepository; - - @Autowired - private PairRepository pairRepository; - - @Test - @DisplayName("매칭 가능한 페어가 존재하는지 확인한다.") - void canMatch() { - Mission mission = createMission(); - createSubmission(mission, createMember()); - Submission submission = createSubmission(mission, createMember()); - - boolean result = pairService.canMatch(submission); - - assertThat(result).isTrue(); - } - - @Test - @DisplayName("매칭 가능한 페어가 존재하지 않은지 확인한다.") - void canNotMatch() { - Mission mission = createMission(); - Submission submission = createSubmission(mission, createMember()); - - boolean result = pairService.canMatch(submission); - - assertThat(result).isFalse(); - } - - @Test - @DisplayName("자신을 제외한 매칭 가능한 페어가 존재하지 않은지 확인한다.") - void canNotMatchWithMember() { - Mission mission = createMission(); - Member sameMember = createMember(); - Submission submission = createSubmission(mission, sameMember); - createSubmission(mission, sameMember); - - boolean result = pairService.canMatch(submission); - - assertThat(result).isFalse(); - } - - @Test - @DisplayName("페어를 매칭한다.") - void match() { - Mission mission = createMission(); - Submission mySubmission = createSubmission(mission, createMember()); - Submission otherSubmission = createSubmission(mission, createMember()); - - pairService.match(mySubmission); - - List pairs = pairRepository.findAll(); - assertThat(pairs) - .extracting(Pair::getMain) - .contains(mySubmission, otherSubmission); - } - - @Test - @DisplayName("이미 매칭된 제출로 새로운 매칭을 할 수 없다.") - void alreadyMatched() { - Mission mission = createMission(); - Submission mySubmission = createSubmission(mission, createMember()); - createSubmission(mission, createMember()); - pairService.match(mySubmission); - - assertThatThrownBy(() -> pairService.match(mySubmission)) - .isInstanceOf(DevelupException.class) - .hasMessage("이미 매칭된 제출입니다."); - } - - @Test - @DisplayName("매칭할 제출이 존재하지 않으면 예외를 발생한다.") - void cannotMatch() { - Mission mission = createMission(); - Submission mySubmission = createSubmission(mission, createMember()); - - assertThatThrownBy(() -> pairService.match(mySubmission)) - .isInstanceOf(DevelupException.class) - .hasMessage("매칭할 제출이 존재하지 않습니다."); - } - - @Test - @DisplayName("자신의 제출과 매칭될 수 없다.") - void cannotMatchWithMe() { - Mission mission = createMission(); - Member sameMember = createMember(); - createSubmission(mission, sameMember); - Submission mySubmission = createSubmission(mission, sameMember); - - assertThatThrownBy(() -> pairService.match(mySubmission)) - .isInstanceOf(DevelupException.class) - .hasMessage("매칭할 제출이 존재하지 않습니다."); - } - - @Test - @DisplayName("존재하지 않는 제출은 매칭될 수 없다.") - void notfoundSubmission() { - Submission submission = SubmissionTestData.defaultSubmission() - .withId(-1L) - .build(); - - assertThatThrownBy(() -> pairService.match(submission)) - .isInstanceOf(DevelupException.class) - .hasMessage("존재하지 않는 제출입니다."); - } - - private Mission createMission() { - Mission mission = MissionTestData.defaultMission().build(); - - return missionRepository.save(mission); - } - - private Member createMember() { - Member member = MemberTestData.defaultMember().build(); - - return memberRepository.save(member); - } - - private Submission createSubmission(Mission mission, Member member) { - Submission submission = SubmissionTestData.defaultSubmission() - .withMission(mission) - .withMember(member) - .build(); - - return submissionRepository.save(submission); - } - - @Test - @DisplayName("존재하지 않는 제출은 리뷰를 완료할 수 없다.") - void completeReview() { - Member member = createMember(); - assertThatThrownBy(() -> pairService.completeReview(member.getId(), -1L)) - .isInstanceOf(DevelupException.class) - .hasMessage("존재하지 않는 제출입니다."); - } - - @Test - @DisplayName("자신의 제출이 아닌 경우 리뷰를 완료할 수 없다.") - void completeReviewFailWhenNotOwner() { - Member member = createMember(); - Member other = createMember(); - Mission mission = createMission(); - Submission mainSubmission = createSubmission(mission, member); - Submission otherSubmission = createSubmission(mission, other); - - createPair(mainSubmission, otherSubmission, PairStatus.MATCHED); - createPair(otherSubmission, mainSubmission, PairStatus.MATCHED); - - assertThatThrownBy(() -> pairService.completeReview(other.getId(), mainSubmission.getId())) - .isInstanceOf(DevelupException.class) - .hasMessage("권한이 없는 요청입니다."); - } - - private Pair createPair(Submission main, Submission other, PairStatus pairStatus) { - Pair pair = PairTestData.defaultPair() - .withMain(main) - .withOther(other) - .withStatus(pairStatus) - .build(); - - return pairRepository.save(pair); - } -} diff --git a/backend/src/test/java/develup/application/submission/SubmissionServiceTest.java b/backend/src/test/java/develup/application/submission/SubmissionServiceTest.java deleted file mode 100644 index 77a4129d..00000000 --- a/backend/src/test/java/develup/application/submission/SubmissionServiceTest.java +++ /dev/null @@ -1,120 +0,0 @@ -package develup.application.submission; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import java.util.List; -import develup.api.exception.DevelupException; -import develup.domain.member.Member; -import develup.domain.member.MemberRepository; -import develup.domain.mission.Mission; -import develup.domain.mission.MissionRepository; -import develup.domain.submission.PairStatus; -import develup.domain.submission.SubmissionRepository; -import develup.support.IntegrationTestSupport; -import develup.support.data.MemberTestData; -import develup.support.data.MissionTestData; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.jdbc.Sql; - -class SubmissionServiceTest extends IntegrationTestSupport { - - @Autowired - private SubmissionService submissionService; - - @Autowired - private SubmissionRepository submissionRepository; - - @Autowired - private MissionRepository missionRepository; - - @Autowired - private MemberRepository memberRepository; - - @Test - @DisplayName("미션을 제출한다.") - void createSubmission() { - Member member = createMember(); - Mission mission = createMission(); - CreateSubmissionRequest request = new CreateSubmissionRequest(mission.getId(), "pr url", "코멘트"); - - submissionService.submit(member.getId(), request); - - assertThat(submissionRepository.findAll()).hasSize(1); - } - - @Test - @DisplayName("존재하지 않는 멤버는 제출할 수 없다.") - void notFoundMember() { - Mission mission = createMission(); - CreateSubmissionRequest request = new CreateSubmissionRequest(mission.getId(), "pr url", "코멘트"); - - assertThatThrownBy(() -> submissionService.submit(-1L, request)) - .isInstanceOf(DevelupException.class) - .hasMessage("존재하지 않는 회원입니다."); - } - - @Test - @DisplayName("존재하지 않는 미션을 제출할 수 없다.") - void notFoundMission() { - Member member = createMember(); - CreateSubmissionRequest request = new CreateSubmissionRequest(-1L, "pr url", "코멘트"); - - assertThatThrownBy(() -> submissionService.submit(member.getId(), request)) - .isInstanceOf(DevelupException.class) - .hasMessage("존재하지 않는 미션입니다."); - } - - private Mission createMission() { - Mission mission = MissionTestData.defaultMission().build(); - - return missionRepository.save(mission); - } - - private Member createMember() { - Member member = MemberTestData.defaultMember().build(); - - return memberRepository.save(member); - } - - @Nested - @Sql(value = {"classpath:mymissions.sql"}) - @DisplayName("특정 유저 미션 현황 서비스 테스트") - class MyMissionTest { - - @Test - @DisplayName("참여한 모든 미션을 조회한다.") - void getMyMissions() { - List myMissions = submissionService.getMyMissions(1L); - - assertThat(myMissions).hasSize(3); - } - - @Test - @DisplayName("매칭된 제출이 없는 경우 `매칭 대기` 상태로 설정된다.") - void getMyMissionsWhenNoPair() { - List myMissions = submissionService.getMyMissions(1L); - - assertThat(myMissions.getFirst().status()).isEqualTo("매칭 대기"); - } - - @Test - @DisplayName("진행 중인 미션이 있는 경우 해당 미션 한 개를 반환한다.") - void getMyMission() { - MyMissionResponse response = submissionService.getMyMission(1L); - - assertThat(response.status()).isEqualTo(PairStatus.WAITING.getDescription()); - } - - @Test - @DisplayName("진행 중인 미션이 없는 경우 null을 반환한다.") - void getMyMissionWhenAllFinished() { - MyMissionResponse response = submissionService.getMyMission(3L); - - assertThat(response).isNull(); - } - } -} diff --git a/backend/src/test/java/develup/domain/submission/PairRepositoryTest.java b/backend/src/test/java/develup/domain/submission/PairRepositoryTest.java deleted file mode 100644 index 4a3655b4..00000000 --- a/backend/src/test/java/develup/domain/submission/PairRepositoryTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package develup.domain.submission; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertAll; - -import develup.support.IntegrationTestSupport; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.jdbc.Sql; - -class PairRepositoryTest extends IntegrationTestSupport { - - @Autowired - private PairRepository pairRepository; - - @Autowired - private SubmissionRepository submissionRepository; - - @Test - @Sql(value = {"classpath:mymissions.sql"}) - @DisplayName("특정 Submission의 페어를 찾는다.") - void findMyMissionBySubmission() { - Submission submission = submissionRepository.findById(1L).get(); - - MyMission myMission = pairRepository.findMyMissionBySubmission(submission).get(); - - assertAll( - () -> assertThat(myMission.getId()).isEqualTo(1L), - () -> assertThat(myMission.getStatusDescription()).isEqualTo("완료") - ); - } -} diff --git a/backend/src/test/java/develup/domain/submission/PairTest.java b/backend/src/test/java/develup/domain/submission/PairTest.java deleted file mode 100644 index f716e9bc..00000000 --- a/backend/src/test/java/develup/domain/submission/PairTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package develup.domain.submission; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import java.util.stream.Stream; -import develup.api.exception.DevelupException; -import develup.support.data.PairTestData; -import develup.support.data.SubmissionTestData; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -class PairTest { - - public static Stream reviewCompleteFailWhenAlreadyReviewParameter() { - return Stream.of(Arguments.of(PairStatus.WAITING, PairStatus.ALL_FINISHED, PairStatus.MY_REVIEW_COMPLETED)); - } - - @Test - @DisplayName("같은 제출로 페어를 맺을 수 없다.") - void createWithSameSubmission() { - Submission submission = SubmissionTestData.defaultSubmission() - .withId(1L) - .build(); - - assertThatThrownBy(() -> new Pair(submission, submission, PairStatus.MATCHED)) - .isInstanceOf(DevelupException.class) - .hasMessage("같은 제출끼리 페어가 될 수 없습니다."); - } - - @ParameterizedTest - @MethodSource("reviewCompleteFailWhenAlreadyReviewParameter") - @DisplayName("이미 리뷰 완료를 한 경우 리뷰 완료를 할 수 없다.") - void reviewCompleteFailWhenAlreadyReview(PairStatus pairStatus) { - Pair pair = PairTestData.defaultPair() - .withStatus(pairStatus) - .build(); - - Pair other = PairTestData.otherPair(pair).build(); - - assertThatThrownBy(() -> pair.completeReview(other)) - .isInstanceOf(DevelupException.class) - .hasMessage("이미 리뷰를 완료했습니다."); - } - - @Test - @DisplayName("매칭 상태에서 리뷰 완료를 한 경우 확인.") - void completeReviewSuccessWhenMatched() { - Pair pair = PairTestData.defaultPair() - .withStatus(PairStatus.MATCHED) - .build(); - - Pair other = PairTestData.otherPair(pair) - .build(); - - pair.completeReview(other); - Assertions.assertAll( - () -> assertThat(pair.getStatus()).isEqualTo(PairStatus.MY_REVIEW_COMPLETED), - () -> assertThat(other.getStatus()).isEqualTo(PairStatus.PARTNER_REVIEW_COMPLETED) - ); - } - - @Test - @DisplayName("상대 리뷰 완료 상태에서 리뷰 완료를 한 경우 확인.") - void reviewCompleteSuccessWhenPartnerCompleteReview() { - Pair pair = PairTestData.defaultPair() - .withStatus(PairStatus.PARTNER_REVIEW_COMPLETED) - .build(); - - Pair other = PairTestData.otherPair(pair) - .build(); - - pair.completeReview(other); - Assertions.assertAll( - () -> assertThat(pair.getStatus()).isEqualTo(PairStatus.ALL_FINISHED), - () -> assertThat(other.getStatus()).isEqualTo(PairStatus.ALL_FINISHED) - ); - } -} diff --git a/backend/src/test/java/develup/domain/submission/SubmissionRepositoryTest.java b/backend/src/test/java/develup/domain/submission/SubmissionRepositoryTest.java deleted file mode 100644 index d4664f4b..00000000 --- a/backend/src/test/java/develup/domain/submission/SubmissionRepositoryTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package develup.domain.submission; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.List; -import java.util.Optional; -import develup.domain.member.Member; -import develup.domain.member.MemberRepository; -import develup.domain.mission.Mission; -import develup.domain.mission.MissionRepository; -import develup.support.IntegrationTestSupport; -import develup.support.data.MemberTestData; -import develup.support.data.MissionTestData; -import develup.support.data.SubmissionTestData; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -class SubmissionRepositoryTest extends IntegrationTestSupport { - - @Autowired - private SubmissionRepository submissionRepository; - - @Autowired - private MissionRepository missionRepository; - - @Autowired - private MemberRepository memberRepository; - - @Test - @DisplayName("아직 매칭되지 않은 제출을 불러온다.") - void findNonMatchedSubmission() { - Mission mission = createMission(); - Submission submission1 = createSubmission(mission, createMember()); - Submission submission2 = createSubmission(mission, createMember()); - - List result = submissionRepository.findNonMatchedSubmissions(mission); - - assertThat(result) - .extracting(Submission::getId) - .contains(submission1.getId(), submission2.getId()); - } - - @Test - @DisplayName("멤버 식별자와 미션 식별자로 제일 최근 제출을 불러온다.") - void findFirstByMember_IdOrderByIdDesc() { - Member member = createMember(); - Mission mission = createMission(); - createSubmission(mission, member); - Submission lateSubmission = createSubmission(mission, member); - - Optional result = submissionRepository - .findFirstByMember_IdAndMission_IdOrderByIdDesc(member.getId(), mission.getId()); - - assertThat(result).isPresent(); - assertThat(result.get().getId()).isEqualTo(lateSubmission.getId()); - } - - private Mission createMission() { - Mission mission = MissionTestData.defaultMission().build(); - - return missionRepository.save(mission); - } - - private Submission createSubmission(Mission mission, Member member) { - Submission submission = SubmissionTestData.defaultSubmission() - .withMember(member) - .withMission(mission) - .build(); - - return submissionRepository.save(submission); - } - - private Member createMember() { - Member member = MemberTestData.defaultMember().build(); - - return memberRepository.save(member); - } -} diff --git a/backend/src/test/java/develup/domain/submission/SubmissionTest.java b/backend/src/test/java/develup/domain/submission/SubmissionTest.java deleted file mode 100644 index 02d64db7..00000000 --- a/backend/src/test/java/develup/domain/submission/SubmissionTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package develup.domain.submission; - -import static org.assertj.core.api.Assertions.assertThat; - -import develup.domain.member.Member; -import develup.domain.mission.Mission; -import develup.support.data.MemberTestData; -import develup.support.data.MissionTestData; -import develup.support.data.SubmissionTestData; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -class SubmissionTest { - - @Test - @DisplayName("같은 사용자의 제출이 아닌지 확인할 수 있다.") - void isNotSameOwner() { - Mission mission = MissionTestData.defaultMission().build(); - Member member1 = createMember(1L); - Member member2 = createMember(2L); - Submission submission1 = createSubmission(member1, mission); - Submission submission2 = createSubmission(member2, mission); - - boolean result = submission1.isNotSameOwner(submission2); - - assertThat(result).isTrue(); - } - - @Test - @DisplayName("같은 사용자의 제출인지 확인할 수 있다.") - void isSameOwner() { - Mission mission = MissionTestData.defaultMission().build(); - Member member = createMember(1L); - Submission submission2 = createSubmission(member, mission); - Submission submission1 = createSubmission(member, mission); - - boolean result = submission1.isNotSameOwner(submission2); - - assertThat(result).isFalse(); - } - - private Member createMember(Long id) { - return MemberTestData.defaultMember() - .withId(id) - .build(); - } - - private Submission createSubmission(Member member, Mission mission) { - return SubmissionTestData.defaultSubmission() - .withMember(member) - .withMission(mission) - .build(); - } -} diff --git a/backend/src/test/java/develup/support/data/MissionTestData.java b/backend/src/test/java/develup/support/data/MissionTestData.java deleted file mode 100644 index b7e1ce7b..00000000 --- a/backend/src/test/java/develup/support/data/MissionTestData.java +++ /dev/null @@ -1,67 +0,0 @@ -package develup.support.data; - -import develup.domain.mission.Language; -import develup.domain.mission.Mission; - -public class MissionTestData { - - public static MissionBuilder defaultMission() { - return new MissionBuilder() - .withTitle("테스트 미션") - .withLanguage(Language.JAVA) - .withDescription("테스트 미션 설명") - .withThumbnail("image.com/1.jpg") - .withUrl("github.com/develup/test"); - } - - public static class MissionBuilder { - - private Long id; - private String title; - private Language language; - private String description; - private String thumbnail; - private String url; - - public MissionBuilder withId(Long id) { - this.id = id; - return this; - } - - public MissionBuilder withTitle(String title) { - this.title = title; - return this; - } - - public MissionBuilder withLanguage(Language language) { - this.language = language; - return this; - } - - public MissionBuilder withDescription(String description) { - this.description = description; - return this; - } - - public MissionBuilder withThumbnail(String thumbnail) { - this.thumbnail = thumbnail; - return this; - } - - public MissionBuilder withUrl(String url) { - this.url = url; - return this; - } - - public Mission build() { - return new Mission( - id, - title, - language, - description, - thumbnail, - url - ); - } - } -} diff --git a/backend/src/test/java/develup/support/data/PairTestData.java b/backend/src/test/java/develup/support/data/PairTestData.java deleted file mode 100644 index 1f2299eb..00000000 --- a/backend/src/test/java/develup/support/data/PairTestData.java +++ /dev/null @@ -1,57 +0,0 @@ -package develup.support.data; - -import develup.domain.submission.Pair; -import develup.domain.submission.PairStatus; -import develup.domain.submission.Submission; - -public class PairTestData { - - public static PairBuilder defaultPair() { - return new PairBuilder() - .withMain(SubmissionTestData.defaultSubmission().withId(Long.MAX_VALUE - 1).build()) - .withOther(SubmissionTestData.defaultSubmission().withId(Long.MAX_VALUE).build()) - .withStatus(PairStatus.MATCHED); - } - - public static PairBuilder otherPair(Pair main) { - return new PairBuilder() - .withMain(main.getOther()) - .withOther(main.getMain()) - .withStatus(main.getStatus().toOtherStatus()); - } - - public static final class PairBuilder { - - private Long id; - private Submission main; - private Submission other; - private PairStatus status; - - private PairBuilder() { - } - - public PairBuilder withId(Long id) { - this.id = id; - return this; - } - - public PairBuilder withMain(Submission main) { - this.main = main; - return this; - } - - public PairBuilder withOther(Submission other) { - this.other = other; - return this; - } - - public PairBuilder withStatus(PairStatus status) { - this.status = status; - return this; - } - - public Pair build() { - return new Pair(id, main, other, status); - } - } -} diff --git a/backend/src/test/java/develup/support/data/SubmissionTestData.java b/backend/src/test/java/develup/support/data/SubmissionTestData.java deleted file mode 100644 index 166c67a0..00000000 --- a/backend/src/test/java/develup/support/data/SubmissionTestData.java +++ /dev/null @@ -1,60 +0,0 @@ -package develup.support.data; - -import develup.domain.member.Member; -import develup.domain.mission.Mission; -import develup.domain.submission.Submission; - -public class SubmissionTestData { - - public static SubmissionBuilder defaultSubmission() { - return new SubmissionBuilder() - .withUrl("github.com/develup/pull/1") - .withComment("리뷰 감사합니다.") - .withMember(MemberTestData.defaultMember().build()) - .withMission(MissionTestData.defaultMission().build()); - } - - public static class SubmissionBuilder { - - private Long id; - private String url; - private String comment; - private Member member; - private Mission mission; - - public SubmissionBuilder withId(Long id) { - this.id = id; - return this; - } - - public SubmissionBuilder withUrl(String url) { - this.url = url; - return this; - } - - public SubmissionBuilder withComment(String comment) { - this.comment = comment; - return this; - } - - public SubmissionBuilder withMember(Member member) { - this.member = member; - return this; - } - - public SubmissionBuilder withMission(Mission mission) { - this.mission = mission; - return this; - } - - public Submission build() { - return new Submission( - id, - url, - comment, - member, - mission - ); - } - } -} diff --git a/backend/src/test/resources/mymissions.sql b/backend/src/test/resources/mymissions.sql deleted file mode 100644 index a6a30132..00000000 --- a/backend/src/test/resources/mymissions.sql +++ /dev/null @@ -1,50 +0,0 @@ -INSERT INTO mission (title, language, description, thumbnail, url) -VALUES ('루터회관 흡연 단속', 'JAVA', 'https://raw.githubusercontent.com/develup-mission/java-smoking/main/README.md', - 'https://raw.githubusercontent.com/develup-mission/docs/main/image/java-smoking.png', - 'https://github.com/develup-mission/java-smoking'); - -INSERT INTO mission (title, language, description, thumbnail, url) -VALUES ('단어 퍼즐 게임', 'JAVA', 'https://raw.githubusercontent.com/develup-mission/java-word-puzzle/main/README.md', - 'https://raw.githubusercontent.com/develup-mission/docs/main/image/java-guessing-number.png', - 'https://github.com/develup-mission/java-word-puzzle'); - -INSERT INTO mission (title, language, description, thumbnail, url) -VALUES ('숫자 추리 게임', 'JAVA', 'https://raw.githubusercontent.com/develup-mission/java-guessing-number/main/README.md', - 'https://raw.githubusercontent.com/develup-mission/docs/main/image/java-word-puzzle.png', - 'https://github.com/develup-mission/java-guessing-number'); - -INSERT INTO member (email, provider, social_id, name, image_url) -VALUES ('test1@gmail.com', 'GITHUB', '1234', '구름', 'www.naver.com'); - -INSERT INTO member (email, provider, social_id, name, image_url) -VALUES ('test1@gmail.com', 'GITHUB', '1234', '리브', 'www.naver.com'); - -INSERT INTO member (email, provider, social_id, name, image_url) -VALUES ('test1@gmail.com', 'GITHUB', '1234', '아톰', 'www.naver.com'); - -INSERT INTO submission (member_id, mission_id, url, comment) -VALUES (1, 1, 'https://github.com/develup-mission/java-smoking/pull/1', '코멘트 1'); - -INSERT INTO submission (member_id, mission_id, url, comment) -VALUES (2, 1, 'https://github.com/develup-mission/java-smoking/pull/2', '코멘트 2'); - -INSERT INTO submission (member_id, mission_id, url, comment) -VALUES (1, 2, 'https://github.com/develup-mission/java-word-puzzle/pull/1', '코멘트 3'); - -INSERT INTO submission (member_id, mission_id, url, comment) -VALUES (2, 2, 'https://github.com/develup-mission/java-word-puzzle/pull/2', '코멘트 4'); - -INSERT INTO submission (member_id, mission_id, url, comment) -VALUES (1, 3, 'https://github.com/develup-mission/java-guessing-number/pull/1', '코멘트 5'); - -INSERT INTO pair (main_submission, pair_submission, status) -VALUES (1, 2, 'ALL_FINISHED'); - -INSERT INTO pair (main_submission, pair_submission, status) -VALUES (2, 1, 'ALL_FINISHED'); - -INSERT INTO pair (main_submission, pair_submission, status) -VALUES (3, 4, 'MY_REVIEW_COMPLETED'); - -INSERT INTO pair (main_submission, pair_submission, status) -VALUES (4, 3, 'PARTNER_REVIEW_COMPLETED');