From 2ec178f8c26dd43c051ef5dd4f1452d700b706b7 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 14 Feb 2024 15:19:20 +0900 Subject: [PATCH 01/46] =?UTF-8?q?feat=20:=20=EC=BB=A4=EC=8A=A4=ED=85=80=20?= =?UTF-8?q?Validator=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MatchingController.java | 16 +++-------- .../request/MatchingApplicationRequest.java | 9 ++++++ .../util/validator/LanguageCheck.java | 23 +++++++++++++++ .../util/validator/LanguageValidator.java | 28 +++++++++++++++++++ 4 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingApplicationRequest.java create mode 100644 src/main/java/com/aliens/backend/mathcing/util/validator/LanguageCheck.java create mode 100644 src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java diff --git a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java index ce50db2a..cacdb6ef 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java @@ -28,36 +28,28 @@ public MatchingController(final MatchingApplicationService matchingApplicationSe @PostMapping("/applications") public SuccessResponse applyMatch(final @Login LoginMember loginMember, final @RequestBody MatchingApplicationInput input) { - - return SuccessResponse.of( - MatchingSuccess.APPLY_MATCHING_SUCCESS, + return SuccessResponse.of(MatchingSuccess.APPLY_MATCHING_SUCCESS, matchingApplicationService.saveParticipant(input.toRequest(loginMember.memberId())) ); } @GetMapping("/applications") public SuccessResponse getMatchingApplication(final @Login LoginMember loginMember) { - - return SuccessResponse.of( - MatchingSuccess.GET_MATCHING_APPLICATION_STATUS_SUCCESS, + return SuccessResponse.of(MatchingSuccess.GET_MATCHING_APPLICATION_STATUS_SUCCESS, matchingApplicationService.findMatchingApplication(loginMember.memberId()) ); } @DeleteMapping("/applications") public SuccessResponse cancelMatchingApplication(final @Login LoginMember loginMember) { - - return SuccessResponse.of( - MatchingSuccess.CANCEL_MATCHING_APPLICATION_SUCCESS, + return SuccessResponse.of(MatchingSuccess.CANCEL_MATCHING_APPLICATION_SUCCESS, matchingApplicationService.deleteMatchingApplication(loginMember.memberId()) ); } @GetMapping("/partners") public SuccessResponse> getMatchingPartners(final @Login LoginMember loginMember) { - - return SuccessResponse.of( - MatchingSuccess.GET_MATCHING_PARTNERS_SUCCESS, + return SuccessResponse.of(MatchingSuccess.GET_MATCHING_PARTNERS_SUCCESS, matchingService.findMatchingResult(loginMember.memberId()) ); } diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingApplicationRequest.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingApplicationRequest.java new file mode 100644 index 00000000..14e9439d --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingApplicationRequest.java @@ -0,0 +1,9 @@ +package com.aliens.backend.mathcing.controller.dto.request; + +import com.aliens.backend.mathcing.service.model.Language; + +public record MatchingApplicationRequest( + Language firstPreferLanguage, + Language secondPreferLanguage +) { +} diff --git a/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageCheck.java b/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageCheck.java new file mode 100644 index 00000000..93f6a3dd --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageCheck.java @@ -0,0 +1,23 @@ +package com.aliens.backend.mathcing.util.validator; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; + +@Target({ PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = {LanguageValidator.class}) +@Documented +public @interface LanguageCheck { + String message() default "Invalid Language Input"; + + Class[] groups() default { }; + + Class[] payload() default { }; +} \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java b/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java new file mode 100644 index 00000000..49885f39 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java @@ -0,0 +1,28 @@ +package com.aliens.backend.mathcing.util.validator; + + +import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.global.response.error.MatchingError; +import com.aliens.backend.mathcing.controller.dto.request.MatchingApplicationRequest; +import com.aliens.backend.mathcing.service.model.Language; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + + +public class LanguageValidator implements ConstraintValidator { + @Override + public boolean isValid(final MatchingApplicationRequest value, final ConstraintValidatorContext context) { + Language firstPreferLanguage = value.firstPreferLanguage(); + Language secondPreferLanguage = value.secondPreferLanguage(); + + if (!firstPreferLanguage.equals(secondPreferLanguage)) { + return true; + } + throw new RestApiException(MatchingError.INVALID_LANGUAGE_INPUT); + } + + @Override + public void initialize(final LanguageCheck constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + } +} \ No newline at end of file From 88f04b618b87d2c44829c699555e62701d350a23 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 14 Feb 2024 15:28:11 +0900 Subject: [PATCH 02/46] =?UTF-8?q?refactor=20:=20getter=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B2=B4=EC=9D=B4=EB=8B=9D=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/MatchingRequest.java | 3 -- .../dto/response/MatchingResponse.java | 6 ++-- .../mathcing/domain/MatchingApplication.java | 34 ++++++++++++++----- .../mathcing/domain/MatchingResult.java | 12 +++++-- .../mathcing/service/model/Participant.java | 2 +- .../MatchingApplicationServiceTest.java | 2 +- 6 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java index dbd8943c..be73a64c 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java @@ -10,8 +10,5 @@ public record MatchingApplicationRequest( Language firstPreferLanguage, Language secondPreferLanguage ) { - public MatchingApplication toEntity(MatchingRound matchingRound) { - return MatchingApplication.of(matchingRound, memberId, firstPreferLanguage, secondPreferLanguage); - } } } diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java index c2415b8a..307edc6f 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java @@ -16,8 +16,8 @@ public record MatchingApplicationResponse( Language secondPreferLanguage) { public static MatchingApplicationResponse of(MatchingApplication matchingApplication) { return new MatchingApplicationResponse( - matchingApplication.getId().getMatchingRound().getRound(), - matchingApplication.getId().getMemberId(), + matchingApplication.getMatchingRound().getRound(), + matchingApplication.getMemberId(), matchingApplication.getFirstPreferLanguage(), matchingApplication.getSecondPreferLanguage()); } @@ -28,7 +28,7 @@ public record MatchingResultResponse( Relationship relationship ) { public static MatchingResultResponse of(MatchingResult matchingResult) { - return new MatchingResultResponse(matchingResult.getId().getMatchedMemberId(), matchingResult.getRelationship()); + return new MatchingResultResponse(matchingResult.getMatchedMemberId(), matchingResult.getRelationship()); } } } diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java index 730921da..42d839f9 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java @@ -1,5 +1,7 @@ package com.aliens.backend.mathcing.domain; +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.mathcing.controller.dto.request.MatchingApplicationRequest; import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; import com.aliens.backend.mathcing.service.model.Language; import com.aliens.backend.mathcing.service.model.Participant; @@ -8,7 +10,6 @@ import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -34,10 +35,6 @@ private MatchingApplication(final MatchingApplicationId id, this.secondPreferLanguage = secondPreferLanguage; } - public MatchingApplicationId getId() { - return id; - } - public Language getFirstPreferLanguage() { return firstPreferLanguage; } @@ -48,10 +45,17 @@ public Language getSecondPreferLanguage() { public static MatchingApplication of(final MatchingRound matchingRound, final Long memberId, - final Language firstPreferLanguage, final Language secondPreferLanguage) { - return new MatchingApplication( - MatchingApplicationId.of(matchingRound, memberId), - firstPreferLanguage, secondPreferLanguage); + final Language firstPreferLanguage, + final Language secondPreferLanguage) { + return new MatchingApplication(MatchingApplicationId.of(matchingRound, memberId), firstPreferLanguage, secondPreferLanguage); + } + + public static MatchingApplication from(final MatchingRound matchingRound, + final LoginMember loginMember, + final MatchingApplicationRequest matchingApplicationRequest) { + return MatchingApplication.of(matchingRound, loginMember.memberId(), + matchingApplicationRequest.firstPreferLanguage(), + matchingApplicationRequest.secondPreferLanguage()); } public static List toParticipantList(final List matchingApplications) { @@ -60,6 +64,18 @@ public static List toParticipantList(final List() diff --git a/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java index 3dc96c3b..5fee4a23 100644 --- a/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java @@ -57,7 +57,7 @@ void applyMatchTest() { MatchingApplication result = matchingApplicationRepository .findById(MatchingApplicationId.of(getCurrentRound(), matchingApplicationRequest.memberId())) .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); - assertThat(result.getId().getMemberId()).isEqualTo(matchingApplicationRequest.memberId()); + assertThat(result.getMemberId()).isEqualTo(matchingApplicationRequest.memberId()); } @Test From 9abf488a80e614b076ca187bc27a1e30d6ed8c4b Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 14 Feb 2024 15:55:53 +0900 Subject: [PATCH 03/46] =?UTF-8?q?refactor=20:=20=EC=9D=B4=EB=84=88=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=A0=9C=EA=B1=B0=20=EB=B0=8F=20?= =?UTF-8?q?DTO=EC=97=90=EC=84=9C=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=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 --- .../mathcing/business/MatchingBusiness.java | 8 +-- .../{service => business}/model/Language.java | 2 +- .../model/MatchingMode.java | 2 +- .../model/Participant.java | 2 +- .../{service => business}/model/Partner.java | 2 +- .../model/Relationship.java | 2 +- .../controller/MatchingController.java | 25 +++++----- .../controller/dto/input/MatchingInput.java | 28 ----------- .../request/MatchingApplicationRequest.java | 2 +- .../dto/request/MatchingRequest.java | 14 ------ .../response/MatchingApplicationResponse.java | 18 +++++++ .../dto/response/MatchingResponse.java | 34 ------------- .../dto/response/MatchingResultResponse.java | 13 +++++ .../mathcing/domain/MatchingApplication.java | 4 +- .../mathcing/domain/MatchingResult.java | 2 +- .../service/MatchingApplicationService.java | 31 ++++++------ .../mathcing/service/MatchingService.java | 14 +++--- .../util/validator/LanguageValidator.java | 2 +- .../aliens/backend/global/DummyGenerator.java | 11 +++-- .../business/MatchingBusinessTest.java | 2 +- .../MatchingApplicationServiceTest.java | 49 ++++++++++++------- 21 files changed, 118 insertions(+), 149 deletions(-) rename src/main/java/com/aliens/backend/mathcing/{service => business}/model/Language.java (92%) rename src/main/java/com/aliens/backend/mathcing/{service => business}/model/MatchingMode.java (69%) rename src/main/java/com/aliens/backend/mathcing/{service => business}/model/Participant.java (96%) rename src/main/java/com/aliens/backend/mathcing/{service => business}/model/Partner.java (80%) rename src/main/java/com/aliens/backend/mathcing/{service => business}/model/Relationship.java (53%) delete mode 100644 src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java delete mode 100644 src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java create mode 100644 src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingApplicationResponse.java delete mode 100644 src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java create mode 100644 src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResultResponse.java diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index e000f0e4..c68b7867 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -2,10 +2,10 @@ import com.aliens.backend.global.property.MatchingRuleProperties; import com.aliens.backend.mathcing.domain.MatchingApplication; -import com.aliens.backend.mathcing.service.model.Language; -import com.aliens.backend.mathcing.service.model.Participant; -import com.aliens.backend.mathcing.service.model.MatchingMode; -import com.aliens.backend.mathcing.service.model.Relationship; +import com.aliens.backend.mathcing.business.model.Language; +import com.aliens.backend.mathcing.business.model.Participant; +import com.aliens.backend.mathcing.business.model.MatchingMode; +import com.aliens.backend.mathcing.business.model.Relationship; import org.springframework.stereotype.Component; import java.util.*; diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Language.java b/src/main/java/com/aliens/backend/mathcing/business/model/Language.java similarity index 92% rename from src/main/java/com/aliens/backend/mathcing/service/model/Language.java rename to src/main/java/com/aliens/backend/mathcing/business/model/Language.java index 2c217c7a..da6b08f4 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/model/Language.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/Language.java @@ -1,4 +1,4 @@ -package com.aliens.backend.mathcing.service.model; +package com.aliens.backend.mathcing.business.model; import java.util.*; diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/MatchingMode.java b/src/main/java/com/aliens/backend/mathcing/business/model/MatchingMode.java similarity index 69% rename from src/main/java/com/aliens/backend/mathcing/service/model/MatchingMode.java rename to src/main/java/com/aliens/backend/mathcing/business/model/MatchingMode.java index 82909c58..6948809b 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/model/MatchingMode.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/MatchingMode.java @@ -1,4 +1,4 @@ -package com.aliens.backend.mathcing.service.model; +package com.aliens.backend.mathcing.business.model; public enum MatchingMode { FIRST_PREFER_LANGUAGE, diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java b/src/main/java/com/aliens/backend/mathcing/business/model/Participant.java similarity index 96% rename from src/main/java/com/aliens/backend/mathcing/service/model/Participant.java rename to src/main/java/com/aliens/backend/mathcing/business/model/Participant.java index 66365aa2..9eb5be19 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/model/Participant.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/Participant.java @@ -1,4 +1,4 @@ -package com.aliens.backend.mathcing.service.model; +package com.aliens.backend.mathcing.business.model; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Partner.java b/src/main/java/com/aliens/backend/mathcing/business/model/Partner.java similarity index 80% rename from src/main/java/com/aliens/backend/mathcing/service/model/Partner.java rename to src/main/java/com/aliens/backend/mathcing/business/model/Partner.java index 288f1f0c..e1acc020 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/model/Partner.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/Partner.java @@ -1,4 +1,4 @@ -package com.aliens.backend.mathcing.service.model; +package com.aliens.backend.mathcing.business.model; public record Partner( Relationship relationship, diff --git a/src/main/java/com/aliens/backend/mathcing/service/model/Relationship.java b/src/main/java/com/aliens/backend/mathcing/business/model/Relationship.java similarity index 53% rename from src/main/java/com/aliens/backend/mathcing/service/model/Relationship.java rename to src/main/java/com/aliens/backend/mathcing/business/model/Relationship.java index 04b97fbd..cc54a174 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/model/Relationship.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/Relationship.java @@ -1,4 +1,4 @@ -package com.aliens.backend.mathcing.service.model; +package com.aliens.backend.mathcing.business.model; public enum Relationship { NORMAL, diff --git a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java index cacdb6ef..9d71333f 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java @@ -4,15 +4,16 @@ import com.aliens.backend.global.config.resolver.Login; import com.aliens.backend.global.response.success.MatchingSuccess; import com.aliens.backend.global.response.SuccessResponse; -import com.aliens.backend.mathcing.controller.dto.response.MatchingResponse; +import com.aliens.backend.mathcing.controller.dto.request.MatchingApplicationRequest; +import com.aliens.backend.mathcing.controller.dto.response.MatchingApplicationResponse; +import com.aliens.backend.mathcing.controller.dto.response.MatchingResultResponse; import com.aliens.backend.mathcing.service.MatchingApplicationService; import com.aliens.backend.mathcing.service.MatchingService; +import com.aliens.backend.mathcing.util.validator.LanguageCheck; import org.springframework.web.bind.annotation.*; import java.util.List; -import static com.aliens.backend.mathcing.controller.dto.input.MatchingInput.*; - @RestController @RequestMapping("/matchings") public class MatchingController { @@ -27,30 +28,26 @@ public MatchingController(final MatchingApplicationService matchingApplicationSe @PostMapping("/applications") public SuccessResponse applyMatch(final @Login LoginMember loginMember, - final @RequestBody MatchingApplicationInput input) { + final @RequestBody @LanguageCheck MatchingApplicationRequest matchingApplicationRequest) { return SuccessResponse.of(MatchingSuccess.APPLY_MATCHING_SUCCESS, - matchingApplicationService.saveParticipant(input.toRequest(loginMember.memberId())) - ); + matchingApplicationService.saveParticipant(loginMember, matchingApplicationRequest)); } @GetMapping("/applications") - public SuccessResponse getMatchingApplication(final @Login LoginMember loginMember) { + public SuccessResponse getMatchingApplication(final @Login LoginMember loginMember) { return SuccessResponse.of(MatchingSuccess.GET_MATCHING_APPLICATION_STATUS_SUCCESS, - matchingApplicationService.findMatchingApplication(loginMember.memberId()) - ); + matchingApplicationService.findMatchingApplication(loginMember)); } @DeleteMapping("/applications") public SuccessResponse cancelMatchingApplication(final @Login LoginMember loginMember) { return SuccessResponse.of(MatchingSuccess.CANCEL_MATCHING_APPLICATION_SUCCESS, - matchingApplicationService.deleteMatchingApplication(loginMember.memberId()) - ); + matchingApplicationService.deleteMatchingApplication(loginMember)); } @GetMapping("/partners") - public SuccessResponse> getMatchingPartners(final @Login LoginMember loginMember) { + public SuccessResponse> getMatchingPartners(final @Login LoginMember loginMember) { return SuccessResponse.of(MatchingSuccess.GET_MATCHING_PARTNERS_SUCCESS, - matchingService.findMatchingResult(loginMember.memberId()) - ); + matchingService.findMatchingResult(loginMember)); } } diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java deleted file mode 100644 index cc1365e7..00000000 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/input/MatchingInput.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.aliens.backend.mathcing.controller.dto.input; - -import com.aliens.backend.global.response.error.MatchingError; -import com.aliens.backend.global.exception.RestApiException; -import com.aliens.backend.mathcing.service.model.Language; - -import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; - -public class MatchingInput { - public record MatchingApplicationInput( - Language firstPreferLanguage, - Language secondPreferLanguage) { - public MatchingApplicationRequest toRequest(final Long memberId){ - validateInput(); - return new MatchingApplicationRequest(memberId, firstPreferLanguage, secondPreferLanguage); - } - - public static MatchingApplicationInput of(Language firstPreferLanguage, Language secondPreferLanguage) { - return new MatchingApplicationInput(firstPreferLanguage, secondPreferLanguage); - } - - private void validateInput() { - if (firstPreferLanguage.equals(secondPreferLanguage)) { - throw new RestApiException(MatchingError.INVALID_LANGUAGE_INPUT); - } - } - } -} diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingApplicationRequest.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingApplicationRequest.java index 14e9439d..5d2d6907 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingApplicationRequest.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingApplicationRequest.java @@ -1,6 +1,6 @@ package com.aliens.backend.mathcing.controller.dto.request; -import com.aliens.backend.mathcing.service.model.Language; +import com.aliens.backend.mathcing.business.model.Language; public record MatchingApplicationRequest( Language firstPreferLanguage, diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java deleted file mode 100644 index be73a64c..00000000 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingRequest.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.aliens.backend.mathcing.controller.dto.request; - -import com.aliens.backend.mathcing.domain.MatchingApplication; -import com.aliens.backend.mathcing.domain.MatchingRound; -import com.aliens.backend.mathcing.service.model.Language; - -public class MatchingRequest { - public record MatchingApplicationRequest( - Long memberId, - Language firstPreferLanguage, - Language secondPreferLanguage - ) { - } -} diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingApplicationResponse.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingApplicationResponse.java new file mode 100644 index 00000000..129a6936 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingApplicationResponse.java @@ -0,0 +1,18 @@ +package com.aliens.backend.mathcing.controller.dto.response; + +import com.aliens.backend.mathcing.domain.MatchingApplication; +import com.aliens.backend.mathcing.business.model.Language; + +public record MatchingApplicationResponse( + Long matchingRound, + Long memberId, + Language firstPreferLanguage, + Language secondPreferLanguage) { + public static MatchingApplicationResponse of(MatchingApplication matchingApplication) { + return new MatchingApplicationResponse( + matchingApplication.getMatchingRound().getRound(), + matchingApplication.getMemberId(), + matchingApplication.getFirstPreferLanguage(), + matchingApplication.getSecondPreferLanguage()); + } +} \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java deleted file mode 100644 index 307edc6f..00000000 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResponse.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.aliens.backend.mathcing.controller.dto.response; - -import com.aliens.backend.mathcing.domain.MatchingApplication; -import com.aliens.backend.mathcing.domain.MatchingResult; -import com.aliens.backend.mathcing.service.model.Language; -import com.aliens.backend.mathcing.service.model.Partner; -import com.aliens.backend.mathcing.service.model.Relationship; - -import java.util.List; - -public class MatchingResponse { - public record MatchingApplicationResponse( - Long matchingRound, - Long memberId, - Language firstPreferLanguage, - Language secondPreferLanguage) { - public static MatchingApplicationResponse of(MatchingApplication matchingApplication) { - return new MatchingApplicationResponse( - matchingApplication.getMatchingRound().getRound(), - matchingApplication.getMemberId(), - matchingApplication.getFirstPreferLanguage(), - matchingApplication.getSecondPreferLanguage()); - } - } - - public record MatchingResultResponse( - Long matchedMemberId, - Relationship relationship - ) { - public static MatchingResultResponse of(MatchingResult matchingResult) { - return new MatchingResultResponse(matchingResult.getMatchedMemberId(), matchingResult.getRelationship()); - } - } -} diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResultResponse.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResultResponse.java new file mode 100644 index 00000000..625f2ef4 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingResultResponse.java @@ -0,0 +1,13 @@ +package com.aliens.backend.mathcing.controller.dto.response; + +import com.aliens.backend.mathcing.domain.MatchingResult; +import com.aliens.backend.mathcing.business.model.Relationship; + +public record MatchingResultResponse( + Long matchedMemberId, + Relationship relationship +) { + public static MatchingResultResponse from(MatchingResult matchingResult) { + return new MatchingResultResponse(matchingResult.getMatchedMemberId(), matchingResult.getRelationship()); + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java index 42d839f9..cde8f2e0 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java @@ -3,8 +3,8 @@ import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.mathcing.controller.dto.request.MatchingApplicationRequest; import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; -import com.aliens.backend.mathcing.service.model.Language; -import com.aliens.backend.mathcing.service.model.Participant; +import com.aliens.backend.mathcing.business.model.Language; +import com.aliens.backend.mathcing.business.model.Participant; import jakarta.persistence.EmbeddedId; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java index 6c19e034..ff73603a 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java @@ -1,7 +1,7 @@ package com.aliens.backend.mathcing.domain; import com.aliens.backend.mathcing.domain.id.MatchingResultId; -import com.aliens.backend.mathcing.service.model.Relationship; +import com.aliens.backend.mathcing.business.model.Relationship; import jakarta.persistence.*; @Entity diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java index 8decf16f..7d9f13aa 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java @@ -1,8 +1,11 @@ package com.aliens.backend.mathcing.service; +import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.response.success.MatchingSuccess; +import com.aliens.backend.mathcing.controller.dto.request.MatchingApplicationRequest; +import com.aliens.backend.mathcing.controller.dto.response.MatchingApplicationResponse; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; @@ -14,9 +17,6 @@ import java.time.Clock; import java.time.LocalDateTime; -import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; -import static com.aliens.backend.mathcing.controller.dto.response.MatchingResponse.*; - @Service public class MatchingApplicationService { private final MatchingApplicationRepository matchingApplicationRepository; @@ -32,41 +32,44 @@ public MatchingApplicationService(final MatchingApplicationRepository matchingAp } @Transactional - public String saveParticipant(final MatchingApplicationRequest matchingApplicationRequest) { + public String saveParticipant(final LoginMember loginMember, + final MatchingApplicationRequest matchingApplicationRequest) { MatchingRound currentRound = getCurrentRound(); checkReceptionTime(currentRound); - matchingApplicationRepository.save(matchingApplicationRequest.toEntity(currentRound)); + MatchingApplication matchingApplication = MatchingApplication.from(currentRound, loginMember, matchingApplicationRequest); + matchingApplicationRepository.save(matchingApplication); return MatchingSuccess.APPLY_MATCHING_SUCCESS.getMessage(); } @Transactional(readOnly = true) - public MatchingApplicationResponse findMatchingApplication(final Long memberId) { + public MatchingApplicationResponse findMatchingApplication(final LoginMember loginMember) { MatchingRound currentRound = getCurrentRound(); MatchingApplication matchingApplication = - matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, memberId)) + matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, loginMember.memberId())) .orElseThrow(()->new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); return MatchingApplicationResponse.of(matchingApplication); } - private MatchingRound getCurrentRound() { - return matchingRoundRepository.findCurrentRound() - .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); - } - @Transactional - public String deleteMatchingApplication(final Long memberId) { + public String deleteMatchingApplication(final LoginMember loginMember) { MatchingRound currentRound = getCurrentRound(); checkReceptionTime(currentRound); MatchingApplication matchingApplication = - matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, memberId)) + matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, loginMember.memberId())) .orElseThrow(()->new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); matchingApplicationRepository.delete(matchingApplication); return MatchingSuccess.CANCEL_MATCHING_APPLICATION_SUCCESS.getMessage(); } + private MatchingRound getCurrentRound() { + return matchingRoundRepository.findCurrentRound() + .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + } + private void checkReceptionTime(MatchingRound matchingRound) { if (!matchingRound.isReceptionTime(LocalDateTime.now(clock))) { throw new RestApiException(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME); } } + } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java index e6e4c41c..6afaf9b9 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java @@ -1,15 +1,17 @@ package com.aliens.backend.mathcing.service; +import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.mathcing.business.MatchingBusiness; +import com.aliens.backend.mathcing.controller.dto.response.MatchingResultResponse; import com.aliens.backend.mathcing.domain.MatchingResult; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; import com.aliens.backend.mathcing.domain.repository.MatchingResultRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; -import com.aliens.backend.mathcing.service.model.Participant; -import com.aliens.backend.mathcing.service.model.Partner; +import com.aliens.backend.mathcing.business.model.Participant; +import com.aliens.backend.mathcing.business.model.Partner; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -17,8 +19,6 @@ import java.util.List; -import static com.aliens.backend.mathcing.controller.dto.response.MatchingResponse.*; - @Service public class MatchingService { private final MatchingRoundRepository matchingRoundRepository; @@ -50,13 +50,13 @@ public void operateMatching() { } @Transactional(readOnly = true) - public List findMatchingResult(final Long memberId) { + public List findMatchingResult(final LoginMember loginMember) { currentRound = matchingRoundRepository.findCurrentRound() .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); List matchingResults = - matchingResultRepository.findAllByMatchingRoundAndMemberId(currentRound, memberId); + matchingResultRepository.findAllByMatchingRoundAndMemberId(currentRound, loginMember.memberId()); checkHasApplied(matchingResults); - return matchingResults.stream().map(MatchingResultResponse::of).toList(); + return matchingResults.stream().map(MatchingResultResponse::from).toList(); } private void saveMatchingResult(final List participants) { diff --git a/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java b/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java index 49885f39..febdbe0e 100644 --- a/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java +++ b/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java @@ -4,7 +4,7 @@ import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.mathcing.controller.dto.request.MatchingApplicationRequest; -import com.aliens.backend.mathcing.service.model.Language; +import com.aliens.backend.mathcing.business.model.Language; import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidatorContext; diff --git a/src/test/java/com/aliens/backend/global/DummyGenerator.java b/src/test/java/com/aliens/backend/global/DummyGenerator.java index a4a8c677..69836d12 100644 --- a/src/test/java/com/aliens/backend/global/DummyGenerator.java +++ b/src/test/java/com/aliens/backend/global/DummyGenerator.java @@ -1,11 +1,13 @@ package com.aliens.backend.global; +import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.auth.domain.Member; +import com.aliens.backend.auth.domain.MemberRole; import com.aliens.backend.auth.service.PasswordEncoder; import com.aliens.backend.auth.service.TokenProvider; -import com.aliens.backend.mathcing.controller.dto.request.MatchingRequest; +import com.aliens.backend.mathcing.controller.dto.request.MatchingApplicationRequest; import com.aliens.backend.mathcing.service.MatchingApplicationService; -import com.aliens.backend.mathcing.service.model.Language; +import com.aliens.backend.mathcing.business.model.Language; import com.aliens.backend.member.controller.dto.EncodedMember; import com.aliens.backend.member.controller.dto.EncodedSignUp; import com.aliens.backend.member.domain.Image; @@ -121,8 +123,9 @@ public void generateAppliersToMatch(Long numberOfMember) { secondPreferLanguage = getRandomLanguage(random); } while (firstPreferLanguage == secondPreferLanguage); - MatchingRequest.MatchingApplicationRequest request = new MatchingRequest.MatchingApplicationRequest(i, firstPreferLanguage, secondPreferLanguage); - matchingApplicationService.saveParticipant(request); + LoginMember loginMember = new LoginMember(i, MemberRole.MEMBER); + MatchingApplicationRequest request = new MatchingApplicationRequest(firstPreferLanguage, secondPreferLanguage); + matchingApplicationService.saveParticipant(loginMember, request); } } diff --git a/src/test/java/com/aliens/backend/matching/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/business/MatchingBusinessTest.java index 32c76cf2..57a20d82 100644 --- a/src/test/java/com/aliens/backend/matching/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/business/MatchingBusinessTest.java @@ -13,7 +13,7 @@ import com.aliens.backend.mathcing.domain.repository.MatchingResultRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.MatchingService; -import com.aliens.backend.mathcing.service.model.Participant; +import com.aliens.backend.mathcing.business.model.Participant; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; diff --git a/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java index 5fee4a23..26968c0f 100644 --- a/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java @@ -1,16 +1,20 @@ package com.aliens.backend.matching.service; +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.auth.domain.MemberRole; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; import com.aliens.backend.matching.time.MockClock; +import com.aliens.backend.mathcing.controller.dto.request.MatchingApplicationRequest; +import com.aliens.backend.mathcing.controller.dto.response.MatchingApplicationResponse; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.id.MatchingApplicationId; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.MatchingApplicationService; -import com.aliens.backend.mathcing.service.model.Language; +import com.aliens.backend.mathcing.business.model.Language; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -22,8 +26,6 @@ import static com.aliens.backend.matching.time.MockTime.INVALID_TIME; import static com.aliens.backend.matching.time.MockTime.VALID_TIME; -import static com.aliens.backend.mathcing.controller.dto.request.MatchingRequest.*; -import static com.aliens.backend.mathcing.controller.dto.response.MatchingResponse.*; import static org.assertj.core.api.Assertions.*; @@ -35,12 +37,16 @@ class MatchingApplicationServiceTest { @Autowired MatchingTimeProperties matchingTimeProperties; @Autowired MockClock mockClock; + LoginMember loginMember; MatchingApplicationRequest matchingApplicationRequest; + MatchingRound currentRound; @BeforeEach void setUp() { createNewMatchingRound(); - matchingApplicationRequest = new MatchingApplicationRequest(1L, Language.KOREAN, Language.ENGLISH); + loginMember = new LoginMember(1L, MemberRole.MEMBER); + matchingApplicationRequest = new MatchingApplicationRequest(Language.KOREAN, Language.ENGLISH); + currentRound = getCurrentRound(); } @Test @@ -49,15 +55,14 @@ void setUp() { void applyMatchTest() { // given mockClock.mockTime(VALID_TIME); + Long expectedResult = loginMember.memberId(); // when - matchingApplicationService.saveParticipant(matchingApplicationRequest); + matchingApplicationService.saveParticipant(loginMember, matchingApplicationRequest); // then - MatchingApplication result = matchingApplicationRepository - .findById(MatchingApplicationId.of(getCurrentRound(), matchingApplicationRequest.memberId())) - .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); - assertThat(result.getMemberId()).isEqualTo(matchingApplicationRequest.memberId()); + MatchingApplication result = findMatchingApplication(loginMember); + assertThat(result.getMemberId()).isEqualTo(expectedResult); } @Test @@ -68,7 +73,7 @@ void applyMatchIfNotValidTime() { mockClock.mockTime(INVALID_TIME); // when & then - assertThatThrownBy(() -> matchingApplicationService.saveParticipant(matchingApplicationRequest)) + assertThatThrownBy(() -> matchingApplicationService.saveParticipant(loginMember, matchingApplicationRequest)) .hasMessage(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME.getDevelopCode()); } @@ -78,14 +83,14 @@ void applyMatchIfNotValidTime() { @Transactional void getMatchingApplicationTest() { // given + Long expectedResult = loginMember.memberId(); applyToMatch(); //when - MatchingApplicationResponse result = matchingApplicationService - .findMatchingApplication(matchingApplicationRequest.memberId()); + MatchingApplicationResponse result = matchingApplicationService.findMatchingApplication(loginMember); // then - assertThat(result.memberId()).isEqualTo(matchingApplicationRequest.memberId()); + assertThat(result.memberId()).isEqualTo(expectedResult); } @Test @@ -93,7 +98,7 @@ void getMatchingApplicationTest() { @Transactional void getMatchingApplicationIfNotApplied() { // when & then - assertThatThrownBy(() -> matchingApplicationService.findMatchingApplication(matchingApplicationRequest.memberId())) + assertThatThrownBy(() -> matchingApplicationService.findMatchingApplication(loginMember)) .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getDevelopCode()); } @@ -106,10 +111,10 @@ void deleteMatchingApplicationTest() { mockClock.mockTime(VALID_TIME); // when - matchingApplicationService.deleteMatchingApplication(matchingApplicationRequest.memberId()); + matchingApplicationService.deleteMatchingApplication(loginMember); // then - assertThatThrownBy(() -> matchingApplicationService.findMatchingApplication(matchingApplicationRequest.memberId())) + assertThatThrownBy(() -> matchingApplicationService.findMatchingApplication(loginMember)) .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getDevelopCode()); } @@ -122,7 +127,7 @@ void deleteMatchIfNotValidTime() { mockClock.mockTime(INVALID_TIME); // when & then - assertThatThrownBy(() -> matchingApplicationService.deleteMatchingApplication(matchingApplicationRequest.memberId())) + assertThatThrownBy(() -> matchingApplicationService.deleteMatchingApplication(loginMember)) .hasMessage(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME.getDevelopCode()); } @@ -133,13 +138,13 @@ void deleteMatchIfNotApplied() { // given mockClock.mockTime(VALID_TIME); - assertThatThrownBy(() -> matchingApplicationService.deleteMatchingApplication(matchingApplicationRequest.memberId())) + assertThatThrownBy(() -> matchingApplicationService.deleteMatchingApplication(loginMember)) .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getDevelopCode()); } private void applyToMatch() { mockClock.mockTime(VALID_TIME); - matchingApplicationService.saveParticipant(matchingApplicationRequest); + matchingApplicationService.saveParticipant(loginMember, matchingApplicationRequest); } private void createNewMatchingRound() { @@ -151,4 +156,10 @@ private MatchingRound getCurrentRound() { return matchingRoundRepository.findCurrentRound() .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); } + + private MatchingApplication findMatchingApplication(LoginMember loginMember) { + return matchingApplicationRepository + .findById(MatchingApplicationId.of(currentRound, loginMember.memberId())) + .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); + } } From 37c3be2179caacfffeed7ecd78f548bc3b96e107 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 14 Feb 2024 15:57:50 +0900 Subject: [PATCH 04/46] =?UTF-8?q?fix=20:=20of=20->=20from=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/dto/response/MatchingApplicationResponse.java | 4 ++-- .../backend/mathcing/service/MatchingApplicationService.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingApplicationResponse.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingApplicationResponse.java index 129a6936..828d469c 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingApplicationResponse.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/response/MatchingApplicationResponse.java @@ -8,9 +8,9 @@ public record MatchingApplicationResponse( Long memberId, Language firstPreferLanguage, Language secondPreferLanguage) { - public static MatchingApplicationResponse of(MatchingApplication matchingApplication) { + public static MatchingApplicationResponse from(MatchingApplication matchingApplication) { return new MatchingApplicationResponse( - matchingApplication.getMatchingRound().getRound(), + matchingApplication.getRound(), matchingApplication.getMemberId(), matchingApplication.getFirstPreferLanguage(), matchingApplication.getSecondPreferLanguage()); diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java index 7d9f13aa..ee6042d7 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java @@ -47,7 +47,7 @@ public MatchingApplicationResponse findMatchingApplication(final LoginMember log MatchingApplication matchingApplication = matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, loginMember.memberId())) .orElseThrow(()->new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); - return MatchingApplicationResponse.of(matchingApplication); + return MatchingApplicationResponse.from(matchingApplication); } @Transactional From 0d2c4f7dfe06445f94c531a664b74bd841181d8d Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 14 Feb 2024 16:10:55 +0900 Subject: [PATCH 05/46] =?UTF-8?q?refactor=20:=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B8=EB=9D=BC=EC=9D=B8=ED=99=94=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20=EB=B0=8F=20=EC=98=88=EC=99=B8=20=EB=8D=98=EC=A7=80?= =?UTF-8?q?=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=8A=94=20=EB=94=B0?= =?UTF-8?q?=EB=A1=9C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MatchingApplicationService.java | 13 +++--- .../service/MatchingRoundService.java | 4 +- .../mathcing/service/MatchingService.java | 41 ++++++++++++------- .../matching/service/MatchingServiceTest.java | 14 +++++-- 4 files changed, 46 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java index ee6042d7..0d7e5a7a 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java @@ -44,9 +44,7 @@ public String saveParticipant(final LoginMember loginMember, @Transactional(readOnly = true) public MatchingApplicationResponse findMatchingApplication(final LoginMember loginMember) { MatchingRound currentRound = getCurrentRound(); - MatchingApplication matchingApplication = - matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, loginMember.memberId())) - .orElseThrow(()->new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); + MatchingApplication matchingApplication = getMatchingApplication(currentRound, loginMember); return MatchingApplicationResponse.from(matchingApplication); } @@ -54,9 +52,7 @@ public MatchingApplicationResponse findMatchingApplication(final LoginMember log public String deleteMatchingApplication(final LoginMember loginMember) { MatchingRound currentRound = getCurrentRound(); checkReceptionTime(currentRound); - MatchingApplication matchingApplication = - matchingApplicationRepository.findById(MatchingApplicationId.of(currentRound, loginMember.memberId())) - .orElseThrow(()->new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); + MatchingApplication matchingApplication = getMatchingApplication(currentRound, loginMember); matchingApplicationRepository.delete(matchingApplication); return MatchingSuccess.CANCEL_MATCHING_APPLICATION_SUCCESS.getMessage(); } @@ -66,6 +62,11 @@ private MatchingRound getCurrentRound() { .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); } + private MatchingApplication getMatchingApplication(MatchingRound matchingRound, LoginMember loginMember) { + return matchingApplicationRepository.findById(MatchingApplicationId.of(matchingRound, loginMember.memberId())) + .orElseThrow(()->new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); + } + private void checkReceptionTime(MatchingRound matchingRound) { if (!matchingRound.isReceptionTime(LocalDateTime.now(clock))) { throw new RestApiException(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME); diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java index c2ba2929..a243f2a7 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java @@ -3,7 +3,6 @@ import com.aliens.backend.global.property.MatchingTimeProperties; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -26,6 +25,7 @@ public MatchingRoundService(final MatchingRoundRepository matchingRoundRepositor @Scheduled(cron = "${matching.round.update-date}") private void saveMatchRound() { - matchingRoundRepository.save(MatchingRound.of(LocalDateTime.now(clock), matchingTimeProperties)); + MatchingRound matchingRound = MatchingRound.of(LocalDateTime.now(clock), matchingTimeProperties); + matchingRoundRepository.save(matchingRound); } } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java index 6afaf9b9..ff9b391c 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java @@ -5,6 +5,7 @@ import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.mathcing.business.MatchingBusiness; import com.aliens.backend.mathcing.controller.dto.response.MatchingResultResponse; +import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingResult; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; @@ -12,7 +13,6 @@ import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.business.model.Participant; import com.aliens.backend.mathcing.business.model.Partner; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -28,7 +28,6 @@ public class MatchingService { private MatchingRound currentRound; - @Autowired public MatchingService(final MatchingRoundRepository matchingRoundRepository, final MatchingApplicationRepository matchingApplicationRepository, final MatchingResultRepository matchingResultRepository, @@ -42,36 +41,48 @@ public MatchingService(final MatchingRoundRepository matchingRoundRepository, @Scheduled(cron = "${matching.round.start}") @Transactional public void operateMatching() { - currentRound = matchingRoundRepository.findCurrentRound() - .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); - List participants = matchingBusiness.operateMatching( - matchingApplicationRepository.findAllByMatchingRound(currentRound)); - saveMatchingResult(participants); + MatchingRound currentRound = getCurrentRound(); + List matchingApplications = getMatchingApplications(currentRound); + List participants = matchingBusiness.operateMatching(matchingApplications); + + saveMatchingResult(currentRound, participants); } @Transactional(readOnly = true) public List findMatchingResult(final LoginMember loginMember) { - currentRound = matchingRoundRepository.findCurrentRound() - .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); - List matchingResults = - matchingResultRepository.findAllByMatchingRoundAndMemberId(currentRound, loginMember.memberId()); + MatchingRound currentRound = getCurrentRound(); + List matchingResults = getMatchingResult(currentRound, loginMember); checkHasApplied(matchingResults); return matchingResults.stream().map(MatchingResultResponse::from).toList(); } - private void saveMatchingResult(final List participants) { + private void saveMatchingResult(final MatchingRound matchingRound, final List participants) { for (Participant participant : participants) { for (Partner partner : participant.partners()) { - matchingResultRepository.save( - MatchingResult.of(currentRound, partner.memberId(), partner.memberId(), partner.relationship())); + MatchingResult matchingResult = + MatchingResult.of(matchingRound, participant.memberId(), partner.memberId(), partner.relationship()); + matchingResultRepository.save(matchingResult); } // TODO : 매칭 완료 알림 이벤트 발송 & 채팅방 개설 이벤트 발송 } } - private void checkHasApplied(List matchingResults) { + private void checkHasApplied(final List matchingResults) { if (matchingResults.isEmpty()) { throw new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO); } } + + private MatchingRound getCurrentRound() { + return matchingRoundRepository.findCurrentRound() + .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + } + + private List getMatchingResult(final MatchingRound matchingRound, final LoginMember loginMember) { + return matchingResultRepository.findAllByMatchingRoundAndMemberId(matchingRound, loginMember.memberId()); + } + + private List getMatchingApplications(final MatchingRound matchingRound) { + return matchingApplicationRepository.findAllByMatchingRound(matchingRound); + } } diff --git a/src/test/java/com/aliens/backend/matching/service/MatchingServiceTest.java b/src/test/java/com/aliens/backend/matching/service/MatchingServiceTest.java index 40131857..70564851 100644 --- a/src/test/java/com/aliens/backend/matching/service/MatchingServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/service/MatchingServiceTest.java @@ -1,5 +1,7 @@ package com.aliens.backend.matching.service; +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.auth.domain.MemberRole; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; @@ -24,19 +26,25 @@ class MatchingServiceTest { @Autowired MatchingTimeProperties matchingTimeProperties; MatchingRound currentRound; + LoginMember loginMember; @BeforeEach void setUp() { + loginMember = new LoginMember(1L, MemberRole.MEMBER); LocalDateTime roundBeginTime = LocalDateTime.of(2024, 1, 29, 0, 0); matchingRoundRepository.save(MatchingRound.of(roundBeginTime, matchingTimeProperties)); - currentRound = matchingRoundRepository.findCurrentRound() - .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + currentRound = getCurrentRound(); } @Test @DisplayName("매칭을 신청한 적이 없는 회원이 매칭 조회") void getMatchingResultTest() { - assertThatThrownBy(() -> matchingService.findMatchingResult(1L)) + assertThatThrownBy(() -> matchingService.findMatchingResult(loginMember)) .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getDevelopCode()); } + + private MatchingRound getCurrentRound() { + return matchingRoundRepository.findCurrentRound() + .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + } } From bf9a5d859aca4487d28255db6b253832679fe0e4 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 14 Feb 2024 16:15:09 +0900 Subject: [PATCH 06/46] =?UTF-8?q?refactor=20:=20MatchingRound=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20matching=20=EC=A0=91=EB=91=90=EC=82=AC=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/domain/MatchingRound.java | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java index bac8ccb2..3465dc6b 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java @@ -12,17 +12,17 @@ public class MatchingRound { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long round; - @Column(name = "matching_request_start_time") - private LocalDateTime matchingRequestStartTime; + @Column(name = "request_start_time") + private LocalDateTime requestStartTime; - @Column(name = "matching_request_end_time") - private LocalDateTime matchingRequestEndTime; + @Column(name = "request_end_time") + private LocalDateTime requestEndTime; - @Column(name = "matching_valid_start_time") - private LocalDateTime matchingValidStartTime; + @Column(name = "valid_start_time") + private LocalDateTime validStartTime; - @Column(name = "matching_valid_end_time") - private LocalDateTime matchingValidEndTime; + @Column(name = "valid_end_time") + private LocalDateTime validEndTime; protected MatchingRound() { } @@ -31,30 +31,30 @@ public Long getRound() { return round; } - public LocalDateTime getMatchingRequestStartTime() { - return matchingRequestStartTime; + public LocalDateTime getRequestStartTime() { + return requestStartTime; } - public LocalDateTime getMatchingRequestEndTime() { - return matchingRequestEndTime; + public LocalDateTime getRequestEndTime() { + return requestEndTime; } - public LocalDateTime getMatchingValidStartTime() { - return matchingValidStartTime; + public LocalDateTime getValidStartTime() { + return validStartTime; } - public LocalDateTime getMatchingValidEndTime() { - return matchingValidEndTime; + public LocalDateTime getValidEndTime() { + return validEndTime; } - private MatchingRound(final LocalDateTime matchingRequestStartTime, - final LocalDateTime matchingRequestEndTime, - final LocalDateTime matchingValidStartTime, - final LocalDateTime matchingValidEndTime) { - this.matchingRequestStartTime = matchingRequestStartTime; - this.matchingRequestEndTime = matchingRequestEndTime; - this.matchingValidStartTime = matchingValidStartTime; - this.matchingValidEndTime = matchingValidEndTime; + private MatchingRound(final LocalDateTime requestStartTime, + final LocalDateTime requestEndTime, + final LocalDateTime validStartTime, + final LocalDateTime validEndTime) { + this.requestStartTime = requestStartTime; + this.requestEndTime = requestEndTime; + this.validStartTime = validStartTime; + this.validEndTime = validEndTime; } public static MatchingRound of(final LocalDateTime today, final MatchingTimeProperties matchingTimeProperties) { @@ -69,17 +69,17 @@ public static MatchingRound of(final LocalDateTime today, final MatchingTimeProp } public boolean isReceptionTime(LocalDateTime now) { - return now.isAfter(this.getMatchingRequestStartTime()) && now.isBefore(this.getMatchingRequestEndTime()); + return now.isAfter(this.getRequestStartTime()) && now.isBefore(this.getRequestEndTime()); } @Override public String toString() { return "MatchingRound{" + "round=" + round + - ", matchingRequestStartTime=" + matchingRequestStartTime + - ", matchingRequestEndTime=" + matchingRequestEndTime + - ", matchingValidStartTime=" + matchingValidStartTime + - ", matchingValidEndTime=" + matchingValidEndTime + + ", requestStartTime=" + requestStartTime + + ", requestEndTime=" + requestEndTime + + ", validStartTime=" + validStartTime + + ", validEndTime=" + validEndTime + '}'; } } From be922d3ac677779e7e027faf50a1255d01a44d2f Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 14 Feb 2024 16:19:45 +0900 Subject: [PATCH 07/46] =?UTF-8?q?refactor=20:=20properties=EC=9D=98=20Pars?= =?UTF-8?q?e=EB=AC=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../property/MatchingTimeProperties.java | 24 +++++++++---------- .../mathcing/domain/MatchingRound.java | 12 +++++----- .../service/MatchingRoundService.java | 2 +- .../business/MatchingBusinessTest.java | 2 +- .../MatchingApplicationServiceTest.java | 2 +- .../service/MatchingRoundServiceTest.java | 4 ++-- .../matching/service/MatchingServiceTest.java | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java b/src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java index e199d2ee..202da223 100644 --- a/src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java +++ b/src/main/java/com/aliens/backend/global/property/MatchingTimeProperties.java @@ -8,35 +8,35 @@ @Component public class MatchingTimeProperties { @Value("${matching.request.time.hours}") - private String matchingRequestAvailableTime; + private Long requestAvailableTime; @Value("${matching.valid.time.hours}") - private String matchingValidBeginHours; + private Integer validBeginHours; @Value("${matching.valid.day-of-week.if.monday.hours}") - private String mondayMatchingValidHours; + private Long mondayMatchingValidHours; @Value("${matching.valid.day-of-week.if.thursday.hours}") - private String thursdayMatchingValidHours; + private Long thursdayMatchingValidHours; @Value("${matching.valid.day-of-week.if.default.hours}") - private String defaultMatchingValidHours; + private Long defaultMatchingValidHours; - public Long getMatchingRequestAvailableTime() { - return Long.parseLong(matchingRequestAvailableTime); + public Long getRequestAvailableTime() { + return requestAvailableTime; } - public Integer getMatchingValidBeginHours() { - return Integer.parseInt(matchingValidBeginHours); + public Integer getValidBeginHours() { + return validBeginHours; } public Long getMatchingValidHours(final DayOfWeek dayOfWeek) { if (dayOfWeek.equals(DayOfWeek.MONDAY)) { - return Long.parseLong(mondayMatchingValidHours); + return mondayMatchingValidHours; } if (dayOfWeek.equals(DayOfWeek.THURSDAY)) { - return Long.parseLong(thursdayMatchingValidHours); + return thursdayMatchingValidHours; } - return Long.parseLong(defaultMatchingValidHours); + return defaultMatchingValidHours; } } diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java index 3465dc6b..d24b7e88 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java @@ -57,15 +57,15 @@ private MatchingRound(final LocalDateTime requestStartTime, this.validEndTime = validEndTime; } - public static MatchingRound of(final LocalDateTime today, final MatchingTimeProperties matchingTimeProperties) { + public static MatchingRound from(final LocalDateTime today, final MatchingTimeProperties matchingTimeProperties) { DayOfWeek dayOfWeek = today.getDayOfWeek(); - LocalDateTime matchingRequestStartTime = today.withHour(0).withMinute(0).withSecond(0).withNano(0); - LocalDateTime matchingRequestEndTime = matchingRequestStartTime.plusHours(matchingTimeProperties.getMatchingRequestAvailableTime()); - LocalDateTime matchingValidStartTime = today.withHour(matchingTimeProperties.getMatchingValidBeginHours()).withMinute(0).withSecond(0).withNano(0); - LocalDateTime matchingValidEndTime = matchingValidStartTime.plusHours(matchingTimeProperties.getMatchingValidHours(dayOfWeek)); + LocalDateTime requestStartTime = today.withHour(0).withMinute(0).withSecond(0).withNano(0); + LocalDateTime requestEndTime = requestStartTime.plusHours(matchingTimeProperties.getRequestAvailableTime()); + LocalDateTime validStartTime = today.withHour(matchingTimeProperties.getValidBeginHours()).withMinute(0).withSecond(0).withNano(0); + LocalDateTime validEndTime = validStartTime.plusHours(matchingTimeProperties.getMatchingValidHours(dayOfWeek)); - return new MatchingRound(matchingRequestStartTime, matchingRequestEndTime, matchingValidStartTime, matchingValidEndTime); + return new MatchingRound(requestStartTime, requestEndTime, validStartTime, validEndTime); } public boolean isReceptionTime(LocalDateTime now) { diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java index a243f2a7..f24ca0ea 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingRoundService.java @@ -25,7 +25,7 @@ public MatchingRoundService(final MatchingRoundRepository matchingRoundRepositor @Scheduled(cron = "${matching.round.update-date}") private void saveMatchRound() { - MatchingRound matchingRound = MatchingRound.of(LocalDateTime.now(clock), matchingTimeProperties); + MatchingRound matchingRound = MatchingRound.from(LocalDateTime.now(clock), matchingTimeProperties); matchingRoundRepository.save(matchingRound); } } diff --git a/src/test/java/com/aliens/backend/matching/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/business/MatchingBusinessTest.java index 57a20d82..3cca08aa 100644 --- a/src/test/java/com/aliens/backend/matching/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/business/MatchingBusinessTest.java @@ -43,7 +43,7 @@ class MatchingBusinessTest { @BeforeEach void setUp() { LocalDateTime roundBeginTime = LocalDateTime.of(2024, 1, 29, 0, 0); - matchingRoundRepository.save(MatchingRound.of(roundBeginTime, matchingTimeProperties)); + matchingRoundRepository.save(MatchingRound.from(roundBeginTime, matchingTimeProperties)); currentRound = matchingRoundRepository.findCurrentRound() .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); } diff --git a/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java index 26968c0f..e743ba1c 100644 --- a/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java @@ -149,7 +149,7 @@ private void applyToMatch() { private void createNewMatchingRound() { LocalDateTime roundBeginTime = LocalDateTime.of(2024, 1, 29, 0, 0); - matchingRoundRepository.save(MatchingRound.of(roundBeginTime, matchingTimeProperties)); + matchingRoundRepository.save(MatchingRound.from(roundBeginTime, matchingTimeProperties)); } private MatchingRound getCurrentRound() { diff --git a/src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java b/src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java index 60024e53..7e0fd9c3 100644 --- a/src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java @@ -25,7 +25,7 @@ class MatchingRoundServiceTest { @Transactional void saveMatchRoundTest() { LocalDateTime monday = LocalDateTime.of(2024, 1, 29, 0, 0); - MatchingRound result = matchingRoundRepository.save(MatchingRound.of(monday, matchingTimeProperties)); + MatchingRound result = matchingRoundRepository.save(MatchingRound.from(monday, matchingTimeProperties)); assertThat(result.getRound()).isNotNull(); } @@ -35,7 +35,7 @@ void saveMatchRoundTest() { @Transactional void getCurrentRound() { LocalDateTime monday = LocalDateTime.of(2024, 1, 29, 0, 0); - matchingRoundRepository.save(MatchingRound.of(monday, matchingTimeProperties)); + matchingRoundRepository.save(MatchingRound.from(monday, matchingTimeProperties)); MatchingRound result = matchingRoundRepository.findCurrentRound() .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); diff --git a/src/test/java/com/aliens/backend/matching/service/MatchingServiceTest.java b/src/test/java/com/aliens/backend/matching/service/MatchingServiceTest.java index 70564851..37f4922d 100644 --- a/src/test/java/com/aliens/backend/matching/service/MatchingServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/service/MatchingServiceTest.java @@ -32,7 +32,7 @@ class MatchingServiceTest { void setUp() { loginMember = new LoginMember(1L, MemberRole.MEMBER); LocalDateTime roundBeginTime = LocalDateTime.of(2024, 1, 29, 0, 0); - matchingRoundRepository.save(MatchingRound.of(roundBeginTime, matchingTimeProperties)); + matchingRoundRepository.save(MatchingRound.from(roundBeginTime, matchingTimeProperties)); currentRound = getCurrentRound(); } From 56f25f80434b2561a3e143992e7144541ca223de Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 14 Feb 2024 16:20:39 +0900 Subject: [PATCH 08/46] =?UTF-8?q?refactor=20:=20private=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EB=8A=94=20public=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=95=84=EB=9E=98=EC=97=90=20=EC=9C=84=EC=B9=98?= =?UTF-8?q?=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 --- .../backend/mathcing/business/MatchingBusiness.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index c68b7867..6562703a 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -23,12 +23,6 @@ public MatchingBusiness(final MatchingRuleProperties matchingRuleProperties) { this.matchingRuleProperties = matchingRuleProperties; } - private void initialize(final List matchingApplications) { - participants = MatchingApplication.toParticipantList(matchingApplications); - languageQueueWithParticipants = Language.createQueueWith(participants); - relationship = Relationship.NORMAL; - } - public List operateMatching(final List matchingApplications) { initialize(matchingApplications); @@ -40,6 +34,12 @@ public List operateMatching(final List matchin return participants; } + private void initialize(final List matchingApplications) { + participants = MatchingApplication.toParticipantList(matchingApplications); + languageQueueWithParticipants = Language.createQueueWith(participants); + relationship = Relationship.NORMAL; + } + private void matchParticipantsWith(final MatchingMode matchingMode) { List participants = null; if (matchingMode.equals(MatchingMode.FIRST_PREFER_LANGUAGE)) { From 67fed89d34779c8815d491cc9a57c9171a57fbb8 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 14 Feb 2024 16:21:41 +0900 Subject: [PATCH 09/46] =?UTF-8?q?refactor=20:=20MatchingRuleProperties?= =?UTF-8?q?=EC=9D=98=20Parse=EB=AC=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/property/MatchingRuleProperties.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/aliens/backend/global/property/MatchingRuleProperties.java b/src/main/java/com/aliens/backend/global/property/MatchingRuleProperties.java index 1f678d9b..e6a07970 100644 --- a/src/main/java/com/aliens/backend/global/property/MatchingRuleProperties.java +++ b/src/main/java/com/aliens/backend/global/property/MatchingRuleProperties.java @@ -6,23 +6,23 @@ @Component public class MatchingRuleProperties { @Value("${matching.rule.max-matches.partner}") - private String maxPartners; + private Integer maxPartners; @Value("${matching.rule.max-matches.normal-partner}") - private String maxNormalPartners; + private Integer maxNormalPartners; @Value("${matching.rule.max-tries}") - private String maxTries; + private Integer maxTries; public Integer getMaxNormalPartners() { - return Integer.parseInt(maxNormalPartners); + return maxNormalPartners; } public Integer getMaxTries() { - return Integer.parseInt(maxTries); + return maxTries; } public Integer getMaxPartners() { - return Integer.parseInt(maxPartners); + return maxPartners; } } From 14086f4d0e82d45f526752b5e4c4e5ded98e645a Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 14 Feb 2024 16:27:08 +0900 Subject: [PATCH 10/46] =?UTF-8?q?fix=20:=20MatchingRound=EA=B0=80=20MAX?= =?UTF-8?q?=EC=9D=B8=20Round=EB=A5=BC=20=EA=B0=80=EC=A0=B8=EC=98=A4?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=BF=BC=EB=A6=AC=EB=A5=BC=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 --- .../mathcing/domain/MatchingRound.java | 4 ++++ .../repository/MatchingRoundRepository.java | 2 +- .../backend/matching/time/MockTime.java | 14 ----------- .../business/MatchingBusinessTest.java | 6 ++--- .../MatchingApplicationServiceTest.java | 8 +++---- .../service/MatchingRoundServiceTest.java | 23 +++++++++++++++---- .../service/MatchingServiceTest.java | 2 +- .../matching/{ => util}/time/MockClock.java | 2 +- .../backend/matching/util/time/MockTime.java | 22 ++++++++++++++++++ 9 files changed, 54 insertions(+), 29 deletions(-) delete mode 100644 src/test/java/com/aliens/backend/matching/time/MockTime.java rename src/test/java/com/aliens/backend/matching/{ => unit}/business/MatchingBusinessTest.java (94%) rename src/test/java/com/aliens/backend/matching/{ => unit}/service/MatchingApplicationServiceTest.java (96%) rename src/test/java/com/aliens/backend/matching/{ => unit}/service/MatchingRoundServiceTest.java (66%) rename src/test/java/com/aliens/backend/matching/{ => unit}/service/MatchingServiceTest.java (97%) rename src/test/java/com/aliens/backend/matching/{ => util}/time/MockClock.java (93%) create mode 100644 src/test/java/com/aliens/backend/matching/util/time/MockTime.java diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java index d24b7e88..a301584a 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java @@ -47,6 +47,10 @@ public LocalDateTime getValidEndTime() { return validEndTime; } + public DayOfWeek getDayOfWeek() { + return requestStartTime.getDayOfWeek(); + } + private MatchingRound(final LocalDateTime requestStartTime, final LocalDateTime requestEndTime, final LocalDateTime validStartTime, diff --git a/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingRoundRepository.java b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingRoundRepository.java index af5f1431..9fd8f3b3 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingRoundRepository.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingRoundRepository.java @@ -9,6 +9,6 @@ @Repository public interface MatchingRoundRepository extends JpaRepository { - @Query("SELECT mr FROM MatchingRound mr ORDER BY mr.round DESC") + @Query("SELECT mr FROM MatchingRound mr WHERE mr.round = (SELECT MAX(mr.round) FROM MatchingRound mr)") Optional findCurrentRound(); } diff --git a/src/test/java/com/aliens/backend/matching/time/MockTime.java b/src/test/java/com/aliens/backend/matching/time/MockTime.java deleted file mode 100644 index 9a1538c7..00000000 --- a/src/test/java/com/aliens/backend/matching/time/MockTime.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.aliens.backend.matching.time; - -import java.time.LocalDateTime; - -public enum MockTime { - INVALID_TIME(LocalDateTime.of(2024, 1, 29, 19, 0)), - VALID_TIME(LocalDateTime.of(2024, 1, 29, 10, 0)); - - public LocalDateTime time; - - MockTime(LocalDateTime time) { - this.time = time; - } -} diff --git a/src/test/java/com/aliens/backend/matching/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java similarity index 94% rename from src/test/java/com/aliens/backend/matching/business/MatchingBusinessTest.java rename to src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java index 3cca08aa..d1994e38 100644 --- a/src/test/java/com/aliens/backend/matching/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -1,11 +1,11 @@ -package com.aliens.backend.matching.business; +package com.aliens.backend.matching.unit.business; import com.aliens.backend.global.DummyGenerator; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; -import com.aliens.backend.matching.time.MockClock; -import com.aliens.backend.matching.time.MockTime; +import com.aliens.backend.matching.util.time.MockClock; +import com.aliens.backend.matching.util.time.MockTime; import com.aliens.backend.mathcing.business.MatchingBusiness; import com.aliens.backend.mathcing.domain.MatchingResult; import com.aliens.backend.mathcing.domain.MatchingRound; diff --git a/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java similarity index 96% rename from src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java rename to src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index e743ba1c..7c3c8e3e 100644 --- a/src/test/java/com/aliens/backend/matching/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -1,11 +1,11 @@ -package com.aliens.backend.matching.service; +package com.aliens.backend.matching.unit.service; import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.auth.domain.MemberRole; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; -import com.aliens.backend.matching.time.MockClock; +import com.aliens.backend.matching.util.time.MockClock; import com.aliens.backend.mathcing.controller.dto.request.MatchingApplicationRequest; import com.aliens.backend.mathcing.controller.dto.response.MatchingApplicationResponse; import com.aliens.backend.mathcing.domain.MatchingApplication; @@ -24,8 +24,8 @@ import java.time.LocalDateTime; -import static com.aliens.backend.matching.time.MockTime.INVALID_TIME; -import static com.aliens.backend.matching.time.MockTime.VALID_TIME; +import static com.aliens.backend.matching.util.time.MockTime.INVALID_TIME; +import static com.aliens.backend.matching.util.time.MockTime.VALID_TIME; import static org.assertj.core.api.Assertions.*; diff --git a/src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java similarity index 66% rename from src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java rename to src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java index 7e0fd9c3..19f5355c 100644 --- a/src/test/java/com/aliens/backend/matching/service/MatchingRoundServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java @@ -1,8 +1,9 @@ -package com.aliens.backend.matching.service; +package com.aliens.backend.matching.unit.service; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; +import com.aliens.backend.matching.util.time.MockTime; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import org.junit.jupiter.api.DisplayName; @@ -11,6 +12,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.transaction.annotation.Transactional; +import java.time.DayOfWeek; import java.time.LocalDateTime; import static org.assertj.core.api.Assertions.*; @@ -24,16 +26,22 @@ class MatchingRoundServiceTest { @DisplayName("매주 월, 목 매칭 회차 업데이트") @Transactional void saveMatchRoundTest() { - LocalDateTime monday = LocalDateTime.of(2024, 1, 29, 0, 0); - MatchingRound result = matchingRoundRepository.save(MatchingRound.from(monday, matchingTimeProperties)); + // given + MatchingRound monday = MatchingRound.from(MockTime.MONDAY.getTime(), matchingTimeProperties); - assertThat(result.getRound()).isNotNull(); + // when + matchingRoundRepository.save(monday); + + // then + MatchingRound currentRound = getCurrentRound(); + DayOfWeek result = currentRound.getDayOfWeek(); + assertThat(result).isEqualTo(DayOfWeek.MONDAY); } @Test @DisplayName("현재 매칭 회차 조회") @Transactional - void getCurrentRound() { + void getCurrentRoundTest() { LocalDateTime monday = LocalDateTime.of(2024, 1, 29, 0, 0); matchingRoundRepository.save(MatchingRound.from(monday, matchingTimeProperties)); @@ -42,4 +50,9 @@ void getCurrentRound() { assertThat(result.getRound()).isNotNull(); } + + private MatchingRound getCurrentRound() { + return matchingRoundRepository.findCurrentRound() + .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + } } diff --git a/src/test/java/com/aliens/backend/matching/service/MatchingServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java similarity index 97% rename from src/test/java/com/aliens/backend/matching/service/MatchingServiceTest.java rename to src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java index 37f4922d..7e278828 100644 --- a/src/test/java/com/aliens/backend/matching/service/MatchingServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java @@ -1,4 +1,4 @@ -package com.aliens.backend.matching.service; +package com.aliens.backend.matching.unit.service; import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.auth.domain.MemberRole; diff --git a/src/test/java/com/aliens/backend/matching/time/MockClock.java b/src/test/java/com/aliens/backend/matching/util/time/MockClock.java similarity index 93% rename from src/test/java/com/aliens/backend/matching/time/MockClock.java rename to src/test/java/com/aliens/backend/matching/util/time/MockClock.java index cd850598..3106e4ba 100644 --- a/src/test/java/com/aliens/backend/matching/time/MockClock.java +++ b/src/test/java/com/aliens/backend/matching/util/time/MockClock.java @@ -1,4 +1,4 @@ -package com.aliens.backend.matching.time; +package com.aliens.backend.matching.util.time; import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.stereotype.Component; diff --git a/src/test/java/com/aliens/backend/matching/util/time/MockTime.java b/src/test/java/com/aliens/backend/matching/util/time/MockTime.java new file mode 100644 index 00000000..7577263c --- /dev/null +++ b/src/test/java/com/aliens/backend/matching/util/time/MockTime.java @@ -0,0 +1,22 @@ +package com.aliens.backend.matching.util.time; + +import java.time.LocalDateTime; + +public enum MockTime { + INVALID_TIME(LocalDateTime.of(2024, 1, 29, 19, 0)), + VALID_TIME(LocalDateTime.of(2024, 1, 29, 10, 0)), + + MONDAY(LocalDateTime.of(2024, 1, 29, 0, 0)), + THURSDAY(LocalDateTime.of(2024, 2, 1, 0, 0)), + ; + + public LocalDateTime time; + + MockTime(LocalDateTime time) { + this.time = time; + } + + public LocalDateTime getTime() { + return time; + } +} From 2decf674722e3a1b2b0d3525a263fce1779eccb8 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 14 Feb 2024 16:28:56 +0900 Subject: [PATCH 11/46] =?UTF-8?q?fix=20:=20MatchingRound=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EA=B2=80=EC=A6=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unit/service/MatchingRoundServiceTest.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java index 19f5355c..84594f52 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java @@ -27,10 +27,10 @@ class MatchingRoundServiceTest { @Transactional void saveMatchRoundTest() { // given - MatchingRound monday = MatchingRound.from(MockTime.MONDAY.getTime(), matchingTimeProperties); + MatchingRound mondayRound = MatchingRound.from(MockTime.MONDAY.getTime(), matchingTimeProperties); // when - matchingRoundRepository.save(monday); + matchingRoundRepository.save(mondayRound); // then MatchingRound currentRound = getCurrentRound(); @@ -42,13 +42,15 @@ void saveMatchRoundTest() { @DisplayName("현재 매칭 회차 조회") @Transactional void getCurrentRoundTest() { - LocalDateTime monday = LocalDateTime.of(2024, 1, 29, 0, 0); - matchingRoundRepository.save(MatchingRound.from(monday, matchingTimeProperties)); + // given + MatchingRound mondayRound = MatchingRound.from(MockTime.MONDAY.getTime(), matchingTimeProperties); + matchingRoundRepository.save(mondayRound); - MatchingRound result = matchingRoundRepository.findCurrentRound() - .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + // then + MatchingRound currentRound = getCurrentRound(); + DayOfWeek result = currentRound.getDayOfWeek(); - assertThat(result.getRound()).isNotNull(); + assertThat(result).isEqualTo(DayOfWeek.MONDAY); } private MatchingRound getCurrentRound() { From 539fc48f225203b96bca54999a971cf255777f5c Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 14 Feb 2024 16:36:53 +0900 Subject: [PATCH 12/46] =?UTF-8?q?refactor=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EB=B0=8F=20=EA=B0=84=EC=86=8C=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/model/CandidateGroup.java | 32 ++++++ .../business/model/LanguageQueue.java | 30 +++++ .../business/model/MatchingTypeGroup.java | 26 +++++ .../business/model/ParticipantGroup.java | 106 ++++++++++++++++++ .../type/FirstPreferLanguageType.java | 19 ++++ .../mathcing/business/type/MatchingType.java | 8 ++ .../mathcing/business/type/RandomType.java | 21 ++++ .../type/SecondPreferLanguageType.java | 20 ++++ .../mathcing/business/type/SpecialType.java | 21 ++++ .../mathcing/domain/MatchingResult.java | 3 +- 10 files changed, 284 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java create mode 100644 src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java create mode 100644 src/main/java/com/aliens/backend/mathcing/business/model/MatchingTypeGroup.java create mode 100644 src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java create mode 100644 src/main/java/com/aliens/backend/mathcing/business/type/FirstPreferLanguageType.java create mode 100644 src/main/java/com/aliens/backend/mathcing/business/type/MatchingType.java create mode 100644 src/main/java/com/aliens/backend/mathcing/business/type/RandomType.java create mode 100644 src/main/java/com/aliens/backend/mathcing/business/type/SecondPreferLanguageType.java create mode 100644 src/main/java/com/aliens/backend/mathcing/business/type/SpecialType.java diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java new file mode 100644 index 00000000..f737c93a --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java @@ -0,0 +1,32 @@ +package com.aliens.backend.mathcing.business.model; + +import java.util.LinkedList; +import java.util.Queue; + +public class CandidateGroup { + private final Queue candidateQueue; + + public CandidateGroup(final Queue candidateQueue) { + this.candidateQueue = candidateQueue; + } + + public static CandidateGroup init() { + return new CandidateGroup(new LinkedList<>()); + } + + public static CandidateGroup of(ParticipantGroup participantGroup) { + return new CandidateGroup(new LinkedList<>(participantGroup.getParticipants())); + } + + public void add(Participant participant) { + candidateQueue.add(participant); + } + + public Participant poll() { + return candidateQueue.poll(); + } + + public boolean isEmpty() { + return candidateQueue.isEmpty(); + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java b/src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java new file mode 100644 index 00000000..da367bf2 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java @@ -0,0 +1,30 @@ +package com.aliens.backend.mathcing.business.model; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class LanguageQueue { + private final Map languageQueue; + + private LanguageQueue(final Map languageQueue) { + this.languageQueue = languageQueue; + } + + public static LanguageQueue from(final ParticipantGroup participantGroup) { + Map languageQueue = new HashMap<>(); + Arrays.stream(Language.values()).forEach(language -> languageQueue.put(language, CandidateGroup.init())); + + participantGroup.getParticipants() + .forEach(participant -> { + Language language = participant.getPreferLanguage(MatchingMode.FIRST_PREFER_LANGUAGE); + CandidateGroup candidateGroup = languageQueue.get(language); + candidateGroup.add(participant); + }); + return new LanguageQueue(languageQueue); + } + + public CandidateGroup get(Language language) { + return languageQueue.get(language); + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/MatchingTypeGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/MatchingTypeGroup.java new file mode 100644 index 00000000..96702197 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/model/MatchingTypeGroup.java @@ -0,0 +1,26 @@ +package com.aliens.backend.mathcing.business.model; + +import com.aliens.backend.global.property.MatchingRuleProperties; +import com.aliens.backend.mathcing.business.type.*; + +import java.util.List; + +public class MatchingTypeGroup { + private List matchingTypes; + + private MatchingTypeGroup(final List matchingTypes) { + this.matchingTypes = matchingTypes; + } + + public static MatchingTypeGroup init(final MatchingRuleProperties matchingRuleProperties) { + return new MatchingTypeGroup( + List.of(new FirstPreferLanguageType(matchingRuleProperties), + new SecondPreferLanguageType(matchingRuleProperties), + new RandomType(matchingRuleProperties), + new SpecialType(matchingRuleProperties))); + } + + public List getMatchingTypes() { + return matchingTypes; + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java new file mode 100644 index 00000000..8ae57789 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java @@ -0,0 +1,106 @@ +package com.aliens.backend.mathcing.business.model; + +import com.aliens.backend.global.property.MatchingRuleProperties; +import com.aliens.backend.mathcing.domain.MatchingApplication; + +import java.util.List; +import java.util.stream.Collectors; + +public class ParticipantGroup { + private final List participants; + private final MatchingRuleProperties matchingRuleProperties; + private Relationship relationship; + + private ParticipantGroup(final List participants, + final MatchingRuleProperties matchingRuleProperties) { + this.participants = participants; + this.matchingRuleProperties = matchingRuleProperties; + this.relationship = Relationship.NORMAL; + } + + public static ParticipantGroup from(final List matchingApplications, + final MatchingRuleProperties matchingRuleProperties) { + List participants = matchingApplications.stream().map(Participant::of).collect(Collectors.toList()); + return new ParticipantGroup(participants, matchingRuleProperties); + } + + public void matchAllWith(CandidateGroup candidateGroup) { + for (Participant participant : participants) { + tryMatchBetween(participant, candidateGroup); + } + } + + public void matchEachWith(LanguageQueue languageQueue, MatchingMode matchingMode) { + for (Participant participant : participants) { + Language preferLanguage = participant.getPreferLanguage(matchingMode); + CandidateGroup candidateGroup = languageQueue.get(preferLanguage); + tryMatchBetween(participant, candidateGroup); + } + } + + public void updateToSpecialRelationshipMode() { + this.relationship = Relationship.SPECIAL; + } + + public ParticipantGroup getParticipantsLessThan(final int numberOfPartner) { + return toGroup(participants.stream() + .filter(participant -> participant.getNumberOfPartners() < numberOfPartner) + .collect(Collectors.toList())); + } + + public List getParticipants() { + return participants; + } + + private void tryMatchBetween(final Participant participant, final CandidateGroup candidates) { + int tries = 0; + while (canContinueMatching(relationship, participant, tries, candidates)) { + Participant partner = candidates.poll(); + tries++; + if (isValidMatching(relationship, participant, partner)) { + addMatching(participant, partner); + if (!isExceededMaxPartners(relationship, partner)) { + candidates.add(partner); + } + } else { + candidates.add(partner); + } + } + } + + private boolean canContinueMatching(final Relationship relationship, + final Participant participant, + int tries, + final CandidateGroup candidates) { + return !isExceededMaxPartners(relationship, participant) && !isExceedMaxTries(tries) && !candidates.isEmpty(); + } + + private void addMatching(final Participant participant, final Participant partner) { + participant.addPartner(relationship, partner.memberId()); + partner.addPartner(relationship, participant.memberId()); + } + + private boolean isValidMatching(final Relationship relationship, + final Participant participant, + final Participant partner) { + return participant != partner && + !participant.isPartnerWith(partner) && + !partner.isPartnerWith(participant) && + !isExceededMaxPartners(relationship, partner); + } + + private boolean isExceededMaxPartners(final Relationship relationship, final Participant participant) { + if (relationship.equals(Relationship.NORMAL)) { + return participant.getNumberOfPartners() >= matchingRuleProperties.getMaxNormalPartners(); // 4 + } + return participant.getNumberOfPartners() >= matchingRuleProperties.getMaxPartners(); // 5 + } + + private boolean isExceedMaxTries(int tries) { + return tries > matchingRuleProperties.getMaxTries(); + } + + private ParticipantGroup toGroup(List participants) { + return new ParticipantGroup(participants, matchingRuleProperties); + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/business/type/FirstPreferLanguageType.java b/src/main/java/com/aliens/backend/mathcing/business/type/FirstPreferLanguageType.java new file mode 100644 index 00000000..faac2513 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/type/FirstPreferLanguageType.java @@ -0,0 +1,19 @@ +package com.aliens.backend.mathcing.business.type; + +import com.aliens.backend.global.property.MatchingRuleProperties; +import com.aliens.backend.mathcing.business.model.LanguageQueue; +import com.aliens.backend.mathcing.business.model.MatchingMode; +import com.aliens.backend.mathcing.business.model.ParticipantGroup; + +public class FirstPreferLanguageType implements MatchingType { + private final MatchingRuleProperties matchingRuleProperties; + + public FirstPreferLanguageType(final MatchingRuleProperties matchingRuleProperties) { + this.matchingRuleProperties = matchingRuleProperties; + } + + @Override + public void doMatch(ParticipantGroup participantGroup, LanguageQueue languageQueue) { + participantGroup.matchEachWith(languageQueue, MatchingMode.FIRST_PREFER_LANGUAGE); + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/business/type/MatchingType.java b/src/main/java/com/aliens/backend/mathcing/business/type/MatchingType.java new file mode 100644 index 00000000..2b5681bd --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/type/MatchingType.java @@ -0,0 +1,8 @@ +package com.aliens.backend.mathcing.business.type; + +import com.aliens.backend.mathcing.business.model.LanguageQueue; +import com.aliens.backend.mathcing.business.model.ParticipantGroup; + +public interface MatchingType { + void doMatch(ParticipantGroup participantGroup, LanguageQueue languageQueue); +} diff --git a/src/main/java/com/aliens/backend/mathcing/business/type/RandomType.java b/src/main/java/com/aliens/backend/mathcing/business/type/RandomType.java new file mode 100644 index 00000000..05a8a963 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/type/RandomType.java @@ -0,0 +1,21 @@ +package com.aliens.backend.mathcing.business.type; + +import com.aliens.backend.global.property.MatchingRuleProperties; +import com.aliens.backend.mathcing.business.model.CandidateGroup; +import com.aliens.backend.mathcing.business.model.LanguageQueue; +import com.aliens.backend.mathcing.business.model.ParticipantGroup; + +public class RandomType implements MatchingType { + private final MatchingRuleProperties matchingRuleProperties; + + public RandomType(final MatchingRuleProperties matchingRuleProperties) { + this.matchingRuleProperties = matchingRuleProperties; + } + + @Override + public void doMatch(final ParticipantGroup participantGroup, final LanguageQueue languageQueue) { + ParticipantGroup participants = participantGroup.getParticipantsLessThan(matchingRuleProperties.getMaxNormalPartners()); + participants.updateToSpecialRelationshipMode(); + participants.matchAllWith(CandidateGroup.of(participants)); + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/business/type/SecondPreferLanguageType.java b/src/main/java/com/aliens/backend/mathcing/business/type/SecondPreferLanguageType.java new file mode 100644 index 00000000..03952afe --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/type/SecondPreferLanguageType.java @@ -0,0 +1,20 @@ +package com.aliens.backend.mathcing.business.type; + +import com.aliens.backend.global.property.MatchingRuleProperties; +import com.aliens.backend.mathcing.business.model.LanguageQueue; +import com.aliens.backend.mathcing.business.model.MatchingMode; +import com.aliens.backend.mathcing.business.model.ParticipantGroup; + +public class SecondPreferLanguageType implements MatchingType { + private final MatchingRuleProperties matchingRuleProperties; + + public SecondPreferLanguageType(final MatchingRuleProperties matchingRuleProperties) { + this.matchingRuleProperties = matchingRuleProperties; + } + + @Override + public void doMatch(final ParticipantGroup participantGroup, final LanguageQueue languageQueue) { + ParticipantGroup participants = participantGroup.getParticipantsLessThan(matchingRuleProperties.getMaxNormalPartners()); + participants.matchEachWith(languageQueue, MatchingMode.SECOND_PREFER_LANGUAGE); + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/business/type/SpecialType.java b/src/main/java/com/aliens/backend/mathcing/business/type/SpecialType.java new file mode 100644 index 00000000..59a8967f --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/type/SpecialType.java @@ -0,0 +1,21 @@ +package com.aliens.backend.mathcing.business.type; + +import com.aliens.backend.global.property.MatchingRuleProperties; +import com.aliens.backend.mathcing.business.model.CandidateGroup; +import com.aliens.backend.mathcing.business.model.LanguageQueue; +import com.aliens.backend.mathcing.business.model.ParticipantGroup; + +public class SpecialType implements MatchingType { + private final MatchingRuleProperties matchingRuleProperties; + + public SpecialType(final MatchingRuleProperties matchingRuleProperties) { + this.matchingRuleProperties = matchingRuleProperties; + } + + @Override + public void doMatch(final ParticipantGroup participantGroup, final LanguageQueue languageQueue) { + ParticipantGroup participants = participantGroup.getParticipantsLessThan(matchingRuleProperties.getMaxPartners()); + participants.updateToSpecialRelationshipMode(); + participants.matchAllWith(CandidateGroup.of(participants)); + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java index ff73603a..bccbf16d 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingResult.java @@ -24,8 +24,7 @@ public static MatchingResult of(MatchingRound matchingRound, Long matchingMemberId, Long matchedMemberId, Relationship relationship) { - return new MatchingResult( - MatchingResultId.of(matchingRound, matchingMemberId, matchedMemberId), relationship); + return new MatchingResult(MatchingResultId.of(matchingRound, matchingMemberId, matchedMemberId), relationship); } public MatchingRound getMatchingRound() { From c8d6b27ff5829b8a2c73f7177838a13b3bd56713 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 14 Feb 2024 16:41:04 +0900 Subject: [PATCH 13/46] =?UTF-8?q?refactor=20:=20=EB=B9=84=EC=A6=88?= =?UTF-8?q?=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EA=B0=84=EC=86=8C=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/business/MatchingBusiness.java | 111 ++---------------- 1 file changed, 10 insertions(+), 101 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index 6562703a..5b568b7c 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -1,125 +1,34 @@ package com.aliens.backend.mathcing.business; import com.aliens.backend.global.property.MatchingRuleProperties; +import com.aliens.backend.mathcing.business.model.*; import com.aliens.backend.mathcing.domain.MatchingApplication; -import com.aliens.backend.mathcing.business.model.Language; -import com.aliens.backend.mathcing.business.model.Participant; -import com.aliens.backend.mathcing.business.model.MatchingMode; -import com.aliens.backend.mathcing.business.model.Relationship; import org.springframework.stereotype.Component; import java.util.*; -import java.util.stream.Collectors; @Component public class MatchingBusiness { private final MatchingRuleProperties matchingRuleProperties; - private List participants = new ArrayList<>(); - private Map> languageQueueWithParticipants = new HashMap<>(); - private Relationship relationship; + private MatchingTypeGroup matchingTypeGroup; + private ParticipantGroup participantGroup; + private LanguageQueue languageQueue; public MatchingBusiness(final MatchingRuleProperties matchingRuleProperties) { this.matchingRuleProperties = matchingRuleProperties; } - public List operateMatching(final List matchingApplications) { + public List operateMatching(List matchingApplications) { initialize(matchingApplications); - matchParticipantsWith(MatchingMode.FIRST_PREFER_LANGUAGE); - matchParticipantsWith(MatchingMode.SECOND_PREFER_LANGUAGE); - matchParticipantsWith(MatchingMode.RANDOM); - matchParticipantsWith(MatchingMode.SPECIAL); - - return participants; + matchingTypeGroup.getMatchingTypes().forEach(matchingType -> matchingType.doMatch(participantGroup, languageQueue)); + return participantGroup.getParticipants(); } private void initialize(final List matchingApplications) { - participants = MatchingApplication.toParticipantList(matchingApplications); - languageQueueWithParticipants = Language.createQueueWith(participants); - relationship = Relationship.NORMAL; - } - - private void matchParticipantsWith(final MatchingMode matchingMode) { - List participants = null; - if (matchingMode.equals(MatchingMode.FIRST_PREFER_LANGUAGE)) { - participants = this.participants; - } - if (matchingMode.equals(MatchingMode.SECOND_PREFER_LANGUAGE)) { - participants = getParticipantsLessThan(matchingRuleProperties.getMaxNormalPartners()); - languageQueueWithParticipants = Language.createQueueWith(this.participants); - } - if (matchingMode.equals(MatchingMode.RANDOM)) { - relationship = Relationship.SPECIAL; - participants = getParticipantsLessThan(matchingRuleProperties.getMaxNormalPartners()); - } - if (matchingMode.equals(MatchingMode.SPECIAL)) { - participants = getParticipantsLessThan(matchingRuleProperties.getMaxPartners()); - } - matchWith(matchingMode, participants); - } - - private void matchWith(final MatchingMode matchingMode, final List participants) { - Queue candidates = null; - if (matchingMode.equals(MatchingMode.RANDOM)) { - candidates = new LinkedList<>(getParticipantsLessThan(matchingRuleProperties.getMaxPartners())); - } - if (matchingMode.equals(MatchingMode.SPECIAL)) { - candidates = new LinkedList<>(participants); - } - for (Participant participant : participants) { - if (matchingMode.equals(MatchingMode.FIRST_PREFER_LANGUAGE) || - matchingMode.equals(MatchingMode.SECOND_PREFER_LANGUAGE)) { - candidates = languageQueueWithParticipants.get(participant.getPreferLanguage(matchingMode)); - } - tryMatchBetween(participant, candidates); - } - } - - private void tryMatchBetween(final Participant participant, final Queue candidates) { - int tries = 0; - while (!isExceededMaxPartners(relationship, participant) && !isExceedMaxTries(tries) && !candidates.isEmpty()) { - Participant partner = candidates.poll(); - tries++; - if (isValidMatching(relationship, participant, partner)) { - addMatching(participant, partner); - if (!isExceededMaxPartners(relationship, partner)) { - candidates.add(partner); - } - } else { - candidates.add(partner); - } - } - } - - private void addMatching(final Participant participant, final Participant partner) { - participant.addPartner(relationship, partner.memberId()); - partner.addPartner(relationship, participant.memberId()); - } - - private List getParticipantsLessThan(int numberOfPartner) { - return participants.stream() - .filter(participant -> participant.getNumberOfPartners() < numberOfPartner) - .collect(Collectors.toList()); - } - - private boolean isValidMatching(final Relationship relationship, - final Participant participant, - final Participant partner) { - return participant != partner && - !participant.isPartnerWith(partner) && - !partner.isPartnerWith(participant) && - !isExceededMaxPartners(relationship, partner); - } - - private boolean isExceededMaxPartners(final Relationship relationship, final Participant participant) { - if (relationship.equals(Relationship.NORMAL)) { - return participant.getNumberOfPartners() >= matchingRuleProperties.getMaxNormalPartners(); // 4 - } - return participant.getNumberOfPartners() >= matchingRuleProperties.getMaxPartners(); // 5 - } - - private boolean isExceedMaxTries(int tries) { - return tries > matchingRuleProperties.getMaxTries(); + participantGroup = ParticipantGroup.from(matchingApplications, matchingRuleProperties); + languageQueue = LanguageQueue.from(participantGroup); + matchingTypeGroup = MatchingTypeGroup.init(matchingRuleProperties); } } From 0fcc54d8731f72cb33d5b51cded44152a2282014 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 14 Feb 2024 16:44:13 +0900 Subject: [PATCH 14/46] =?UTF-8?q?fix=20:=20=EB=A7=A4=EC=B9=AD=20=EC=9E=91?= =?UTF-8?q?=EB=8F=99=20=EB=A1=9C=EC=A7=81=EA=B3=BC=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=EC=A1=B0=ED=9A=8C=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/mathcing/business/MatchingBusiness.java | 5 ++++- .../com/aliens/backend/mathcing/service/MatchingService.java | 5 +++-- .../backend/matching/unit/business/MatchingBusinessTest.java | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index 5b568b7c..55cc2c7c 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -19,10 +19,13 @@ public MatchingBusiness(final MatchingRuleProperties matchingRuleProperties) { this.matchingRuleProperties = matchingRuleProperties; } - public List operateMatching(List matchingApplications) { + public void operateMatching(List matchingApplications) { initialize(matchingApplications); matchingTypeGroup.getMatchingTypes().forEach(matchingType -> matchingType.doMatch(participantGroup, languageQueue)); + } + + public List getParticipants() { return participantGroup.getParticipants(); } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java index ff9b391c..5f5362cb 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java @@ -43,9 +43,10 @@ public MatchingService(final MatchingRoundRepository matchingRoundRepository, public void operateMatching() { MatchingRound currentRound = getCurrentRound(); List matchingApplications = getMatchingApplications(currentRound); - List participants = matchingBusiness.operateMatching(matchingApplications); + matchingBusiness.operateMatching(matchingApplications); - saveMatchingResult(currentRound, participants); + List matchedParticipants = matchingBusiness.getParticipants(); + saveMatchingResult(currentRound, matchedParticipants); } @Transactional(readOnly = true) diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java index d1994e38..abb8263f 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -55,7 +55,8 @@ void matchingLogicTest() { mockClock.mockTime(MockTime.VALID_TIME); dummyGenerator.generateAppliersToMatch(15L); - List result = matchingBusiness.operateMatching(matchingApplicationRepository.findAllByMatchingRound(currentRound)); + matchingBusiness.operateMatching(matchingApplicationRepository.findAllByMatchingRound(currentRound)); + List result = matchingBusiness.getParticipants(); result.forEach(participant -> assertThat(participant.partners()).isNotNull()); } From 4cd86088799f0dd9585376986faa2e88fd92461c Mon Sep 17 00:00:00 2001 From: Oniqued Date: Wed, 14 Feb 2024 16:47:40 +0900 Subject: [PATCH 15/46] =?UTF-8?q?refactor=20:=20@transactional=EC=9D=84=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=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 --- .../matching/unit/business/MatchingBusinessTest.java | 5 ++--- .../unit/service/MatchingApplicationServiceTest.java | 10 ++-------- .../unit/service/MatchingRoundServiceTest.java | 5 ++--- .../matching/unit/service/MatchingServiceTest.java | 3 ++- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java index abb8263f..b3c09ad5 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -1,5 +1,6 @@ package com.aliens.backend.matching.unit.business; +import com.aliens.backend.global.BaseServiceTest; import com.aliens.backend.global.DummyGenerator; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; @@ -28,7 +29,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @SpringBootTest -class MatchingBusinessTest { +class MatchingBusinessTest extends BaseServiceTest { @Autowired MatchingService matchingService; @Autowired MatchingApplicationRepository matchingApplicationRepository; @Autowired MatchingRoundRepository matchingRoundRepository; @@ -49,7 +50,6 @@ void setUp() { } @Test - @Transactional @DisplayName("매칭 로직 실행 테스트") void matchingLogicTest() { mockClock.mockTime(MockTime.VALID_TIME); @@ -63,7 +63,6 @@ void matchingLogicTest() { @Test @DisplayName("매칭 결과 조회") - @Transactional void operateMatchingTest() { // given mockClock.mockTime(MockTime.VALID_TIME); diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index 7c3c8e3e..762798bf 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -2,6 +2,7 @@ import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.auth.domain.MemberRole; +import com.aliens.backend.global.BaseServiceTest; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; @@ -30,7 +31,7 @@ @SpringBootTest -class MatchingApplicationServiceTest { +class MatchingApplicationServiceTest extends BaseServiceTest { @Autowired MatchingApplicationService matchingApplicationService; @Autowired MatchingApplicationRepository matchingApplicationRepository; @Autowired MatchingRoundRepository matchingRoundRepository; @@ -51,7 +52,6 @@ void setUp() { @Test @DisplayName("매칭 신청 단위 테스트") - @Transactional void applyMatchTest() { // given mockClock.mockTime(VALID_TIME); @@ -67,7 +67,6 @@ void applyMatchTest() { @Test @DisplayName("지정 시간 외 매칭 신청시, 에러 발생") - @Transactional void applyMatchIfNotValidTime() { // given mockClock.mockTime(INVALID_TIME); @@ -80,7 +79,6 @@ void applyMatchIfNotValidTime() { @Test @DisplayName("매칭 신청 조회 단위 테스트") - @Transactional void getMatchingApplicationTest() { // given Long expectedResult = loginMember.memberId(); @@ -95,7 +93,6 @@ void getMatchingApplicationTest() { @Test @DisplayName("매칭 신청하지 않은 사용자 조회 테스트") - @Transactional void getMatchingApplicationIfNotApplied() { // when & then assertThatThrownBy(() -> matchingApplicationService.findMatchingApplication(loginMember)) @@ -104,7 +101,6 @@ void getMatchingApplicationIfNotApplied() { @Test @DisplayName("매칭 신청 취소 단위 테스트") - @Transactional void deleteMatchingApplicationTest() { // given applyToMatch(); @@ -120,7 +116,6 @@ void deleteMatchingApplicationTest() { @Test @DisplayName("지정 시간 외 매칭 취소 신청시, 에러 발생") - @Transactional void deleteMatchIfNotValidTime() { // given applyToMatch(); @@ -133,7 +128,6 @@ void deleteMatchIfNotValidTime() { @Test @DisplayName("매칭을 신청하지 않은 사용자 매칭 삭제 요청 테스트") - @Transactional void deleteMatchIfNotApplied() { // given mockClock.mockTime(VALID_TIME); diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java index 84594f52..196dcdea 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingRoundServiceTest.java @@ -1,5 +1,6 @@ package com.aliens.backend.matching.unit.service; +import com.aliens.backend.global.BaseServiceTest; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; @@ -18,13 +19,12 @@ import static org.assertj.core.api.Assertions.*; @SpringBootTest -class MatchingRoundServiceTest { +class MatchingRoundServiceTest extends BaseServiceTest { @Autowired MatchingRoundRepository matchingRoundRepository; @Autowired MatchingTimeProperties matchingTimeProperties; @Test @DisplayName("매주 월, 목 매칭 회차 업데이트") - @Transactional void saveMatchRoundTest() { // given MatchingRound mondayRound = MatchingRound.from(MockTime.MONDAY.getTime(), matchingTimeProperties); @@ -40,7 +40,6 @@ void saveMatchRoundTest() { @Test @DisplayName("현재 매칭 회차 조회") - @Transactional void getCurrentRoundTest() { // given MatchingRound mondayRound = MatchingRound.from(MockTime.MONDAY.getTime(), matchingTimeProperties); diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java index 7e278828..618efee4 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java @@ -2,6 +2,7 @@ import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.auth.domain.MemberRole; +import com.aliens.backend.global.BaseServiceTest; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; @@ -19,7 +20,7 @@ import static org.assertj.core.api.Assertions.*; @SpringBootTest -class MatchingServiceTest { +class MatchingServiceTest extends BaseServiceTest { @Autowired MatchingService matchingService; @Autowired MatchingRoundRepository matchingRoundRepository; From 774dddda7d5f21311fa919f0b9a5c05bce3c7872 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 12:56:40 +0900 Subject: [PATCH 16/46] =?UTF-8?q?refactor=20:=20MatchingTypeGroup=EC=97=90?= =?UTF-8?q?=EA=B2=8C=20=EB=A7=A4=EC=B9=AD=EC=9D=84=20=EB=8F=99=EC=9E=91=20?= =?UTF-8?q?=EC=8B=9C=ED=82=AC=EA=B2=83=EC=9D=84=20=EB=AA=85=EB=A0=B9?= =?UTF-8?q?=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 --- .../aliens/backend/mathcing/business/MatchingBusiness.java | 2 +- .../backend/mathcing/business/model/MatchingTypeGroup.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index 55cc2c7c..d2519872 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -22,7 +22,7 @@ public MatchingBusiness(final MatchingRuleProperties matchingRuleProperties) { public void operateMatching(List matchingApplications) { initialize(matchingApplications); - matchingTypeGroup.getMatchingTypes().forEach(matchingType -> matchingType.doMatch(participantGroup, languageQueue)); + matchingTypeGroup.matchParticipants(participantGroup, languageQueue); } public List getParticipants() { diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/MatchingTypeGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/MatchingTypeGroup.java index 96702197..0699bdac 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/MatchingTypeGroup.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/MatchingTypeGroup.java @@ -6,7 +6,7 @@ import java.util.List; public class MatchingTypeGroup { - private List matchingTypes; + private final List matchingTypes; private MatchingTypeGroup(final List matchingTypes) { this.matchingTypes = matchingTypes; @@ -20,7 +20,7 @@ public static MatchingTypeGroup init(final MatchingRuleProperties matchingRulePr new SpecialType(matchingRuleProperties))); } - public List getMatchingTypes() { - return matchingTypes; + public void matchParticipants(ParticipantGroup participantGroup, LanguageQueue languageQueue) { + matchingTypes.forEach(types -> types.doMatch(participantGroup, languageQueue)); } } From aa654705e5f5527ac8a22d79582fe997fe570ff5 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 12:57:44 +0900 Subject: [PATCH 17/46] =?UTF-8?q?refactor=20:=20=EB=A7=A4=EC=B9=AD=20?= =?UTF-8?q?=EC=B7=A8=EC=86=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=AA=85?= =?UTF-8?q?=EC=9D=84=20delete=20->=20cancel=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/mathcing/controller/MatchingController.java | 2 +- .../mathcing/service/MatchingApplicationService.java | 2 +- .../unit/service/MatchingApplicationServiceTest.java | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java index 9d71333f..0726dd58 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java @@ -42,7 +42,7 @@ public SuccessResponse getMatchingApplication(final @DeleteMapping("/applications") public SuccessResponse cancelMatchingApplication(final @Login LoginMember loginMember) { return SuccessResponse.of(MatchingSuccess.CANCEL_MATCHING_APPLICATION_SUCCESS, - matchingApplicationService.deleteMatchingApplication(loginMember)); + matchingApplicationService.cancelMatchingApplication(loginMember)); } @GetMapping("/partners") diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java index 0d7e5a7a..0207b619 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java @@ -49,7 +49,7 @@ public MatchingApplicationResponse findMatchingApplication(final LoginMember log } @Transactional - public String deleteMatchingApplication(final LoginMember loginMember) { + public String cancelMatchingApplication(final LoginMember loginMember) { MatchingRound currentRound = getCurrentRound(); checkReceptionTime(currentRound); MatchingApplication matchingApplication = getMatchingApplication(currentRound, loginMember); diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index 762798bf..d1a8f71d 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -21,7 +21,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; @@ -107,7 +106,7 @@ void deleteMatchingApplicationTest() { mockClock.mockTime(VALID_TIME); // when - matchingApplicationService.deleteMatchingApplication(loginMember); + matchingApplicationService.cancelMatchingApplication(loginMember); // then assertThatThrownBy(() -> matchingApplicationService.findMatchingApplication(loginMember)) @@ -122,7 +121,7 @@ void deleteMatchIfNotValidTime() { mockClock.mockTime(INVALID_TIME); // when & then - assertThatThrownBy(() -> matchingApplicationService.deleteMatchingApplication(loginMember)) + assertThatThrownBy(() -> matchingApplicationService.cancelMatchingApplication(loginMember)) .hasMessage(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME.getDevelopCode()); } @@ -132,7 +131,7 @@ void deleteMatchIfNotApplied() { // given mockClock.mockTime(VALID_TIME); - assertThatThrownBy(() -> matchingApplicationService.deleteMatchingApplication(loginMember)) + assertThatThrownBy(() -> matchingApplicationService.cancelMatchingApplication(loginMember)) .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getDevelopCode()); } From 3e3c9277af719165b08fa7a2cbed117eadbfcb3a Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 13:32:45 +0900 Subject: [PATCH 18/46] =?UTF-8?q?refactor=20:=20LanguageQueue=20=EB=8F=99?= =?UTF-8?q?=EC=9E=91=20=EB=AA=A9=EC=A0=81=EC=9D=84=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B4=EB=A6=84=EC=9C=BC=EB=A1=9C=20=ED=91=9C?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/business/MatchingBusiness.java | 2 +- .../business/model/CandidateGroup.java | 2 +- .../business/model/LanguageQueue.java | 27 +++++++++++++------ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index d2519872..6e747efd 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -31,7 +31,7 @@ public List getParticipants() { private void initialize(final List matchingApplications) { participantGroup = ParticipantGroup.from(matchingApplications, matchingRuleProperties); - languageQueue = LanguageQueue.from(participantGroup); + languageQueue = LanguageQueue.classifyByLanguage(participantGroup); matchingTypeGroup = MatchingTypeGroup.init(matchingRuleProperties); } } diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java index f737c93a..ebd8a310 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java @@ -10,7 +10,7 @@ public CandidateGroup(final Queue candidateQueue) { this.candidateQueue = candidateQueue; } - public static CandidateGroup init() { + public static CandidateGroup initWithEmpty() { return new CandidateGroup(new LinkedList<>()); } diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java b/src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java index da367bf2..07ae38af 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java @@ -1,7 +1,7 @@ package com.aliens.backend.mathcing.business.model; -import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; public class LanguageQueue { @@ -11,20 +11,31 @@ private LanguageQueue(final Map languageQueue) { this.languageQueue = languageQueue; } - public static LanguageQueue from(final ParticipantGroup participantGroup) { + public static LanguageQueue classifyByLanguage(final ParticipantGroup participantGroup) { + Map languageQueue = createEmptyLanguageQueues(); + classifyParticipantsByLanguage(languageQueue, participantGroup); + + return new LanguageQueue(languageQueue); + } + + public CandidateGroup get(final Language language) { + return languageQueue.get(language); + } + + private static Map createEmptyLanguageQueues() { Map languageQueue = new HashMap<>(); - Arrays.stream(Language.values()).forEach(language -> languageQueue.put(language, CandidateGroup.init())); + List languages = List.of(Language.values()); + languages.forEach(language -> languageQueue.put(language, CandidateGroup.initWithEmpty())); + return languageQueue; + } + private static void classifyParticipantsByLanguage(final Map languageQueue, + final ParticipantGroup participantGroup) { participantGroup.getParticipants() .forEach(participant -> { Language language = participant.getPreferLanguage(MatchingMode.FIRST_PREFER_LANGUAGE); CandidateGroup candidateGroup = languageQueue.get(language); candidateGroup.add(participant); }); - return new LanguageQueue(languageQueue); - } - - public CandidateGroup get(Language language) { - return languageQueue.get(language); } } From a25390581929bc3b6ad5cc95adea854bd9e9152e Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 14:12:24 +0900 Subject: [PATCH 19/46] =?UTF-8?q?refactor=20:=20ParticipantGroup=EC=97=90?= =?UTF-8?q?=20=ED=8A=B9=EC=A0=95=20=EC=96=B8=EC=96=B4=EB=A5=BC=20=EA=B0=80?= =?UTF-8?q?=EC=A7=84=20=EC=B0=B8=EA=B0=80=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=ED=95=98=EC=97=AC,=20=EC=9D=B4=EB=A5=BC=20LanguageQueue?= =?UTF-8?q?=EA=B0=80=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=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 --- .../mathcing/business/model/CandidateGroup.java | 5 +++++ .../mathcing/business/model/LanguageQueue.java | 11 +++++------ .../mathcing/business/model/ParticipantGroup.java | 4 ++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java index ebd8a310..3e43eeb5 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java @@ -1,6 +1,7 @@ package com.aliens.backend.mathcing.business.model; import java.util.LinkedList; +import java.util.List; import java.util.Queue; public class CandidateGroup { @@ -22,6 +23,10 @@ public void add(Participant participant) { candidateQueue.add(participant); } + public void addAll(List participants) { + candidateQueue.addAll(participants); + } + public Participant poll() { return candidateQueue.poll(); } diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java b/src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java index 07ae38af..0b5dd082 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java @@ -31,11 +31,10 @@ private static Map createEmptyLanguageQueues() { private static void classifyParticipantsByLanguage(final Map languageQueue, final ParticipantGroup participantGroup) { - participantGroup.getParticipants() - .forEach(participant -> { - Language language = participant.getPreferLanguage(MatchingMode.FIRST_PREFER_LANGUAGE); - CandidateGroup candidateGroup = languageQueue.get(language); - candidateGroup.add(participant); - }); + for (Language language : Language.values()) { + List participants = participantGroup.getParticipantsByLanguage(language); + CandidateGroup candidateGroup = languageQueue.get(language); + candidateGroup.addAll(participants); + } } } diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java index 8ae57789..e1f116c7 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java @@ -48,6 +48,10 @@ public ParticipantGroup getParticipantsLessThan(final int numberOfPartner) { .collect(Collectors.toList())); } + public List getParticipantsByLanguage(Language language) { + return participants.stream().filter(participant -> participant.firstPreferLanguage().equals(language)).toList(); + } + public List getParticipants() { return participants; } From 365f52666e1bc212a7a63bc23547d90ca34cd646 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 14:33:37 +0900 Subject: [PATCH 20/46] =?UTF-8?q?refactor=20:=20=EB=B3=80=EC=88=98=20?= =?UTF-8?q?=EC=9D=B8=EB=9D=BC=EC=9D=B8=ED=99=94=20=EB=A6=AC=ED=84=B4=20?= =?UTF-8?q?=EC=A7=80=EC=96=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/mathcing/business/model/ParticipantGroup.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java index e1f116c7..a29c4281 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java @@ -43,9 +43,10 @@ public void updateToSpecialRelationshipMode() { } public ParticipantGroup getParticipantsLessThan(final int numberOfPartner) { - return toGroup(participants.stream() - .filter(participant -> participant.getNumberOfPartners() < numberOfPartner) - .collect(Collectors.toList())); + List filteredParticipants = participants.stream() + .filter(participant -> participant.getNumberOfPartners() < numberOfPartner).toList()); + ParticipantGroup participantGroup = toGroup(filteredParticipants); + return participantGroup; } public List getParticipantsByLanguage(Language language) { From f143dbc55bbcba5d0d4bc0e42b2796a25e891953 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 14:35:47 +0900 Subject: [PATCH 21/46] =?UTF-8?q?fix=20:=20;=20=EC=98=A4=ED=83=88=EC=9E=90?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/mathcing/business/model/ParticipantGroup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java index a29c4281..bf9b2295 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java @@ -44,7 +44,7 @@ public void updateToSpecialRelationshipMode() { public ParticipantGroup getParticipantsLessThan(final int numberOfPartner) { List filteredParticipants = participants.stream() - .filter(participant -> participant.getNumberOfPartners() < numberOfPartner).toList()); + .filter(participant -> participant.getNumberOfPartners() < numberOfPartner).toList(); ParticipantGroup participantGroup = toGroup(filteredParticipants); return participantGroup; } From 7a3c478a6e9b83115480fe43a2b3f2c2c5040e4a Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 14:37:28 +0900 Subject: [PATCH 22/46] =?UTF-8?q?refactor=20:=20operateMatching=20?= =?UTF-8?q?=EC=9D=B4=ED=9B=84=20=EA=B2=B0=EA=B3=BC=EB=A5=BC=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=80=EB=A1=9C,=20getMatchedParticipants=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/mathcing/business/MatchingBusiness.java | 2 +- .../com/aliens/backend/mathcing/service/MatchingService.java | 2 +- .../backend/matching/unit/business/MatchingBusinessTest.java | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index 6e747efd..7ec188da 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -25,7 +25,7 @@ public void operateMatching(List matchingApplications) { matchingTypeGroup.matchParticipants(participantGroup, languageQueue); } - public List getParticipants() { + public List getMatchedParticipants() { return participantGroup.getParticipants(); } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java index 5f5362cb..247ea122 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java @@ -45,7 +45,7 @@ public void operateMatching() { List matchingApplications = getMatchingApplications(currentRound); matchingBusiness.operateMatching(matchingApplications); - List matchedParticipants = matchingBusiness.getParticipants(); + List matchedParticipants = matchingBusiness.getMatchedParticipants(); saveMatchingResult(currentRound, matchedParticipants); } diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java index b3c09ad5..ca9e1428 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -21,7 +21,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; import java.util.List; @@ -56,7 +55,7 @@ void matchingLogicTest() { dummyGenerator.generateAppliersToMatch(15L); matchingBusiness.operateMatching(matchingApplicationRepository.findAllByMatchingRound(currentRound)); - List result = matchingBusiness.getParticipants(); + List result = matchingBusiness.getMatchedParticipants(); result.forEach(participant -> assertThat(participant.partners()).isNotNull()); } From cafb567033eaf5afc0a67e40c736a7a31c597c27 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 14:39:23 +0900 Subject: [PATCH 23/46] =?UTF-8?q?refactor=20:=20=EB=A7=A4=EC=B9=AD?= =?UTF-8?q?=EC=9D=B4=20=EC=95=84=EC=A7=81=20=EB=8D=9C=20=EB=90=9C=20?= =?UTF-8?q?=EC=B0=B8=EA=B0=80=EC=9E=90=EB=93=A4=20=EC=9D=B4=EB=AF=80?= =?UTF-8?q?=EB=A1=9C,=20remainedParticipants=EB=A1=9C=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/mathcing/business/type/RandomType.java | 6 +++--- .../mathcing/business/type/SecondPreferLanguageType.java | 4 ++-- .../aliens/backend/mathcing/business/type/SpecialType.java | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/type/RandomType.java b/src/main/java/com/aliens/backend/mathcing/business/type/RandomType.java index 05a8a963..9ef79667 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/type/RandomType.java +++ b/src/main/java/com/aliens/backend/mathcing/business/type/RandomType.java @@ -14,8 +14,8 @@ public RandomType(final MatchingRuleProperties matchingRuleProperties) { @Override public void doMatch(final ParticipantGroup participantGroup, final LanguageQueue languageQueue) { - ParticipantGroup participants = participantGroup.getParticipantsLessThan(matchingRuleProperties.getMaxNormalPartners()); - participants.updateToSpecialRelationshipMode(); - participants.matchAllWith(CandidateGroup.of(participants)); + ParticipantGroup remainedParticipants = participantGroup.getParticipantsLessThan(matchingRuleProperties.getMaxNormalPartners()); + remainedParticipants.updateToSpecialRelationshipMode(); + remainedParticipants.matchAllWith(CandidateGroup.of(remainedParticipants)); } } diff --git a/src/main/java/com/aliens/backend/mathcing/business/type/SecondPreferLanguageType.java b/src/main/java/com/aliens/backend/mathcing/business/type/SecondPreferLanguageType.java index 03952afe..4cc738ee 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/type/SecondPreferLanguageType.java +++ b/src/main/java/com/aliens/backend/mathcing/business/type/SecondPreferLanguageType.java @@ -14,7 +14,7 @@ public SecondPreferLanguageType(final MatchingRuleProperties matchingRulePropert @Override public void doMatch(final ParticipantGroup participantGroup, final LanguageQueue languageQueue) { - ParticipantGroup participants = participantGroup.getParticipantsLessThan(matchingRuleProperties.getMaxNormalPartners()); - participants.matchEachWith(languageQueue, MatchingMode.SECOND_PREFER_LANGUAGE); + ParticipantGroup remainedParticipants = participantGroup.getParticipantsLessThan(matchingRuleProperties.getMaxNormalPartners()); + remainedParticipants.matchEachWith(languageQueue, MatchingMode.SECOND_PREFER_LANGUAGE); } } diff --git a/src/main/java/com/aliens/backend/mathcing/business/type/SpecialType.java b/src/main/java/com/aliens/backend/mathcing/business/type/SpecialType.java index 59a8967f..81b1be03 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/type/SpecialType.java +++ b/src/main/java/com/aliens/backend/mathcing/business/type/SpecialType.java @@ -14,8 +14,8 @@ public SpecialType(final MatchingRuleProperties matchingRuleProperties) { @Override public void doMatch(final ParticipantGroup participantGroup, final LanguageQueue languageQueue) { - ParticipantGroup participants = participantGroup.getParticipantsLessThan(matchingRuleProperties.getMaxPartners()); - participants.updateToSpecialRelationshipMode(); - participants.matchAllWith(CandidateGroup.of(participants)); + ParticipantGroup remainedParticipants = participantGroup.getParticipantsLessThan(matchingRuleProperties.getMaxPartners()); + remainedParticipants.updateToSpecialRelationshipMode(); + remainedParticipants.matchAllWith(CandidateGroup.of(remainedParticipants)); } } From a3bc46d3d8d83a86cbd4a2fa4f1bd223c5ea7ba2 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 14:40:40 +0900 Subject: [PATCH 24/46] =?UTF-8?q?refactor=20:=20=EC=A7=81=EA=B4=80?= =?UTF-8?q?=EC=A0=81=EC=9C=BC=EB=A1=9C=20=EC=98=88=EC=99=B8=EB=A5=BC=20?= =?UTF-8?q?=EB=8D=98=EC=A7=80=EB=8F=84=EB=A1=9D=20=EA=B0=80=EB=8F=85?= =?UTF-8?q?=EC=84=B1=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/mathcing/util/validator/LanguageValidator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java b/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java index febdbe0e..3533ea8a 100644 --- a/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java +++ b/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java @@ -15,10 +15,10 @@ public boolean isValid(final MatchingApplicationRequest value, final ConstraintV Language firstPreferLanguage = value.firstPreferLanguage(); Language secondPreferLanguage = value.secondPreferLanguage(); - if (!firstPreferLanguage.equals(secondPreferLanguage)) { - return true; + if (firstPreferLanguage.equals(secondPreferLanguage)) { + throw new RestApiException(MatchingError.INVALID_LANGUAGE_INPUT); } - throw new RestApiException(MatchingError.INVALID_LANGUAGE_INPUT); + return true; } @Override From fb9442c829dd7349142d731b9d22d2ee7ffbf966 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 14:42:06 +0900 Subject: [PATCH 25/46] =?UTF-8?q?refactor=20:=20LanguageCheck=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{mathcing/util => global}/validator/LanguageCheck.java | 3 ++- .../aliens/backend/mathcing/controller/MatchingController.java | 2 +- .../backend/mathcing/util/validator/LanguageValidator.java | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) rename src/main/java/com/aliens/backend/{mathcing/util => global}/validator/LanguageCheck.java (83%) diff --git a/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageCheck.java b/src/main/java/com/aliens/backend/global/validator/LanguageCheck.java similarity index 83% rename from src/main/java/com/aliens/backend/mathcing/util/validator/LanguageCheck.java rename to src/main/java/com/aliens/backend/global/validator/LanguageCheck.java index 93f6a3dd..2aaa0276 100644 --- a/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageCheck.java +++ b/src/main/java/com/aliens/backend/global/validator/LanguageCheck.java @@ -1,5 +1,6 @@ -package com.aliens.backend.mathcing.util.validator; +package com.aliens.backend.global.validator; +import com.aliens.backend.mathcing.util.validator.LanguageValidator; import jakarta.validation.Constraint; import jakarta.validation.Payload; diff --git a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java index 0726dd58..4ba4c1cf 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java @@ -9,7 +9,7 @@ import com.aliens.backend.mathcing.controller.dto.response.MatchingResultResponse; import com.aliens.backend.mathcing.service.MatchingApplicationService; import com.aliens.backend.mathcing.service.MatchingService; -import com.aliens.backend.mathcing.util.validator.LanguageCheck; +import com.aliens.backend.global.validator.LanguageCheck; import org.springframework.web.bind.annotation.*; import java.util.List; diff --git a/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java b/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java index 3533ea8a..993c20cf 100644 --- a/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java +++ b/src/main/java/com/aliens/backend/mathcing/util/validator/LanguageValidator.java @@ -3,6 +3,7 @@ import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.response.error.MatchingError; +import com.aliens.backend.global.validator.LanguageCheck; import com.aliens.backend.mathcing.controller.dto.request.MatchingApplicationRequest; import com.aliens.backend.mathcing.business.model.Language; import jakarta.validation.ConstraintValidator; From a3f4492058c202781a5bce78ac8ff275d74ab507 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 14:42:40 +0900 Subject: [PATCH 26/46] =?UTF-8?q?refactor=20:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20CurrentRound=20?= =?UTF-8?q?=EC=A0=84=EC=97=AD=EB=B3=80=EC=88=98=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/mathcing/service/MatchingService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java index 247ea122..54b3dd9b 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java @@ -26,8 +26,6 @@ public class MatchingService { private final MatchingResultRepository matchingResultRepository; private final MatchingBusiness matchingBusiness; - private MatchingRound currentRound; - public MatchingService(final MatchingRoundRepository matchingRoundRepository, final MatchingApplicationRepository matchingApplicationRepository, final MatchingResultRepository matchingResultRepository, From d56c87a7ba31eb0bda8f85b7adff95522282b53f Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 14:49:06 +0900 Subject: [PATCH 27/46] =?UTF-8?q?refactor=20:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20toParticipants=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=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 --- .../aliens/backend/mathcing/domain/MatchingApplication.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java index cde8f2e0..eec9a9f6 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingApplication.java @@ -58,12 +58,6 @@ public static MatchingApplication from(final MatchingRound matchingRound, matchingApplicationRequest.secondPreferLanguage()); } - public static List toParticipantList(final List matchingApplications) { - return matchingApplications.stream() - .map(Participant::of) - .collect(Collectors.toList()); - } - public Long getMemberId() { return id.getMemberId(); } From 51912670473891da256449fd463b63332ab3e377 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 15:18:38 +0900 Subject: [PATCH 28/46] =?UTF-8?q?refactor=20:=20=EA=B8=B0=EC=A1=B4=20Match?= =?UTF-8?q?ingService=EB=A5=BC=20MatchingProcessService=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=ED=9B=84,=20ApplicationContoller=EC=99=80=20Proces?= =?UTF-8?q?sController=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ava => MatchingApplicationController.java} | 21 +++------------ .../controller/MatchingProcessController.java | 27 +++++++++++++++++++ ...rvice.java => MatchingProcessService.java} | 10 +++---- .../unit/business/MatchingBusinessTest.java | 7 ++--- ...t.java => MatchingProcessServiceTest.java} | 9 ++++--- 5 files changed, 45 insertions(+), 29 deletions(-) rename src/main/java/com/aliens/backend/mathcing/controller/{MatchingController.java => MatchingApplicationController.java} (71%) create mode 100644 src/main/java/com/aliens/backend/mathcing/controller/MatchingProcessController.java rename src/main/java/com/aliens/backend/mathcing/service/{MatchingService.java => MatchingProcessService.java} (90%) rename src/test/java/com/aliens/backend/matching/unit/service/{MatchingServiceTest.java => MatchingProcessServiceTest.java} (86%) diff --git a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java b/src/main/java/com/aliens/backend/mathcing/controller/MatchingApplicationController.java similarity index 71% rename from src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java rename to src/main/java/com/aliens/backend/mathcing/controller/MatchingApplicationController.java index 4ba4c1cf..eef63ac7 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/MatchingController.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/MatchingApplicationController.java @@ -2,28 +2,21 @@ import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.global.config.resolver.Login; -import com.aliens.backend.global.response.success.MatchingSuccess; import com.aliens.backend.global.response.SuccessResponse; +import com.aliens.backend.global.response.success.MatchingSuccess; +import com.aliens.backend.global.validator.LanguageCheck; import com.aliens.backend.mathcing.controller.dto.request.MatchingApplicationRequest; import com.aliens.backend.mathcing.controller.dto.response.MatchingApplicationResponse; -import com.aliens.backend.mathcing.controller.dto.response.MatchingResultResponse; import com.aliens.backend.mathcing.service.MatchingApplicationService; -import com.aliens.backend.mathcing.service.MatchingService; -import com.aliens.backend.global.validator.LanguageCheck; import org.springframework.web.bind.annotation.*; -import java.util.List; - @RestController @RequestMapping("/matchings") -public class MatchingController { +public class MatchingApplicationController { private final MatchingApplicationService matchingApplicationService; - private final MatchingService matchingService; - public MatchingController(final MatchingApplicationService matchingApplicationService, - final MatchingService matchingService) { + public MatchingApplicationController(final MatchingApplicationService matchingApplicationService) { this.matchingApplicationService = matchingApplicationService; - this.matchingService = matchingService; } @PostMapping("/applications") @@ -44,10 +37,4 @@ public SuccessResponse cancelMatchingApplication(final @Login LoginMembe return SuccessResponse.of(MatchingSuccess.CANCEL_MATCHING_APPLICATION_SUCCESS, matchingApplicationService.cancelMatchingApplication(loginMember)); } - - @GetMapping("/partners") - public SuccessResponse> getMatchingPartners(final @Login LoginMember loginMember) { - return SuccessResponse.of(MatchingSuccess.GET_MATCHING_PARTNERS_SUCCESS, - matchingService.findMatchingResult(loginMember)); - } } diff --git a/src/main/java/com/aliens/backend/mathcing/controller/MatchingProcessController.java b/src/main/java/com/aliens/backend/mathcing/controller/MatchingProcessController.java new file mode 100644 index 00000000..2772a5f5 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/controller/MatchingProcessController.java @@ -0,0 +1,27 @@ +package com.aliens.backend.mathcing.controller; + +import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.global.config.resolver.Login; +import com.aliens.backend.global.response.success.MatchingSuccess; +import com.aliens.backend.global.response.SuccessResponse; +import com.aliens.backend.mathcing.controller.dto.response.MatchingResultResponse; +import com.aliens.backend.mathcing.service.MatchingProcessService; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/matchings") +public class MatchingProcessController { + private final MatchingProcessService matchingProcessService; + + public MatchingProcessController(final MatchingProcessService matchingProcessService) { + this.matchingProcessService = matchingProcessService; + } + + @GetMapping("/partners") + public SuccessResponse> getMatchingPartners(final @Login LoginMember loginMember) { + return SuccessResponse.of(MatchingSuccess.GET_MATCHING_PARTNERS_SUCCESS, + matchingProcessService.findMatchingResult(loginMember)); + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingProcessService.java similarity index 90% rename from src/main/java/com/aliens/backend/mathcing/service/MatchingService.java rename to src/main/java/com/aliens/backend/mathcing/service/MatchingProcessService.java index 54b3dd9b..7611fc96 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingProcessService.java @@ -20,16 +20,16 @@ import java.util.List; @Service -public class MatchingService { +public class MatchingProcessService { private final MatchingRoundRepository matchingRoundRepository; private final MatchingApplicationRepository matchingApplicationRepository; private final MatchingResultRepository matchingResultRepository; private final MatchingBusiness matchingBusiness; - public MatchingService(final MatchingRoundRepository matchingRoundRepository, - final MatchingApplicationRepository matchingApplicationRepository, - final MatchingResultRepository matchingResultRepository, - final MatchingBusiness matchingBusiness) { + public MatchingProcessService(final MatchingRoundRepository matchingRoundRepository, + final MatchingApplicationRepository matchingApplicationRepository, + final MatchingResultRepository matchingResultRepository, + final MatchingBusiness matchingBusiness) { this.matchingRoundRepository = matchingRoundRepository; this.matchingApplicationRepository = matchingApplicationRepository; this.matchingResultRepository = matchingResultRepository; diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java index ca9e1428..4dcb5665 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -13,7 +13,7 @@ import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; import com.aliens.backend.mathcing.domain.repository.MatchingResultRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; -import com.aliens.backend.mathcing.service.MatchingService; +import com.aliens.backend.mathcing.service.MatchingProcessService; import com.aliens.backend.mathcing.business.model.Participant; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -29,7 +29,8 @@ @SpringBootTest class MatchingBusinessTest extends BaseServiceTest { - @Autowired MatchingService matchingService; + @Autowired + MatchingProcessService matchingProcessService; @Autowired MatchingApplicationRepository matchingApplicationRepository; @Autowired MatchingRoundRepository matchingRoundRepository; @Autowired MatchingResultRepository matchingResultRepository; @@ -68,7 +69,7 @@ void operateMatchingTest() { dummyGenerator.generateAppliersToMatch(20L); // when - matchingService.operateMatching(); + matchingProcessService.operateMatching(); // then List result = matchingResultRepository.findAllByMatchingRound(currentRound); diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java similarity index 86% rename from src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java rename to src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java index 618efee4..7983c453 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java @@ -8,7 +8,7 @@ import com.aliens.backend.global.property.MatchingTimeProperties; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; -import com.aliens.backend.mathcing.service.MatchingService; +import com.aliens.backend.mathcing.service.MatchingProcessService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -20,9 +20,10 @@ import static org.assertj.core.api.Assertions.*; @SpringBootTest -class MatchingServiceTest extends BaseServiceTest { +class MatchingProcessServiceTest extends BaseServiceTest { - @Autowired MatchingService matchingService; + @Autowired + MatchingProcessService matchingProcessService; @Autowired MatchingRoundRepository matchingRoundRepository; @Autowired MatchingTimeProperties matchingTimeProperties; @@ -40,7 +41,7 @@ void setUp() { @Test @DisplayName("매칭을 신청한 적이 없는 회원이 매칭 조회") void getMatchingResultTest() { - assertThatThrownBy(() -> matchingService.findMatchingResult(loginMember)) + assertThatThrownBy(() -> matchingProcessService.findMatchingResult(loginMember)) .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getDevelopCode()); } From 1f5a91f2ad10b486471f858760890c30703d3844 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 15:19:47 +0900 Subject: [PATCH 29/46] =?UTF-8?q?refactor=20:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20createQueueWith=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=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 --- .../backend/mathcing/business/model/Language.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/Language.java b/src/main/java/com/aliens/backend/mathcing/business/model/Language.java index da6b08f4..5e35718f 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/Language.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/Language.java @@ -1,24 +1,9 @@ package com.aliens.backend.mathcing.business.model; -import java.util.*; - public enum Language { KOREAN, ENGLISH, JAPANESE, CHINESE ; - - public static Map> createQueueWith(final List participants) { - Map> languageQueue = new HashMap<>(); - for (Language language : values()) { - languageQueue.put(language, new LinkedList<>()); - } - - for (Participant participant : participants) { - languageQueue.get(participant.getPreferLanguage(MatchingMode.FIRST_PREFER_LANGUAGE)).add(participant); - } - - return languageQueue; - } } From 38c40e07e97627dd24c57d8a52df1b343aa44fa1 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 15:23:22 +0900 Subject: [PATCH 30/46] =?UTF-8?q?refactor=20:=20LanguageQueue.get=EC=9D=84?= =?UTF-8?q?,=20=EC=96=B4=EB=96=A4=20=EA=B2=83=EC=9D=84=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EB=8A=94=EC=A7=80=20=EB=AA=85=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/mathcing/business/model/LanguageQueue.java | 2 +- .../backend/mathcing/business/model/ParticipantGroup.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java b/src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java index 0b5dd082..b02af574 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/LanguageQueue.java @@ -18,7 +18,7 @@ public static LanguageQueue classifyByLanguage(final ParticipantGroup participan return new LanguageQueue(languageQueue); } - public CandidateGroup get(final Language language) { + public CandidateGroup getCandidateGroupByLanguage(final Language language) { return languageQueue.get(language); } diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java index bf9b2295..3fd96cca 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java @@ -33,7 +33,7 @@ public void matchAllWith(CandidateGroup candidateGroup) { public void matchEachWith(LanguageQueue languageQueue, MatchingMode matchingMode) { for (Participant participant : participants) { Language preferLanguage = participant.getPreferLanguage(matchingMode); - CandidateGroup candidateGroup = languageQueue.get(preferLanguage); + CandidateGroup candidateGroup = languageQueue.getCandidateGroupByLanguage(preferLanguage); tryMatchBetween(participant, candidateGroup); } } From 8e57ad4b46f1c0174ba807d692e3d1ae4d087990 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 16:19:10 +0900 Subject: [PATCH 31/46] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=20=EC=A0=95=EB=B3=B4,=20=EC=9D=B4=EC=A0=84=20?= =?UTF-8?q?=EB=A7=A4=EC=B9=AD=20=EA=B2=B0=EA=B3=BC=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=A5=BC=20=EB=AC=B6=EB=8A=94=20MatchingOperateReques?= =?UTF-8?q?t=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/MatchingOperateRequest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingOperateRequest.java diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingOperateRequest.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingOperateRequest.java new file mode 100644 index 00000000..a370b738 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingOperateRequest.java @@ -0,0 +1,17 @@ +package com.aliens.backend.mathcing.controller.dto.request; + +import com.aliens.backend.mathcing.domain.MatchingApplication; +import com.aliens.backend.mathcing.domain.MatchingResult; + +import java.util.List; + +public record MatchingOperateRequest( + List matchingApplications, + List previousMatchingResults + // TODO : 차단 유저 리스트 +) { + public static MatchingOperateRequest of(List matchingApplications, + List previousMatchingResults) { + return new MatchingOperateRequest(matchingApplications, previousMatchingResults); + } +} \ No newline at end of file From e8d553c4ee0a91ecb0babf8774a022d5d489e98b Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 16:20:12 +0900 Subject: [PATCH 32/46] =?UTF-8?q?feat=20:=20=EC=B0=B8=EA=B0=80=EC=9E=90=20?= =?UTF-8?q?=EB=AA=A8=EB=8D=B8=EC=97=90=20=EC=9D=B4=EC=A0=84=20=ED=8C=8C?= =?UTF-8?q?=ED=8A=B8=EB=84=88=20=EB=AA=A9=EB=A1=9D=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/mathcing/business/model/Participant.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/Participant.java b/src/main/java/com/aliens/backend/mathcing/business/model/Participant.java index 9eb5be19..3f50dfd6 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/Participant.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/Participant.java @@ -6,12 +6,15 @@ import java.util.ArrayList; import java.util.List; +import java.util.Set; public record Participant( Long memberId, Language firstPreferLanguage, Language secondPreferLanguage, - List partners + List partners, + Set previousPartners + // TODO : Set blockedPartners ) { public Language getPreferLanguage(MatchingMode matchingMode) { if (matchingMode.equals(MatchingMode.FIRST_PREFER_LANGUAGE)) { @@ -23,12 +26,12 @@ public Language getPreferLanguage(MatchingMode matchingMode) { throw new RestApiException(MatchingError.NOT_FOUND_PREFER_LANGUAGE); } - public static Participant of(final MatchingApplication matchingApplication) { + public static Participant from(final MatchingApplication matchingApplication, final Set previousPartners) { return new Participant( matchingApplication.getMemberId(), matchingApplication.getFirstPreferLanguage(), matchingApplication.getSecondPreferLanguage(), - new ArrayList<>() + new ArrayList<>(), previousPartners ); } public int getNumberOfPartners() { From c7b12b9239e3a2a5a275155bb3cfe8c366d6d4ba Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 18:06:06 +0900 Subject: [PATCH 33/46] =?UTF-8?q?style(CandidateGroup)=20:=20public=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=EC=9E=90=20private=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aliens/backend/mathcing/business/model/CandidateGroup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java index 3e43eeb5..99f20a33 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/CandidateGroup.java @@ -7,7 +7,7 @@ public class CandidateGroup { private final Queue candidateQueue; - public CandidateGroup(final Queue candidateQueue) { + private CandidateGroup(final Queue candidateQueue) { this.candidateQueue = candidateQueue; } From a684dd5c836ace5fbbba714190f329040fb5b9dd Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 18:07:04 +0900 Subject: [PATCH 34/46] =?UTF-8?q?feat=20:=20=EB=A7=A4=EC=B9=AD=EC=97=90=20?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EB=A5=BC=20dto=EB=A1=9C=20=EC=A0=84=EB=8B=AC=ED=95=98=EB=8A=94?= =?UTF-8?q?=20=EA=B5=AC=EC=A1=B0=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mathcing/business/MatchingBusiness.java | 10 ++-- .../unit/business/MatchingBusinessTest.java | 51 ++++++++++++++----- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java index 7ec188da..9b266c79 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java +++ b/src/main/java/com/aliens/backend/mathcing/business/MatchingBusiness.java @@ -2,7 +2,7 @@ import com.aliens.backend.global.property.MatchingRuleProperties; import com.aliens.backend.mathcing.business.model.*; -import com.aliens.backend.mathcing.domain.MatchingApplication; +import com.aliens.backend.mathcing.controller.dto.request.MatchingOperateRequest; import org.springframework.stereotype.Component; import java.util.*; @@ -19,8 +19,8 @@ public MatchingBusiness(final MatchingRuleProperties matchingRuleProperties) { this.matchingRuleProperties = matchingRuleProperties; } - public void operateMatching(List matchingApplications) { - initialize(matchingApplications); + public void operateMatching(final MatchingOperateRequest matchingOperateRequest) { + initialize(matchingOperateRequest); matchingTypeGroup.matchParticipants(participantGroup, languageQueue); } @@ -29,8 +29,8 @@ public List getMatchedParticipants() { return participantGroup.getParticipants(); } - private void initialize(final List matchingApplications) { - participantGroup = ParticipantGroup.from(matchingApplications, matchingRuleProperties); + private void initialize(final MatchingOperateRequest matchingOperateRequest) { + participantGroup = ParticipantGroup.from(matchingOperateRequest, matchingRuleProperties); // TODO : 이전 매칭 기록, 차단 목록 주고 만들도록 시킴 languageQueue = LanguageQueue.classifyByLanguage(participantGroup); matchingTypeGroup = MatchingTypeGroup.init(matchingRuleProperties); } diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java index 4dcb5665..e6d7215f 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -8,6 +8,8 @@ import com.aliens.backend.matching.util.time.MockClock; import com.aliens.backend.matching.util.time.MockTime; import com.aliens.backend.mathcing.business.MatchingBusiness; +import com.aliens.backend.mathcing.controller.dto.request.MatchingOperateRequest; +import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingResult; import com.aliens.backend.mathcing.domain.MatchingRound; import com.aliens.backend.mathcing.domain.repository.MatchingApplicationRepository; @@ -15,7 +17,6 @@ import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.MatchingProcessService; import com.aliens.backend.mathcing.business.model.Participant; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -40,39 +41,65 @@ class MatchingBusinessTest extends BaseServiceTest { @Autowired MockClock mockClock; MatchingRound currentRound; + MatchingOperateRequest matchingOperateRequest; @BeforeEach void setUp() { LocalDateTime roundBeginTime = LocalDateTime.of(2024, 1, 29, 0, 0); matchingRoundRepository.save(MatchingRound.from(roundBeginTime, matchingTimeProperties)); - currentRound = matchingRoundRepository.findCurrentRound() - .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + currentRound = getCurrentRound(); } @Test @DisplayName("매칭 로직 실행 테스트") void matchingLogicTest() { mockClock.mockTime(MockTime.VALID_TIME); - dummyGenerator.generateAppliersToMatch(15L); + dummyGenerator.generateAppliersToMatch(20L); + matchingOperateRequest = createOperateRequest(currentRound); - matchingBusiness.operateMatching(matchingApplicationRepository.findAllByMatchingRound(currentRound)); - List result = matchingBusiness.getMatchedParticipants(); + matchingBusiness.operateMatching(matchingOperateRequest); + List result = matchingBusiness.getMatchedParticipants(); result.forEach(participant -> assertThat(participant.partners()).isNotNull()); } @Test - @DisplayName("매칭 결과 조회") - void operateMatchingTest() { - // given + @DisplayName("직전 회차에 매칭된 사용자와 매칭되지 않는 기능 테스트") + void isDuplicateMatchingTest() { mockClock.mockTime(MockTime.VALID_TIME); dummyGenerator.generateAppliersToMatch(20L); + matchingOperateRequest = createOperateRequest(currentRound); // when - matchingProcessService.operateMatching(); + matchingBusiness.operateMatching(matchingOperateRequest); // then - List result = matchingResultRepository.findAllByMatchingRound(currentRound); - Assertions.assertThat(result).isNotNull(); + + } + + private MatchingRound getCurrentRound() { + return matchingRoundRepository.findCurrentRound() + .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + } + + private List getMatchingApplications(MatchingRound matchingRound) { + return matchingApplicationRepository.findAllByMatchingRound(matchingRound); + } + + private MatchingRound getPreviousMatchingRound(MatchingRound matchingRound) { + Long previousRound = matchingRound.getRound() - 1; + return matchingRoundRepository.findMatchingRoundByRound(previousRound) + .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + } + + private List getPreviousMatchingResult(MatchingRound matchingRound) { + MatchingRound previousMatchingRound = getPreviousMatchingRound(matchingRound); + return matchingResultRepository.findAllByMatchingRound(previousMatchingRound); + } + + private MatchingOperateRequest createOperateRequest(MatchingRound matchingRound) { + List matchingApplications = getMatchingApplications(matchingRound); + List previousMatchingResult = getPreviousMatchingResult(matchingRound); + return MatchingOperateRequest.of(matchingApplications, previousMatchingResult); } } From de004c6435996f18ebb09bcdc340a165f610a334 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 18:11:41 +0900 Subject: [PATCH 35/46] =?UTF-8?q?feat=20:=20=EC=9D=B4=EC=A0=84=20=EB=A7=A4?= =?UTF-8?q?=EC=B9=AD=20=ED=9A=8C=EC=B0=A8=EB=A5=BC=20=EA=B0=80=EC=A0=B8?= =?UTF-8?q?=EC=98=A4=EB=8A=94=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 --- .../repository/MatchingRoundRepository.java | 2 ++ .../service/MatchingProcessService.java | 23 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingRoundRepository.java b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingRoundRepository.java index 9fd8f3b3..e2f57b47 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingRoundRepository.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/repository/MatchingRoundRepository.java @@ -11,4 +11,6 @@ public interface MatchingRoundRepository extends JpaRepository { @Query("SELECT mr FROM MatchingRound mr WHERE mr.round = (SELECT MAX(mr.round) FROM MatchingRound mr)") Optional findCurrentRound(); + + Optional findMatchingRoundByRound(Long round); } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingProcessService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingProcessService.java index 7611fc96..470e15e2 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingProcessService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingProcessService.java @@ -4,6 +4,7 @@ import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.mathcing.business.MatchingBusiness; +import com.aliens.backend.mathcing.controller.dto.request.MatchingOperateRequest; import com.aliens.backend.mathcing.controller.dto.response.MatchingResultResponse; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingResult; @@ -40,8 +41,9 @@ public MatchingProcessService(final MatchingRoundRepository matchingRoundReposit @Transactional public void operateMatching() { MatchingRound currentRound = getCurrentRound(); - List matchingApplications = getMatchingApplications(currentRound); - matchingBusiness.operateMatching(matchingApplications); + MatchingOperateRequest matchingOperateRequest = createOperateRequest(currentRound); + + matchingBusiness.operateMatching(matchingOperateRequest); List matchedParticipants = matchingBusiness.getMatchedParticipants(); saveMatchingResult(currentRound, matchedParticipants); @@ -84,4 +86,21 @@ private List getMatchingResult(final MatchingRound matchingRound private List getMatchingApplications(final MatchingRound matchingRound) { return matchingApplicationRepository.findAllByMatchingRound(matchingRound); } + + private MatchingRound getPreviousMatchingRound(MatchingRound matchingRound) { + Long previousRound = matchingRound.getPreviousRound(); + return matchingRoundRepository.findMatchingRoundByRound(previousRound) + .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); + } + + private List getPreviousMatchingResult(MatchingRound matchingRound) { + MatchingRound previousMatchingRound = getPreviousMatchingRound(matchingRound); + return matchingResultRepository.findAllByMatchingRound(previousMatchingRound); + } + + private MatchingOperateRequest createOperateRequest(MatchingRound matchingRound) { + List matchingApplications = getMatchingApplications(matchingRound); + List previousMatchingResult = getPreviousMatchingResult(matchingRound); + return MatchingOperateRequest.of(matchingApplications, previousMatchingResult); + } } From 7f5bc684fbe7c9d8c6e1e2f69999fc33c4d39969 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 18:13:01 +0900 Subject: [PATCH 36/46] =?UTF-8?q?fix=20:=20=EB=A7=A4=EC=B9=AD=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20MatchingProcessServiceTest?= =?UTF-8?q?=EB=A1=9C=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MatchingProcessServiceTest.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java index 7983c453..efbf27bf 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java @@ -3,12 +3,18 @@ import com.aliens.backend.auth.controller.dto.LoginMember; import com.aliens.backend.auth.domain.MemberRole; import com.aliens.backend.global.BaseServiceTest; +import com.aliens.backend.global.DummyGenerator; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; +import com.aliens.backend.matching.util.time.MockClock; +import com.aliens.backend.matching.util.time.MockTime; +import com.aliens.backend.mathcing.domain.MatchingResult; import com.aliens.backend.mathcing.domain.MatchingRound; +import com.aliens.backend.mathcing.domain.repository.MatchingResultRepository; import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.MatchingProcessService; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -16,16 +22,18 @@ import org.springframework.boot.test.context.SpringBootTest; import java.time.LocalDateTime; +import java.util.List; import static org.assertj.core.api.Assertions.*; @SpringBootTest class MatchingProcessServiceTest extends BaseServiceTest { - - @Autowired - MatchingProcessService matchingProcessService; + @Autowired MatchingProcessService matchingProcessService; @Autowired MatchingRoundRepository matchingRoundRepository; @Autowired MatchingTimeProperties matchingTimeProperties; + @Autowired MatchingResultRepository matchingResultRepository; + @Autowired MockClock mockClock; + @Autowired DummyGenerator dummyGenerator; MatchingRound currentRound; LoginMember loginMember; @@ -38,6 +46,21 @@ void setUp() { currentRound = getCurrentRound(); } + @Test + @DisplayName("매칭 결과 조회") + void operateMatchingTest() { + // given + mockClock.mockTime(MockTime.VALID_TIME); + dummyGenerator.generateAppliersToMatch(20L); + + // when + matchingProcessService.operateMatching(); + + // then + List result = matchingResultRepository.findAllByMatchingRound(currentRound); + Assertions.assertThat(result).isNotNull(); + } + @Test @DisplayName("매칭을 신청한 적이 없는 회원이 매칭 조회") void getMatchingResultTest() { From 36d13bf92b068e682d6ae17afb3076ee43e5ad39 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 18:13:52 +0900 Subject: [PATCH 37/46] =?UTF-8?q?feat=20:=20MatchingRound=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=EC=97=90=20=EC=9D=B4=EC=A0=84=20=ED=9A=8C?= =?UTF-8?q?=EC=B0=A8=EB=A5=BC=20=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aliens/backend/mathcing/domain/MatchingRound.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java index a301584a..b9fc2b82 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java @@ -76,6 +76,10 @@ public boolean isReceptionTime(LocalDateTime now) { return now.isAfter(this.getRequestStartTime()) && now.isBefore(this.getRequestEndTime()); } + public Long getPreviousRound() { + return round - 1; + } + @Override public String toString() { return "MatchingRound{" + From d266adcbf716fe99d16c53c38bc02027958bef41 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 19:10:26 +0900 Subject: [PATCH 38/46] =?UTF-8?q?feat=20:=20=EC=9D=B4=EC=A0=84=20=ED=9A=8C?= =?UTF-8?q?=EC=B0=A8=EC=97=90=20=EB=A7=A4=EC=B9=AD=EB=90=98=EC=97=88?= =?UTF-8?q?=EB=8D=98=20=ED=9A=8C=EC=9B=90=EA=B3=BC=EB=8A=94=20=EB=A7=A4?= =?UTF-8?q?=EC=B9=AD=20=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/model/MatchingResultGroup.java | 25 ++++++++++++++ .../mathcing/business/model/Participant.java | 17 +++++++--- .../business/model/ParticipantGroup.java | 33 ++++++++++++------- .../business/model/PreviousPartnerGroup.java | 23 +++++++++++++ .../dto/request/MatchingOperateRequest.java | 7 ++-- 5 files changed, 86 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/aliens/backend/mathcing/business/model/MatchingResultGroup.java create mode 100644 src/main/java/com/aliens/backend/mathcing/business/model/PreviousPartnerGroup.java diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/MatchingResultGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/MatchingResultGroup.java new file mode 100644 index 00000000..1892c3c9 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/model/MatchingResultGroup.java @@ -0,0 +1,25 @@ +package com.aliens.backend.mathcing.business.model; + +import com.aliens.backend.mathcing.domain.MatchingApplication; +import com.aliens.backend.mathcing.domain.MatchingResult; + +import java.util.List; + +public class MatchingResultGroup { + private final List matchingResults; + + private MatchingResultGroup(final List matchingResults) { + this.matchingResults = matchingResults; + } + + public static MatchingResultGroup of(List matchingResults) { + return new MatchingResultGroup(matchingResults); + } + + public List getMatchingResultsWith(MatchingApplication matchingApplication) { + List filteredMatchingResult = matchingResults.stream() + .filter(matchingResult -> matchingApplication.getMemberId().equals(matchingResult.getMatchedMemberId())) + .toList(); + return filteredMatchingResult; + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/Participant.java b/src/main/java/com/aliens/backend/mathcing/business/model/Participant.java index 3f50dfd6..79336ca8 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/Participant.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/Participant.java @@ -3,18 +3,18 @@ import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.mathcing.domain.MatchingApplication; +import com.aliens.backend.mathcing.domain.MatchingResult; import java.util.ArrayList; import java.util.List; -import java.util.Set; public record Participant( Long memberId, Language firstPreferLanguage, Language secondPreferLanguage, List partners, - Set previousPartners - // TODO : Set blockedPartners + PreviousPartnerGroup previousPartnerGroup + // TODO : List blockedPartners ) { public Language getPreferLanguage(MatchingMode matchingMode) { if (matchingMode.equals(MatchingMode.FIRST_PREFER_LANGUAGE)) { @@ -26,14 +26,17 @@ public Language getPreferLanguage(MatchingMode matchingMode) { throw new RestApiException(MatchingError.NOT_FOUND_PREFER_LANGUAGE); } - public static Participant from(final MatchingApplication matchingApplication, final Set previousPartners) { + public static Participant from(final MatchingApplication matchingApplication, + final List previousMatchingResults) { + PreviousPartnerGroup previousPartnerGroup = PreviousPartnerGroup.from(previousMatchingResults); return new Participant( matchingApplication.getMemberId(), matchingApplication.getFirstPreferLanguage(), matchingApplication.getSecondPreferLanguage(), - new ArrayList<>(), previousPartners + new ArrayList<>(), previousPartnerGroup ); } + public int getNumberOfPartners() { return partners.size(); } @@ -50,4 +53,8 @@ public boolean isPartnerWith(Participant participant) { } return false; } + + public boolean hasMetPreviousRound(Participant participant) { + return previousPartnerGroup.contains(participant); + } } diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java index 3fd96cca..a9a73270 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java @@ -1,10 +1,11 @@ package com.aliens.backend.mathcing.business.model; import com.aliens.backend.global.property.MatchingRuleProperties; +import com.aliens.backend.mathcing.controller.dto.request.MatchingOperateRequest; import com.aliens.backend.mathcing.domain.MatchingApplication; +import com.aliens.backend.mathcing.domain.MatchingResult; import java.util.List; -import java.util.stream.Collectors; public class ParticipantGroup { private final List participants; @@ -18,9 +19,16 @@ private ParticipantGroup(final List participants, this.relationship = Relationship.NORMAL; } - public static ParticipantGroup from(final List matchingApplications, + public static ParticipantGroup from(final MatchingOperateRequest matchingOperateRequest, final MatchingRuleProperties matchingRuleProperties) { - List participants = matchingApplications.stream().map(Participant::of).collect(Collectors.toList()); + List matchingApplications = matchingOperateRequest.matchingApplications(); + MatchingResultGroup previousMatchingResultGroup = matchingOperateRequest.previousMatchingResult(); + + List participants = matchingApplications.stream() + .map(matchingApplication -> { + List previousMatchingResults = previousMatchingResultGroup.getMatchingResultsWith(matchingApplication); + return Participant.from(matchingApplication, previousMatchingResults); + }).toList(); return new ParticipantGroup(participants, matchingRuleProperties); } @@ -45,8 +53,7 @@ public void updateToSpecialRelationshipMode() { public ParticipantGroup getParticipantsLessThan(final int numberOfPartner) { List filteredParticipants = participants.stream() .filter(participant -> participant.getNumberOfPartners() < numberOfPartner).toList(); - ParticipantGroup participantGroup = toGroup(filteredParticipants); - return participantGroup; + return new ParticipantGroup(filteredParticipants, matchingRuleProperties); } public List getParticipantsByLanguage(Language language) { @@ -89,8 +96,8 @@ private boolean isValidMatching(final Relationship relationship, final Participant participant, final Participant partner) { return participant != partner && - !participant.isPartnerWith(partner) && - !partner.isPartnerWith(participant) && + !hasMetBetween(participant, partner) && + !isPartnerBetween(participant, partner) && !isExceededMaxPartners(relationship, partner); } @@ -101,11 +108,15 @@ private boolean isExceededMaxPartners(final Relationship relationship, final Par return participant.getNumberOfPartners() >= matchingRuleProperties.getMaxPartners(); // 5 } - private boolean isExceedMaxTries(int tries) { - return tries > matchingRuleProperties.getMaxTries(); + private boolean hasMetBetween(final Participant participant, final Participant partner) { + return participant.hasMetPreviousRound(partner) || partner.hasMetPreviousRound(participant); } - private ParticipantGroup toGroup(List participants) { - return new ParticipantGroup(participants, matchingRuleProperties); + private boolean isPartnerBetween(final Participant participant, final Participant partner) { + return participant.isPartnerWith(partner) || partner.isPartnerWith(participant); + } + + private boolean isExceedMaxTries(int tries) { + return tries > matchingRuleProperties.getMaxTries(); } } diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/PreviousPartnerGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/PreviousPartnerGroup.java new file mode 100644 index 00000000..acd97fe2 --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/model/PreviousPartnerGroup.java @@ -0,0 +1,23 @@ +package com.aliens.backend.mathcing.business.model; + +import com.aliens.backend.mathcing.domain.MatchingResult; + +import java.util.List; + +public class PreviousPartnerGroup { + private final List previousPartners; + + private PreviousPartnerGroup(final List previousPartners) { + this.previousPartners = previousPartners; + } + + public static PreviousPartnerGroup from(final List previousMatchingResult) { + List previousPartners = previousMatchingResult.stream() + .mapToLong(MatchingResult::getMatchedMemberId).boxed().toList(); + return new PreviousPartnerGroup(previousPartners); + } + + public boolean contains(Participant participant) { + return previousPartners.contains(participant.memberId()); + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingOperateRequest.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingOperateRequest.java index a370b738..09c47096 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingOperateRequest.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingOperateRequest.java @@ -1,5 +1,6 @@ package com.aliens.backend.mathcing.controller.dto.request; +import com.aliens.backend.mathcing.business.model.MatchingResultGroup; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingResult; @@ -7,11 +8,11 @@ public record MatchingOperateRequest( List matchingApplications, - List previousMatchingResults + MatchingResultGroup previousMatchingResult // TODO : 차단 유저 리스트 ) { public static MatchingOperateRequest of(List matchingApplications, - List previousMatchingResults) { - return new MatchingOperateRequest(matchingApplications, previousMatchingResults); + List previousMatchingResult) { + return new MatchingOperateRequest(matchingApplications, MatchingResultGroup.of(previousMatchingResult)); } } \ No newline at end of file From 6bc29e26b78a190ca6520cba90c182e934f01b91 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 19:22:23 +0900 Subject: [PATCH 39/46] =?UTF-8?q?style=20:=20MockTime=20=EC=86=8D=EC=84=B1?= =?UTF-8?q?=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EA=B5=AC=EC=B2=B4=EC=A0=81?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unit/business/MatchingBusinessTest.java | 29 ++++++++++++------- .../MatchingApplicationServiceTest.java | 16 +++++----- .../service/MatchingProcessServiceTest.java | 2 +- .../backend/matching/util/time/MockTime.java | 4 +-- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java index e6d7215f..3991e3eb 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -30,8 +30,7 @@ @SpringBootTest class MatchingBusinessTest extends BaseServiceTest { - @Autowired - MatchingProcessService matchingProcessService; + @Autowired MatchingProcessService matchingProcessService; @Autowired MatchingApplicationRepository matchingApplicationRepository; @Autowired MatchingRoundRepository matchingRoundRepository; @Autowired MatchingResultRepository matchingResultRepository; @@ -53,7 +52,7 @@ void setUp() { @Test @DisplayName("매칭 로직 실행 테스트") void matchingLogicTest() { - mockClock.mockTime(MockTime.VALID_TIME); + mockClock.mockTime(MockTime.VALID_RECEPTION_TIME); dummyGenerator.generateAppliersToMatch(20L); matchingOperateRequest = createOperateRequest(currentRound); @@ -66,15 +65,11 @@ void matchingLogicTest() { @Test @DisplayName("직전 회차에 매칭된 사용자와 매칭되지 않는 기능 테스트") void isDuplicateMatchingTest() { - mockClock.mockTime(MockTime.VALID_TIME); - dummyGenerator.generateAppliersToMatch(20L); - matchingOperateRequest = createOperateRequest(currentRound); - - // when - matchingBusiness.operateMatching(matchingOperateRequest); + // given & when + operateMatchingTwice(); // then - + System.out.println(); } private MatchingRound getCurrentRound() { @@ -87,7 +82,7 @@ private List getMatchingApplications(MatchingRound matching } private MatchingRound getPreviousMatchingRound(MatchingRound matchingRound) { - Long previousRound = matchingRound.getRound() - 1; + Long previousRound = matchingRound.getPreviousRound(); return matchingRoundRepository.findMatchingRoundByRound(previousRound) .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); } @@ -102,4 +97,16 @@ private MatchingOperateRequest createOperateRequest(MatchingRound matchingRound) List previousMatchingResult = getPreviousMatchingResult(matchingRound); return MatchingOperateRequest.of(matchingApplications, previousMatchingResult); } + + private void operateMatchingTwice() { + mockClock.mockTime(MockTime.MONDAY); + dummyGenerator.generateAppliersToMatch(20L); + matchingOperateRequest = createOperateRequest(currentRound); + matchingBusiness.operateMatching(matchingOperateRequest); + + mockClock.mockTime(MockTime.THURSDAY); + dummyGenerator.generateAppliersToMatch(20L); + matchingOperateRequest = createOperateRequest(currentRound); + matchingBusiness.operateMatching(matchingOperateRequest); + } } diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index d1a8f71d..a93d77b0 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -24,8 +24,8 @@ import java.time.LocalDateTime; -import static com.aliens.backend.matching.util.time.MockTime.INVALID_TIME; -import static com.aliens.backend.matching.util.time.MockTime.VALID_TIME; +import static com.aliens.backend.matching.util.time.MockTime.INVALID_RECEPTION_TIME; +import static com.aliens.backend.matching.util.time.MockTime.VALID_RECEPTION_TIME; import static org.assertj.core.api.Assertions.*; @@ -53,7 +53,7 @@ void setUp() { @DisplayName("매칭 신청 단위 테스트") void applyMatchTest() { // given - mockClock.mockTime(VALID_TIME); + mockClock.mockTime(VALID_RECEPTION_TIME); Long expectedResult = loginMember.memberId(); // when @@ -68,7 +68,7 @@ void applyMatchTest() { @DisplayName("지정 시간 외 매칭 신청시, 에러 발생") void applyMatchIfNotValidTime() { // given - mockClock.mockTime(INVALID_TIME); + mockClock.mockTime(INVALID_RECEPTION_TIME); // when & then assertThatThrownBy(() -> matchingApplicationService.saveParticipant(loginMember, matchingApplicationRequest)) @@ -103,7 +103,7 @@ void getMatchingApplicationIfNotApplied() { void deleteMatchingApplicationTest() { // given applyToMatch(); - mockClock.mockTime(VALID_TIME); + mockClock.mockTime(VALID_RECEPTION_TIME); // when matchingApplicationService.cancelMatchingApplication(loginMember); @@ -118,7 +118,7 @@ void deleteMatchingApplicationTest() { void deleteMatchIfNotValidTime() { // given applyToMatch(); - mockClock.mockTime(INVALID_TIME); + mockClock.mockTime(INVALID_RECEPTION_TIME); // when & then assertThatThrownBy(() -> matchingApplicationService.cancelMatchingApplication(loginMember)) @@ -129,14 +129,14 @@ void deleteMatchIfNotValidTime() { @DisplayName("매칭을 신청하지 않은 사용자 매칭 삭제 요청 테스트") void deleteMatchIfNotApplied() { // given - mockClock.mockTime(VALID_TIME); + mockClock.mockTime(VALID_RECEPTION_TIME); assertThatThrownBy(() -> matchingApplicationService.cancelMatchingApplication(loginMember)) .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getDevelopCode()); } private void applyToMatch() { - mockClock.mockTime(VALID_TIME); + mockClock.mockTime(VALID_RECEPTION_TIME); matchingApplicationService.saveParticipant(loginMember, matchingApplicationRequest); } diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java index efbf27bf..1a0b521a 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java @@ -50,7 +50,7 @@ void setUp() { @DisplayName("매칭 결과 조회") void operateMatchingTest() { // given - mockClock.mockTime(MockTime.VALID_TIME); + mockClock.mockTime(MockTime.VALID_RECEPTION_TIME); dummyGenerator.generateAppliersToMatch(20L); // when diff --git a/src/test/java/com/aliens/backend/matching/util/time/MockTime.java b/src/test/java/com/aliens/backend/matching/util/time/MockTime.java index 7577263c..1622a690 100644 --- a/src/test/java/com/aliens/backend/matching/util/time/MockTime.java +++ b/src/test/java/com/aliens/backend/matching/util/time/MockTime.java @@ -3,8 +3,8 @@ import java.time.LocalDateTime; public enum MockTime { - INVALID_TIME(LocalDateTime.of(2024, 1, 29, 19, 0)), - VALID_TIME(LocalDateTime.of(2024, 1, 29, 10, 0)), + INVALID_RECEPTION_TIME(LocalDateTime.of(2024, 1, 29, 19, 0)), + VALID_RECEPTION_TIME(LocalDateTime.of(2024, 1, 29, 10, 0)), MONDAY(LocalDateTime.of(2024, 1, 29, 0, 0)), THURSDAY(LocalDateTime.of(2024, 2, 1, 0, 0)), From 53a558612f75534afd2932240c9ea917b8de596e Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 22:08:41 +0900 Subject: [PATCH 40/46] =?UTF-8?q?test=20:=20=EC=A7=81=EC=A0=84=20=ED=9A=8C?= =?UTF-8?q?=EC=B0=A8=EC=97=90=20=EB=A7=A4=EC=B9=AD=EB=90=9C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=EC=99=80=20=EB=A7=A4=EC=B9=AD=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/model/MatchingResultGroup.java | 2 +- .../business/model/PreviousPartnerGroup.java | 7 +++ .../mathcing/domain/MatchingRound.java | 4 ++ .../service/MatchingApplicationService.java | 1 - .../service/MatchingProcessService.java | 4 ++ .../unit/business/MatchingBusinessTest.java | 44 +++++-------- .../MatchingApplicationServiceTest.java | 24 +++---- .../service/MatchingProcessServiceTest.java | 62 ++++++++++++++++--- .../backend/matching/util/time/MockClock.java | 5 +- .../backend/matching/util/time/MockTime.java | 6 +- 10 files changed, 107 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/MatchingResultGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/MatchingResultGroup.java index 1892c3c9..59a23dad 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/MatchingResultGroup.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/MatchingResultGroup.java @@ -18,7 +18,7 @@ public static MatchingResultGroup of(List matchingResults) { public List getMatchingResultsWith(MatchingApplication matchingApplication) { List filteredMatchingResult = matchingResults.stream() - .filter(matchingResult -> matchingApplication.getMemberId().equals(matchingResult.getMatchedMemberId())) + .filter(matchingResult -> matchingApplication.getMemberId().equals(matchingResult.getMatchingMemberId())) .toList(); return filteredMatchingResult; } diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/PreviousPartnerGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/PreviousPartnerGroup.java index acd97fe2..304a8402 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/PreviousPartnerGroup.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/PreviousPartnerGroup.java @@ -20,4 +20,11 @@ public static PreviousPartnerGroup from(final List previousMatch public boolean contains(Participant participant) { return previousPartners.contains(participant.memberId()); } + + @Override + public String toString() { + return "PreviousPartnerGroup{" + + "previousPartners=" + previousPartners + + '}'; + } } diff --git a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java index b9fc2b82..ec42c63b 100644 --- a/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java +++ b/src/main/java/com/aliens/backend/mathcing/domain/MatchingRound.java @@ -76,6 +76,10 @@ public boolean isReceptionTime(LocalDateTime now) { return now.isAfter(this.getRequestStartTime()) && now.isBefore(this.getRequestEndTime()); } + public boolean isFirstRound() { + return round == 1; + } + public Long getPreviousRound() { return round - 1; } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java index 0207b619..77a4514d 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingApplicationService.java @@ -72,5 +72,4 @@ private void checkReceptionTime(MatchingRound matchingRound) { throw new RestApiException(MatchingError.NOT_VALID_MATCHING_RECEPTION_TIME); } } - } diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingProcessService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingProcessService.java index 470e15e2..0ff8c0c9 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingProcessService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingProcessService.java @@ -18,6 +18,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; @Service @@ -94,6 +95,9 @@ private MatchingRound getPreviousMatchingRound(MatchingRound matchingRound) { } private List getPreviousMatchingResult(MatchingRound matchingRound) { + if (matchingRound.isFirstRound()) { + return new ArrayList<>(); + } MatchingRound previousMatchingRound = getPreviousMatchingRound(matchingRound); return matchingResultRepository.findAllByMatchingRound(previousMatchingRound); } diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java index 3991e3eb..07559965 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -8,6 +8,7 @@ import com.aliens.backend.matching.util.time.MockClock; import com.aliens.backend.matching.util.time.MockTime; import com.aliens.backend.mathcing.business.MatchingBusiness; +import com.aliens.backend.mathcing.business.model.Partner; import com.aliens.backend.mathcing.controller.dto.request.MatchingOperateRequest; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingResult; @@ -17,16 +18,18 @@ import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.MatchingProcessService; import com.aliens.backend.mathcing.business.model.Participant; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.api.Assertions.*; @SpringBootTest class MatchingBusinessTest extends BaseServiceTest { @@ -39,39 +42,22 @@ class MatchingBusinessTest extends BaseServiceTest { @Autowired MatchingTimeProperties matchingTimeProperties; @Autowired MockClock mockClock; - MatchingRound currentRound; MatchingOperateRequest matchingOperateRequest; @BeforeEach void setUp() { - LocalDateTime roundBeginTime = LocalDateTime.of(2024, 1, 29, 0, 0); - matchingRoundRepository.save(MatchingRound.from(roundBeginTime, matchingTimeProperties)); - currentRound = getCurrentRound(); + saveMatchRound(MockTime.MONDAY); } @Test @DisplayName("매칭 로직 실행 테스트") void matchingLogicTest() { - mockClock.mockTime(MockTime.VALID_RECEPTION_TIME); - dummyGenerator.generateAppliersToMatch(20L); - matchingOperateRequest = createOperateRequest(currentRound); - - matchingBusiness.operateMatching(matchingOperateRequest); + operateMatching(MockTime.VALID_RECEPTION_TIME_ON_MONDAY); List result = matchingBusiness.getMatchedParticipants(); result.forEach(participant -> assertThat(participant.partners()).isNotNull()); } - @Test - @DisplayName("직전 회차에 매칭된 사용자와 매칭되지 않는 기능 테스트") - void isDuplicateMatchingTest() { - // given & when - operateMatchingTwice(); - - // then - System.out.println(); - } - private MatchingRound getCurrentRound() { return matchingRoundRepository.findCurrentRound() .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); @@ -88,6 +74,9 @@ private MatchingRound getPreviousMatchingRound(MatchingRound matchingRound) { } private List getPreviousMatchingResult(MatchingRound matchingRound) { + if (matchingRound.isFirstRound()) { + return new ArrayList<>(); + } MatchingRound previousMatchingRound = getPreviousMatchingRound(matchingRound); return matchingResultRepository.findAllByMatchingRound(previousMatchingRound); } @@ -98,15 +87,16 @@ private MatchingOperateRequest createOperateRequest(MatchingRound matchingRound) return MatchingOperateRequest.of(matchingApplications, previousMatchingResult); } - private void operateMatchingTwice() { - mockClock.mockTime(MockTime.MONDAY); - dummyGenerator.generateAppliersToMatch(20L); - matchingOperateRequest = createOperateRequest(currentRound); - matchingBusiness.operateMatching(matchingOperateRequest); + private void saveMatchRound(MockTime mockTime) { + mockClock.mockTime(mockTime); + MatchingRound matchingRound = MatchingRound.from(mockTime.getTime(), matchingTimeProperties); + matchingRoundRepository.save(matchingRound); + } - mockClock.mockTime(MockTime.THURSDAY); + private void operateMatching(MockTime mockTime) { + mockClock.mockTime(mockTime); dummyGenerator.generateAppliersToMatch(20L); - matchingOperateRequest = createOperateRequest(currentRound); + matchingOperateRequest = createOperateRequest(getCurrentRound()); matchingBusiness.operateMatching(matchingOperateRequest); } } diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java index a93d77b0..5e2faa7f 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingApplicationServiceTest.java @@ -7,6 +7,7 @@ import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; import com.aliens.backend.matching.util.time.MockClock; +import com.aliens.backend.matching.util.time.MockTime; import com.aliens.backend.mathcing.controller.dto.request.MatchingApplicationRequest; import com.aliens.backend.mathcing.controller.dto.response.MatchingApplicationResponse; import com.aliens.backend.mathcing.domain.MatchingApplication; @@ -25,7 +26,7 @@ import java.time.LocalDateTime; import static com.aliens.backend.matching.util.time.MockTime.INVALID_RECEPTION_TIME; -import static com.aliens.backend.matching.util.time.MockTime.VALID_RECEPTION_TIME; +import static com.aliens.backend.matching.util.time.MockTime.VALID_RECEPTION_TIME_ON_MONDAY; import static org.assertj.core.api.Assertions.*; @@ -39,21 +40,19 @@ class MatchingApplicationServiceTest extends BaseServiceTest { LoginMember loginMember; MatchingApplicationRequest matchingApplicationRequest; - MatchingRound currentRound; @BeforeEach void setUp() { - createNewMatchingRound(); + saveMatchRound(MockTime.MONDAY); loginMember = new LoginMember(1L, MemberRole.MEMBER); matchingApplicationRequest = new MatchingApplicationRequest(Language.KOREAN, Language.ENGLISH); - currentRound = getCurrentRound(); } @Test @DisplayName("매칭 신청 단위 테스트") void applyMatchTest() { // given - mockClock.mockTime(VALID_RECEPTION_TIME); + mockClock.mockTime(VALID_RECEPTION_TIME_ON_MONDAY); Long expectedResult = loginMember.memberId(); // when @@ -103,7 +102,7 @@ void getMatchingApplicationIfNotApplied() { void deleteMatchingApplicationTest() { // given applyToMatch(); - mockClock.mockTime(VALID_RECEPTION_TIME); + mockClock.mockTime(VALID_RECEPTION_TIME_ON_MONDAY); // when matchingApplicationService.cancelMatchingApplication(loginMember); @@ -129,20 +128,21 @@ void deleteMatchIfNotValidTime() { @DisplayName("매칭을 신청하지 않은 사용자 매칭 삭제 요청 테스트") void deleteMatchIfNotApplied() { // given - mockClock.mockTime(VALID_RECEPTION_TIME); + mockClock.mockTime(VALID_RECEPTION_TIME_ON_MONDAY); assertThatThrownBy(() -> matchingApplicationService.cancelMatchingApplication(loginMember)) .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getDevelopCode()); } private void applyToMatch() { - mockClock.mockTime(VALID_RECEPTION_TIME); + mockClock.mockTime(VALID_RECEPTION_TIME_ON_MONDAY); matchingApplicationService.saveParticipant(loginMember, matchingApplicationRequest); } - private void createNewMatchingRound() { - LocalDateTime roundBeginTime = LocalDateTime.of(2024, 1, 29, 0, 0); - matchingRoundRepository.save(MatchingRound.from(roundBeginTime, matchingTimeProperties)); + private void saveMatchRound(MockTime mockTime) { + mockClock.mockTime(mockTime); + MatchingRound matchingRound = MatchingRound.from(mockTime.getTime(), matchingTimeProperties); + matchingRoundRepository.save(matchingRound); } private MatchingRound getCurrentRound() { @@ -152,7 +152,7 @@ private MatchingRound getCurrentRound() { private MatchingApplication findMatchingApplication(LoginMember loginMember) { return matchingApplicationRepository - .findById(MatchingApplicationId.of(currentRound, loginMember.memberId())) + .findById(MatchingApplicationId.of(getCurrentRound(), loginMember.memberId())) .orElseThrow(() -> new RestApiException(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO)); } } diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java index 1a0b521a..d09a714f 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java @@ -21,10 +21,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import java.time.LocalDateTime; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; @SpringBootTest class MatchingProcessServiceTest extends BaseServiceTest { @@ -35,32 +37,60 @@ class MatchingProcessServiceTest extends BaseServiceTest { @Autowired MockClock mockClock; @Autowired DummyGenerator dummyGenerator; - MatchingRound currentRound; LoginMember loginMember; @BeforeEach void setUp() { loginMember = new LoginMember(1L, MemberRole.MEMBER); - LocalDateTime roundBeginTime = LocalDateTime.of(2024, 1, 29, 0, 0); - matchingRoundRepository.save(MatchingRound.from(roundBeginTime, matchingTimeProperties)); - currentRound = getCurrentRound(); + saveMatchRound(MockTime.MONDAY); } @Test @DisplayName("매칭 결과 조회") void operateMatchingTest() { // given - mockClock.mockTime(MockTime.VALID_RECEPTION_TIME); + mockClock.mockTime(MockTime.VALID_RECEPTION_TIME_ON_MONDAY); dummyGenerator.generateAppliersToMatch(20L); // when matchingProcessService.operateMatching(); // then - List result = matchingResultRepository.findAllByMatchingRound(currentRound); + List result = matchingResultRepository.findAllByMatchingRound(getCurrentRound()); Assertions.assertThat(result).isNotNull(); } + @Test + @DisplayName("연속 매칭 테스트") + void operateMatchingTwice() { + operateMatching(MockTime.VALID_RECEPTION_TIME_ON_MONDAY); + saveMatchRound(MockTime.THURSDAY); + operateMatching(MockTime.VALID_RECEPTION_TIME_ON_THURSDAY); + } + + @Test + @DisplayName("직전 회차에 매칭된 사용자와 매칭되지 않는 기능 테스트") + void isDuplicateMatchingTest() { + // given & when + operateMatching(MockTime.VALID_RECEPTION_TIME_ON_MONDAY); + List firstRoundResult = getMatchingResultByMatchingRound(getCurrentRound()); + saveMatchRound(MockTime.THURSDAY); + operateMatching(MockTime.VALID_RECEPTION_TIME_ON_THURSDAY); + List secondRoundResult = getMatchingResultByMatchingRound(getCurrentRound()); + + Map> matchedMembersInSecondRound = secondRoundResult.stream() + .collect(Collectors.groupingBy( + MatchingResult::getMatchingMemberId, + Collectors.mapping(MatchingResult::getMatchedMemberId, Collectors.toSet()) + )); + + // then + firstRoundResult.forEach(first -> { + Set matchedMemberIds = matchedMembersInSecondRound.get(first.getMatchingMemberId()); + assertThat(matchedMemberIds).doesNotContain(first.getMatchedMemberId()); + }); + } + @Test @DisplayName("매칭을 신청한 적이 없는 회원이 매칭 조회") void getMatchingResultTest() { @@ -72,4 +102,20 @@ private MatchingRound getCurrentRound() { return matchingRoundRepository.findCurrentRound() .orElseThrow(()-> new RestApiException(MatchingError.NOT_FOUND_MATCHING_ROUND)); } + + private void saveMatchRound(MockTime mockTime) { + mockClock.mockTime(mockTime); + MatchingRound matchingRound = MatchingRound.from(mockTime.getTime(), matchingTimeProperties); + matchingRoundRepository.save(matchingRound); + } + + private void operateMatching(MockTime mockTime) { + mockClock.mockTime(mockTime); + dummyGenerator.generateAppliersToMatch(20L); + matchingProcessService.operateMatching(); + } + + private List getMatchingResultByMatchingRound(MatchingRound matchingRound) { + return matchingResultRepository.findAllByMatchingRound(matchingRound); + } } diff --git a/src/test/java/com/aliens/backend/matching/util/time/MockClock.java b/src/test/java/com/aliens/backend/matching/util/time/MockClock.java index 3106e4ba..a5777828 100644 --- a/src/test/java/com/aliens/backend/matching/util/time/MockClock.java +++ b/src/test/java/com/aliens/backend/matching/util/time/MockClock.java @@ -1,5 +1,7 @@ package com.aliens.backend.matching.util.time; +import com.aliens.backend.mathcing.domain.MatchingRound; +import org.mockito.BDDMockito; import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.stereotype.Component; @@ -7,6 +9,7 @@ import java.time.LocalDateTime; import java.time.ZoneId; +import static org.mockito.BDDMockito.*; import static org.mockito.Mockito.when; @Component @@ -15,7 +18,7 @@ public class MockClock { private Clock clock; public void mockTime(MockTime mockTime) { - LocalDateTime time = mockTime.time; + LocalDateTime time = mockTime.getTime(); Clock fixedClock = Clock.fixed(time.atZone(ZoneId.systemDefault()).toInstant(), ZoneId.systemDefault()); when(clock.instant()).thenReturn(fixedClock.instant()); when(clock.getZone()).thenReturn(fixedClock.getZone()); diff --git a/src/test/java/com/aliens/backend/matching/util/time/MockTime.java b/src/test/java/com/aliens/backend/matching/util/time/MockTime.java index 1622a690..7afe35ed 100644 --- a/src/test/java/com/aliens/backend/matching/util/time/MockTime.java +++ b/src/test/java/com/aliens/backend/matching/util/time/MockTime.java @@ -4,13 +4,15 @@ public enum MockTime { INVALID_RECEPTION_TIME(LocalDateTime.of(2024, 1, 29, 19, 0)), - VALID_RECEPTION_TIME(LocalDateTime.of(2024, 1, 29, 10, 0)), + VALID_RECEPTION_TIME_ON_MONDAY(LocalDateTime.of(2024, 1, 29, 10, 0)), + VALID_RECEPTION_TIME_ON_THURSDAY(LocalDateTime.of(2024, 2, 1, 10, 0)), + MONDAY(LocalDateTime.of(2024, 1, 29, 0, 0)), THURSDAY(LocalDateTime.of(2024, 2, 1, 0, 0)), ; - public LocalDateTime time; + private final LocalDateTime time; MockTime(LocalDateTime time) { this.time = time; From e826ac63775b6ae100d456919dd3f5d0b70f2447 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 23:18:43 +0900 Subject: [PATCH 41/46] =?UTF-8?q?feat=20:=20=EC=B0=A8=EB=8B=A8=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/block/domain/repository/BlockRepository.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/aliens/backend/block/domain/repository/BlockRepository.java b/src/main/java/com/aliens/backend/block/domain/repository/BlockRepository.java index 92b85c4b..9297d22a 100644 --- a/src/main/java/com/aliens/backend/block/domain/repository/BlockRepository.java +++ b/src/main/java/com/aliens/backend/block/domain/repository/BlockRepository.java @@ -1,9 +1,14 @@ package com.aliens.backend.block.domain.repository; +import com.aliens.backend.auth.domain.Member; import com.aliens.backend.block.domain.Block; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Optional; + @Repository public interface BlockRepository extends JpaRepository { + List findAllByBlockingMember(Member blockingMember); } From bf391fe3a089a30cf1711a7b68516b7f934120bd Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 23:23:48 +0900 Subject: [PATCH 42/46] =?UTF-8?q?feat=20:=20Block=EC=97=90=20getter=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 --- src/main/java/com/aliens/backend/block/domain/Block.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/aliens/backend/block/domain/Block.java b/src/main/java/com/aliens/backend/block/domain/Block.java index 1c2a0ad6..bc364679 100644 --- a/src/main/java/com/aliens/backend/block/domain/Block.java +++ b/src/main/java/com/aliens/backend/block/domain/Block.java @@ -27,4 +27,12 @@ public static Block of(Member blockedMember, Member blockingMember) { block.blockedMember = blockedMember; return block; } + + public Member getBlockingMember() { + return blockingMember; + } + + public Member getBlockedMember() { + return blockedMember; + } } \ No newline at end of file From c94c1d1078c7d46fec57c8e1cf45d564e3634384 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 23:25:44 +0900 Subject: [PATCH 43/46] =?UTF-8?q?feat=20:=20Block=EC=97=90=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90ID=EB=A5=BC=20=EB=A6=AC=ED=84=B4=ED=95=98?= =?UTF-8?q?=EB=8A=94=20getter=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/aliens/backend/block/domain/Block.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/aliens/backend/block/domain/Block.java b/src/main/java/com/aliens/backend/block/domain/Block.java index bc364679..ff76e46a 100644 --- a/src/main/java/com/aliens/backend/block/domain/Block.java +++ b/src/main/java/com/aliens/backend/block/domain/Block.java @@ -28,11 +28,11 @@ public static Block of(Member blockedMember, Member blockingMember) { return block; } - public Member getBlockingMember() { - return blockingMember; + public Long getBlockingMemberId() { + return blockingMember.getId(); } - public Member getBlockedMember() { - return blockedMember; + public Long getBlockedMember() { + return blockedMember.getId(); } } \ No newline at end of file From 40093f91bfe2e622efe38cc3a3fce8158f423d74 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 23:26:14 +0900 Subject: [PATCH 44/46] =?UTF-8?q?feat=20:=20Block=EC=97=90=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90ID=EB=A5=BC=20=EB=A6=AC=ED=84=B4=ED=95=98?= =?UTF-8?q?=EB=8A=94=20getter=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/aliens/backend/block/domain/Block.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/aliens/backend/block/domain/Block.java b/src/main/java/com/aliens/backend/block/domain/Block.java index ff76e46a..e2f0f247 100644 --- a/src/main/java/com/aliens/backend/block/domain/Block.java +++ b/src/main/java/com/aliens/backend/block/domain/Block.java @@ -32,7 +32,7 @@ public Long getBlockingMemberId() { return blockingMember.getId(); } - public Long getBlockedMember() { + public Long getBlockedMemberId() { return blockedMember.getId(); } } \ No newline at end of file From 3e118ec71aa4bfc781c0d6399a862546d4ff7365 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Thu, 15 Feb 2024 23:37:42 +0900 Subject: [PATCH 45/46] =?UTF-8?q?feat=20:=20=EC=B0=A8=EB=8B=A8=EB=90=9C=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=EC=99=80=EB=8A=94=20=EB=A7=A4?= =?UTF-8?q?=EC=B9=AD=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/model/BlockHistoryGroup.java | 25 +++++++++++ .../business/model/BlockedPartnerGroup.java | 30 ++++++++++++++ .../mathcing/business/model/Participant.java | 16 ++++++-- .../business/model/ParticipantGroup.java | 12 +++++- .../business/model/PreviousPartnerGroup.java | 4 +- .../dto/request/MatchingOperateRequest.java | 13 ++++-- .../service/MatchingProcessService.java | 41 ++++++++++++++++--- .../service/MatchingProcessServiceTest.java | 6 +++ 8 files changed, 130 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/aliens/backend/mathcing/business/model/BlockHistoryGroup.java create mode 100644 src/main/java/com/aliens/backend/mathcing/business/model/BlockedPartnerGroup.java diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/BlockHistoryGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/BlockHistoryGroup.java new file mode 100644 index 00000000..36ef999e --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/model/BlockHistoryGroup.java @@ -0,0 +1,25 @@ +package com.aliens.backend.mathcing.business.model; + +import com.aliens.backend.block.domain.Block; +import com.aliens.backend.mathcing.domain.MatchingApplication; + +import java.util.List; + +public class BlockHistoryGroup { + private final List blockHistories; + + private BlockHistoryGroup(final List blockHistories) { + this.blockHistories = blockHistories; + } + + public static BlockHistoryGroup of(final List blockHistories) { + return new BlockHistoryGroup(blockHistories); + } + + public List getBlockHistoriesWith(MatchingApplication matchingApplication) { + List filteredBlockHistories = blockHistories.stream() + .filter(blockHistory -> blockHistory.getBlockingMemberId().equals(matchingApplication.getMemberId())) + .toList(); + return filteredBlockHistories; + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/BlockedPartnerGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/BlockedPartnerGroup.java new file mode 100644 index 00000000..9214371f --- /dev/null +++ b/src/main/java/com/aliens/backend/mathcing/business/model/BlockedPartnerGroup.java @@ -0,0 +1,30 @@ +package com.aliens.backend.mathcing.business.model; + +import com.aliens.backend.block.domain.Block; + +import java.util.List; + +public class BlockedPartnerGroup { + private final List blockedPartners; + + public BlockedPartnerGroup(final List blockedPartners) { + this.blockedPartners = blockedPartners; + } + + public static BlockedPartnerGroup from(final List blockHistories) { + List blockedPartners = blockHistories.stream() + .mapToLong(Block::getBlockedMemberId).boxed().toList(); + return new BlockedPartnerGroup(blockedPartners); + } + + public boolean contains(Participant participant) { + return blockedPartners.contains(participant.memberId()); + } + + @Override + public String toString() { + return "BlockedPartnerGroup{" + + "blockedPartners=" + blockedPartners + + '}'; + } +} diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/Participant.java b/src/main/java/com/aliens/backend/mathcing/business/model/Participant.java index 79336ca8..6c24bf5b 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/Participant.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/Participant.java @@ -1,5 +1,6 @@ package com.aliens.backend.mathcing.business.model; +import com.aliens.backend.block.domain.Block; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.mathcing.domain.MatchingApplication; @@ -13,8 +14,8 @@ public record Participant( Language firstPreferLanguage, Language secondPreferLanguage, List partners, - PreviousPartnerGroup previousPartnerGroup - // TODO : List blockedPartners + PreviousPartnerGroup previousPartnerGroup, + BlockedPartnerGroup blockedPartnerGroup ) { public Language getPreferLanguage(MatchingMode matchingMode) { if (matchingMode.equals(MatchingMode.FIRST_PREFER_LANGUAGE)) { @@ -27,13 +28,16 @@ public Language getPreferLanguage(MatchingMode matchingMode) { } public static Participant from(final MatchingApplication matchingApplication, - final List previousMatchingResults) { + final List previousMatchingResults, + final List blockHistories) { PreviousPartnerGroup previousPartnerGroup = PreviousPartnerGroup.from(previousMatchingResults); + BlockedPartnerGroup blockedPartnerGroup = BlockedPartnerGroup.from(blockHistories); + return new Participant( matchingApplication.getMemberId(), matchingApplication.getFirstPreferLanguage(), matchingApplication.getSecondPreferLanguage(), - new ArrayList<>(), previousPartnerGroup + new ArrayList<>(), previousPartnerGroup, blockedPartnerGroup ); } @@ -57,4 +61,8 @@ public boolean isPartnerWith(Participant participant) { public boolean hasMetPreviousRound(Participant participant) { return previousPartnerGroup.contains(participant); } + + public boolean hasBlocked(Participant participant) { + return blockedPartnerGroup.contains(participant); + } } diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java index a9a73270..1311827b 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/ParticipantGroup.java @@ -1,5 +1,6 @@ package com.aliens.backend.mathcing.business.model; +import com.aliens.backend.block.domain.Block; import com.aliens.backend.global.property.MatchingRuleProperties; import com.aliens.backend.mathcing.controller.dto.request.MatchingOperateRequest; import com.aliens.backend.mathcing.domain.MatchingApplication; @@ -22,12 +23,14 @@ private ParticipantGroup(final List participants, public static ParticipantGroup from(final MatchingOperateRequest matchingOperateRequest, final MatchingRuleProperties matchingRuleProperties) { List matchingApplications = matchingOperateRequest.matchingApplications(); - MatchingResultGroup previousMatchingResultGroup = matchingOperateRequest.previousMatchingResult(); + MatchingResultGroup previousMatchingResultGroup = matchingOperateRequest.previousMatchingResultGroup(); + BlockHistoryGroup blockHistoryGroup = matchingOperateRequest.blockHistoryGroup(); List participants = matchingApplications.stream() .map(matchingApplication -> { List previousMatchingResults = previousMatchingResultGroup.getMatchingResultsWith(matchingApplication); - return Participant.from(matchingApplication, previousMatchingResults); + List blockHistories = blockHistoryGroup.getBlockHistoriesWith(matchingApplication); + return Participant.from(matchingApplication, previousMatchingResults, blockHistories); }).toList(); return new ParticipantGroup(participants, matchingRuleProperties); } @@ -98,6 +101,7 @@ private boolean isValidMatching(final Relationship relationship, return participant != partner && !hasMetBetween(participant, partner) && !isPartnerBetween(participant, partner) && + !hasBlockedBetween(participant, partner) && !isExceededMaxPartners(relationship, partner); } @@ -116,6 +120,10 @@ private boolean isPartnerBetween(final Participant participant, final Participan return participant.isPartnerWith(partner) || partner.isPartnerWith(participant); } + private boolean hasBlockedBetween(final Participant participant, final Participant partner) { + return participant.hasBlocked(partner) || partner.hasBlocked(participant); + } + private boolean isExceedMaxTries(int tries) { return tries > matchingRuleProperties.getMaxTries(); } diff --git a/src/main/java/com/aliens/backend/mathcing/business/model/PreviousPartnerGroup.java b/src/main/java/com/aliens/backend/mathcing/business/model/PreviousPartnerGroup.java index 304a8402..6e0034d9 100644 --- a/src/main/java/com/aliens/backend/mathcing/business/model/PreviousPartnerGroup.java +++ b/src/main/java/com/aliens/backend/mathcing/business/model/PreviousPartnerGroup.java @@ -11,8 +11,8 @@ private PreviousPartnerGroup(final List previousPartners) { this.previousPartners = previousPartners; } - public static PreviousPartnerGroup from(final List previousMatchingResult) { - List previousPartners = previousMatchingResult.stream() + public static PreviousPartnerGroup from(final List previousMatchingResults) { + List previousPartners = previousMatchingResults.stream() .mapToLong(MatchingResult::getMatchedMemberId).boxed().toList(); return new PreviousPartnerGroup(previousPartners); } diff --git a/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingOperateRequest.java b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingOperateRequest.java index 09c47096..205ea931 100644 --- a/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingOperateRequest.java +++ b/src/main/java/com/aliens/backend/mathcing/controller/dto/request/MatchingOperateRequest.java @@ -1,5 +1,7 @@ package com.aliens.backend.mathcing.controller.dto.request; +import com.aliens.backend.block.domain.Block; +import com.aliens.backend.mathcing.business.model.BlockHistoryGroup; import com.aliens.backend.mathcing.business.model.MatchingResultGroup; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingResult; @@ -8,11 +10,14 @@ public record MatchingOperateRequest( List matchingApplications, - MatchingResultGroup previousMatchingResult - // TODO : 차단 유저 리스트 + MatchingResultGroup previousMatchingResultGroup, + BlockHistoryGroup blockHistoryGroup ) { public static MatchingOperateRequest of(List matchingApplications, - List previousMatchingResult) { - return new MatchingOperateRequest(matchingApplications, MatchingResultGroup.of(previousMatchingResult)); + List previousMatchingResults, + List blockHistories) { + return new MatchingOperateRequest(matchingApplications, + MatchingResultGroup.of(previousMatchingResults), + BlockHistoryGroup.of(blockHistories)); } } \ No newline at end of file diff --git a/src/main/java/com/aliens/backend/mathcing/service/MatchingProcessService.java b/src/main/java/com/aliens/backend/mathcing/service/MatchingProcessService.java index 0ff8c0c9..cf659443 100644 --- a/src/main/java/com/aliens/backend/mathcing/service/MatchingProcessService.java +++ b/src/main/java/com/aliens/backend/mathcing/service/MatchingProcessService.java @@ -1,8 +1,13 @@ package com.aliens.backend.mathcing.service; import com.aliens.backend.auth.controller.dto.LoginMember; +import com.aliens.backend.auth.domain.Member; +import com.aliens.backend.auth.domain.repository.MemberRepository; +import com.aliens.backend.block.domain.Block; +import com.aliens.backend.block.domain.repository.BlockRepository; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; +import com.aliens.backend.global.response.error.MemberError; import com.aliens.backend.mathcing.business.MatchingBusiness; import com.aliens.backend.mathcing.controller.dto.request.MatchingOperateRequest; import com.aliens.backend.mathcing.controller.dto.response.MatchingResultResponse; @@ -23,19 +28,25 @@ @Service public class MatchingProcessService { + private final MatchingBusiness matchingBusiness; private final MatchingRoundRepository matchingRoundRepository; private final MatchingApplicationRepository matchingApplicationRepository; private final MatchingResultRepository matchingResultRepository; - private final MatchingBusiness matchingBusiness; + private final MemberRepository memberRepository; + private final BlockRepository blockRepository; - public MatchingProcessService(final MatchingRoundRepository matchingRoundRepository, + public MatchingProcessService(final MatchingBusiness matchingBusiness, + final MatchingRoundRepository matchingRoundRepository, final MatchingApplicationRepository matchingApplicationRepository, final MatchingResultRepository matchingResultRepository, - final MatchingBusiness matchingBusiness) { + final MemberRepository memberRepository, + final BlockRepository blockRepository) { this.matchingRoundRepository = matchingRoundRepository; this.matchingApplicationRepository = matchingApplicationRepository; this.matchingResultRepository = matchingResultRepository; this.matchingBusiness = matchingBusiness; + this.memberRepository = memberRepository; + this.blockRepository = blockRepository; } @Scheduled(cron = "${matching.round.start}") @@ -87,7 +98,7 @@ private List getMatchingResult(final MatchingRound matchingRound private List getMatchingApplications(final MatchingRound matchingRound) { return matchingApplicationRepository.findAllByMatchingRound(matchingRound); } - + private MatchingRound getPreviousMatchingRound(MatchingRound matchingRound) { Long previousRound = matchingRound.getPreviousRound(); return matchingRoundRepository.findMatchingRoundByRound(previousRound) @@ -102,9 +113,29 @@ private List getPreviousMatchingResult(MatchingRound matchingRou return matchingResultRepository.findAllByMatchingRound(previousMatchingRound); } + private List getBlockListByMatchingApplications(MatchingRound matchingRound) { + List matchingApplications = getMatchingApplications(matchingRound); + List blockHistory = matchingApplications.stream() + .map(MatchingApplication::getMemberId) + .map(this::getMemberById) + .flatMap(member -> getBlockListByBlockingMember(member).stream()) + .toList(); + return blockHistory; + } + + private List getBlockListByBlockingMember(Member blockingMember) { + return blockRepository.findAllByBlockingMember(blockingMember); + } + + private Member getMemberById(Long memberId) { + return memberRepository.findById(memberId) + .orElseThrow(() -> new RestApiException(MemberError.NULL_MEMBER)); + } + private MatchingOperateRequest createOperateRequest(MatchingRound matchingRound) { List matchingApplications = getMatchingApplications(matchingRound); List previousMatchingResult = getPreviousMatchingResult(matchingRound); - return MatchingOperateRequest.of(matchingApplications, previousMatchingResult); + List participantBlockHistory = getBlockListByMatchingApplications(matchingRound); + return MatchingOperateRequest.of(matchingApplications, previousMatchingResult, participantBlockHistory); } } diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java index d09a714f..75fad8fa 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java @@ -91,6 +91,12 @@ void isDuplicateMatchingTest() { }); } + @Test + @DisplayName("차단된 유저와 매칭이 되지 않는지 테스트") + void isBlockedMemberTest() { + + } + @Test @DisplayName("매칭을 신청한 적이 없는 회원이 매칭 조회") void getMatchingResultTest() { From 903aa98977da1f6595471084e99106c28c97f098 Mon Sep 17 00:00:00 2001 From: Oniqued Date: Fri, 16 Feb 2024 01:32:01 +0900 Subject: [PATCH 46/46] =?UTF-8?q?test=20:=20=EC=B0=A8=EB=8B=A8=EB=90=9C=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=EC=99=80=20=EB=A7=A4=EC=B9=AD=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unit/business/MatchingBusinessTest.java | 33 +++++++++++++-- .../service/MatchingProcessServiceTest.java | 42 ++++++++++++++----- 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java index 07559965..03ac2a87 100644 --- a/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/business/MatchingBusinessTest.java @@ -1,14 +1,18 @@ package com.aliens.backend.matching.unit.business; +import com.aliens.backend.auth.domain.Member; +import com.aliens.backend.auth.domain.repository.MemberRepository; +import com.aliens.backend.block.domain.Block; +import com.aliens.backend.block.domain.repository.BlockRepository; import com.aliens.backend.global.BaseServiceTest; import com.aliens.backend.global.DummyGenerator; import com.aliens.backend.global.response.error.MatchingError; import com.aliens.backend.global.exception.RestApiException; import com.aliens.backend.global.property.MatchingTimeProperties; +import com.aliens.backend.global.response.error.MemberError; import com.aliens.backend.matching.util.time.MockClock; import com.aliens.backend.matching.util.time.MockTime; import com.aliens.backend.mathcing.business.MatchingBusiness; -import com.aliens.backend.mathcing.business.model.Partner; import com.aliens.backend.mathcing.controller.dto.request.MatchingOperateRequest; import com.aliens.backend.mathcing.domain.MatchingApplication; import com.aliens.backend.mathcing.domain.MatchingResult; @@ -18,7 +22,6 @@ import com.aliens.backend.mathcing.domain.repository.MatchingRoundRepository; import com.aliens.backend.mathcing.service.MatchingProcessService; import com.aliens.backend.mathcing.business.model.Participant; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -29,7 +32,6 @@ import java.util.List; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.junit.jupiter.api.Assertions.*; @SpringBootTest class MatchingBusinessTest extends BaseServiceTest { @@ -40,6 +42,8 @@ class MatchingBusinessTest extends BaseServiceTest { @Autowired MatchingBusiness matchingBusiness; @Autowired DummyGenerator dummyGenerator; @Autowired MatchingTimeProperties matchingTimeProperties; + @Autowired BlockRepository blockRepository; + @Autowired MemberRepository memberRepository; @Autowired MockClock mockClock; MatchingOperateRequest matchingOperateRequest; @@ -81,10 +85,30 @@ private List getPreviousMatchingResult(MatchingRound matchingRou return matchingResultRepository.findAllByMatchingRound(previousMatchingRound); } + private List getBlockListByMatchingApplications(MatchingRound matchingRound) { + List matchingApplications = getMatchingApplications(matchingRound); + List blockHistory = matchingApplications.stream() + .map(MatchingApplication::getMemberId) + .map(this::getMemberById) + .flatMap(member -> getBlockListByBlockingMember(member).stream()) + .toList(); + return blockHistory; + } + + private List getBlockListByBlockingMember(Member blockingMember) { + return blockRepository.findAllByBlockingMember(blockingMember); + } + + private Member getMemberById(Long memberId) { + return memberRepository.findById(memberId) + .orElseThrow(() -> new RestApiException(MemberError.NULL_MEMBER)); + } + private MatchingOperateRequest createOperateRequest(MatchingRound matchingRound) { List matchingApplications = getMatchingApplications(matchingRound); List previousMatchingResult = getPreviousMatchingResult(matchingRound); - return MatchingOperateRequest.of(matchingApplications, previousMatchingResult); + List participantBlockHistory = getBlockListByMatchingApplications(matchingRound); + return MatchingOperateRequest.of(matchingApplications, previousMatchingResult, participantBlockHistory); } private void saveMatchRound(MockTime mockTime) { @@ -95,6 +119,7 @@ private void saveMatchRound(MockTime mockTime) { private void operateMatching(MockTime mockTime) { mockClock.mockTime(mockTime); + dummyGenerator.generateMultiMember(21); dummyGenerator.generateAppliersToMatch(20L); matchingOperateRequest = createOperateRequest(getCurrentRound()); matchingBusiness.operateMatching(matchingOperateRequest); diff --git a/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java b/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java index 75fad8fa..ff4bb127 100644 --- a/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java +++ b/src/test/java/com/aliens/backend/matching/unit/service/MatchingProcessServiceTest.java @@ -1,7 +1,10 @@ package com.aliens.backend.matching.unit.service; import com.aliens.backend.auth.controller.dto.LoginMember; -import com.aliens.backend.auth.domain.MemberRole; +import com.aliens.backend.auth.domain.Member; +import com.aliens.backend.block.controller.dto.BlockRequest; +import com.aliens.backend.block.domain.Block; +import com.aliens.backend.block.domain.repository.BlockRepository; import com.aliens.backend.global.BaseServiceTest; import com.aliens.backend.global.DummyGenerator; import com.aliens.backend.global.response.error.MatchingError; @@ -25,8 +28,6 @@ import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; @SpringBootTest class MatchingProcessServiceTest extends BaseServiceTest { @@ -34,26 +35,23 @@ class MatchingProcessServiceTest extends BaseServiceTest { @Autowired MatchingRoundRepository matchingRoundRepository; @Autowired MatchingTimeProperties matchingTimeProperties; @Autowired MatchingResultRepository matchingResultRepository; + @Autowired BlockRepository blockRepository; @Autowired MockClock mockClock; @Autowired DummyGenerator dummyGenerator; - LoginMember loginMember; + List members; @BeforeEach void setUp() { - loginMember = new LoginMember(1L, MemberRole.MEMBER); + members = dummyGenerator.generateMultiMember(20); saveMatchRound(MockTime.MONDAY); } @Test @DisplayName("매칭 결과 조회") void operateMatchingTest() { - // given - mockClock.mockTime(MockTime.VALID_RECEPTION_TIME_ON_MONDAY); - dummyGenerator.generateAppliersToMatch(20L); - - // when - matchingProcessService.operateMatching(); + // given & when + operateMatching(MockTime.VALID_RECEPTION_TIME_ON_MONDAY); // then List result = matchingResultRepository.findAllByMatchingRound(getCurrentRound()); @@ -94,12 +92,26 @@ void isDuplicateMatchingTest() { @Test @DisplayName("차단된 유저와 매칭이 되지 않는지 테스트") void isBlockedMemberTest() { + // given + Member blockingMember = members.get(0); + makeThisMemberBlockAllPartner(blockingMember); + // when + operateMatching(MockTime.VALID_RECEPTION_TIME_ON_MONDAY); + + // then + List matchingResults = getMatchingResultByMatchingRound(getCurrentRound()); + List matchingResultsOfBlockingMember = matchingResults.stream() + .filter(matchingResult -> matchingResult.getMatchingMemberId().equals(blockingMember.getId())).toList(); + assertThat(matchingResultsOfBlockingMember).isEmpty(); } @Test @DisplayName("매칭을 신청한 적이 없는 회원이 매칭 조회") void getMatchingResultTest() { + Member member = members.get(0); + LoginMember loginMember = member.getLoginMember(); + assertThatThrownBy(() -> matchingProcessService.findMatchingResult(loginMember)) .hasMessage(MatchingError.NOT_FOUND_MATCHING_APPLICATION_INFO.getDevelopCode()); } @@ -124,4 +136,12 @@ private void operateMatching(MockTime mockTime) { private List getMatchingResultByMatchingRound(MatchingRound matchingRound) { return matchingResultRepository.findAllByMatchingRound(matchingRound); } + + private void makeThisMemberBlockAllPartner(Member blockingMember) { + for (int i = 1; i < members.size(); i++) { + Member blockedMember = members.get(i); + Block blockRequest = Block.of(blockingMember, blockedMember); + blockRepository.save(blockRequest); + } + } }