From f015f04deeb82d60ea1c47e0489346be779a6840 Mon Sep 17 00:00:00 2001 From: fnsl1026 Date: Thu, 15 May 2025 17:50:33 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20=ED=95=98=EB=A3=A8=EC=97=90=20?= =?UTF-8?q?=EB=A7=A4=EC=B9=AD=EB=90=9C=20=ED=9A=9F=EC=88=98=EB=A5=BC=20?= =?UTF-8?q?=EC=84=B8=EC=95=84=EB=A6=AC=EB=8A=94=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20MatchedHistoryRepository=EC=97=90=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(#352)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../buddyya/match/repository/MatchedHistoryRepository.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/team/buddyya/match/repository/MatchedHistoryRepository.java b/src/main/java/com/team/buddyya/match/repository/MatchedHistoryRepository.java index 4f7f3934..30c5adc0 100644 --- a/src/main/java/com/team/buddyya/match/repository/MatchedHistoryRepository.java +++ b/src/main/java/com/team/buddyya/match/repository/MatchedHistoryRepository.java @@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.time.LocalDateTime; import java.util.Optional; import java.util.Set; @@ -16,4 +17,6 @@ public interface MatchedHistoryRepository extends JpaRepository findMostRecentMatchedHistoryByStudentId(Long studentId); + + int countByStudentIdAndCreatedDateBetween(Long studentId, LocalDateTime start, LocalDateTime end); } From 0666f208d0c4ba3d763e70e626b70694c35a487b Mon Sep 17 00:00:00 2001 From: fnsl1026 Date: Thu, 15 May 2025 17:51:01 +0900 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20=ED=95=98=EB=A3=A8=EC=97=90=20?= =?UTF-8?q?=EB=A7=A4=EC=B9=AD=20=ED=9A=9F=EC=88=98=EA=B0=80=20=EB=91=90?= =?UTF-8?q?=EB=B2=88=EC=9C=BC=EB=A1=9C=20=EC=A6=9D=EA=B0=80=20=ED=96=88?= =?UTF-8?q?=EC=9C=BC=EB=AF=80=EB=A1=9C=20=EC=98=A4=EB=A5=98=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20one=EC=97=90=EC=84=9C=20two=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#352)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/team/buddyya/match/exception/MatchExceptionType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/team/buddyya/match/exception/MatchExceptionType.java b/src/main/java/com/team/buddyya/match/exception/MatchExceptionType.java index 5393b2b5..d83bc5ea 100644 --- a/src/main/java/com/team/buddyya/match/exception/MatchExceptionType.java +++ b/src/main/java/com/team/buddyya/match/exception/MatchExceptionType.java @@ -11,7 +11,7 @@ public enum MatchExceptionType implements BaseExceptionType { MATCH_PROFILE_NOT_FOUND(6003, HttpStatus.NOT_FOUND, "Matching profile not found."), MATCH_PROFILE_NOT_COMPLETED(6004, HttpStatus.BAD_REQUEST, "Matching profile is not completed."), MATCH_HISTORY_NOT_FOUND(6005, HttpStatus.NOT_FOUND, "Recent matched history not found."), - MATCH_REQUEST_TIME_INVALID(6006, HttpStatus.BAD_REQUEST, "You can only request a match once per day."); + MATCH_REQUEST_TIME_INVALID(6006, HttpStatus.BAD_REQUEST, "You can only request a match twice per day."); private final int errorCode; private final HttpStatus httpStatus; From d539199e0818e355166184b9c5f575cbafa68ba8 Mon Sep 17 00:00:00 2001 From: fnsl1026 Date: Thu, 15 May 2025 17:52:15 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20=ED=95=98=EB=A3=A8=EC=97=90=20?= =?UTF-8?q?=EB=A7=A4=EC=B9=AD=20=EC=84=B1=EA=B3=B5=ED=95=9C=20=ED=9A=9F?= =?UTF-8?q?=EC=88=98=EA=B0=80=20=EB=91=90=EB=B2=88=20=EC=9D=B4=EC=83=81?= =?UTF-8?q?=EC=9D=B4=EB=A9=B4=20=EB=A7=A4=EC=B9=AD=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EB=AA=BB=ED=95=98=EA=B2=8C=20=EC=98=88=EC=99=B8=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20(#352)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../match/service/BasicMatchService.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/team/buddyya/match/service/BasicMatchService.java b/src/main/java/com/team/buddyya/match/service/BasicMatchService.java index d77ac438..0f69ebf5 100644 --- a/src/main/java/com/team/buddyya/match/service/BasicMatchService.java +++ b/src/main/java/com/team/buddyya/match/service/BasicMatchService.java @@ -48,6 +48,7 @@ public class BasicMatchService implements MatchService { private static final Long CHINESE_LANGUAGE_ID = 3L; + private static final int MAX_MATCHES_PER_DAY = 2; private final MatchRequestRepository matchRequestRepository; private final MatchedHistoryRepository matchedHistoryRepository; @@ -259,19 +260,17 @@ private void validateMatchProfileCompleted(Student student) { } private void validateMatchRequestTime(Student student) { - Optional recentMatchedHistory = - matchedHistoryRepository.findMostRecentMatchedHistoryByStudentId(student.getId()); - if (recentMatchedHistory.isPresent()) { - LocalDateTime matchedAt = recentMatchedHistory.get().getCreatedDate(); - LocalDate today = LocalDate.now(); - LocalDate matchedDate = matchedAt.toLocalDate(); - if (matchedDate.isEqual(today)) { - throw new MatchException(MatchExceptionType.MATCH_REQUEST_TIME_INVALID); - } + LocalDate today = LocalDate.now(); + LocalDateTime startOfDay = today.atStartOfDay(); + LocalDateTime endOfDay = today.plusDays(1).atStartOfDay(); + int todayMatchCount = matchedHistoryRepository + .countByStudentIdAndCreatedDateBetween(student.getId(), startOfDay, endOfDay); + if (todayMatchCount >= MAX_MATCHES_PER_DAY) { + throw new MatchException(MatchExceptionType.MATCH_REQUEST_TIME_INVALID); } } - public boolean checkChineseAvailability(Student student){ + public boolean checkChineseAvailability(Student student) { return studentLanguageRepository.existsByStudentAndLanguage_Id(student, CHINESE_LANGUAGE_ID); } } From 13c1413f5dcb40d0e7257247e2377f14adef3752 Mon Sep 17 00:00:00 2001 From: fnsl1026 Date: Thu, 15 May 2025 17:53:04 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20=EB=8B=A4=EB=A5=B8=20=ED=95=99?= =?UTF-8?q?=EA=B5=90=EB=A5=BC=20=EC=A0=84=EC=B2=B4=20=ED=95=99=EA=B5=90?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95=ED=95=98=EC=97=AC=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B5=AC=ED=98=84=20(#352)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/team/buddyya/match/service/BasicMatchService.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/team/buddyya/match/service/BasicMatchService.java b/src/main/java/com/team/buddyya/match/service/BasicMatchService.java index 0f69ebf5..9c2df554 100644 --- a/src/main/java/com/team/buddyya/match/service/BasicMatchService.java +++ b/src/main/java/com/team/buddyya/match/service/BasicMatchService.java @@ -192,15 +192,11 @@ private boolean isUniversityMatch(UniversityType matchRequestPreference, UniversityType requesterPreference, Long requesterUniversityId, Long matchRequestUniversityId) { - if (requesterPreference == UniversityType.SAME_UNIVERSITY && - matchRequestPreference == UniversityType.SAME_UNIVERSITY) { - return requesterUniversityId.equals(matchRequestUniversityId); - } if (requesterPreference == UniversityType.DIFFERENT_UNIVERSITY && matchRequestPreference == UniversityType.DIFFERENT_UNIVERSITY) { - return !requesterUniversityId.equals(matchRequestUniversityId); + return true; } - return false; + return requesterUniversityId.equals(matchRequestUniversityId); } private boolean isGenderMatch(GenderType matchRequestPreference,