diff --git a/src/main/java/com/asap/server/service/MeetingService.java b/src/main/java/com/asap/server/service/MeetingService.java index 50098002..c56af2a9 100644 --- a/src/main/java/com/asap/server/service/MeetingService.java +++ b/src/main/java/com/asap/server/service/MeetingService.java @@ -3,8 +3,21 @@ import static com.asap.server.common.exception.Error.INVALID_MEETING_HOST_EXCEPTION; import static com.asap.server.common.exception.Error.MEETING_VALIDATION_FAILED_EXCEPTION; -import com.asap.server.common.utils.DateUtil; +import com.asap.server.common.exception.Error; +import com.asap.server.common.exception.model.ConflictException; +import com.asap.server.common.exception.model.ForbiddenException; +import com.asap.server.common.exception.model.NotFoundException; +import com.asap.server.common.exception.model.UnauthorizedException; import com.asap.server.common.jwt.JwtService; +import com.asap.server.common.utils.DateUtil; +import com.asap.server.persistence.domain.ConfirmedDateTime; +import com.asap.server.persistence.domain.Meeting; +import com.asap.server.persistence.domain.Place; +import com.asap.server.persistence.domain.User; +import com.asap.server.persistence.domain.enums.Role; +import com.asap.server.persistence.repository.meeting.MeetingRepository; +import com.asap.server.persistence.repository.timeblock.TimeBlockRepository; +import com.asap.server.persistence.repository.timeblock.dto.TimeBlockDto; import com.asap.server.presentation.controller.dto.request.MeetingConfirmRequestDto; import com.asap.server.presentation.controller.dto.request.MeetingSaveRequestDto; import com.asap.server.presentation.controller.dto.response.AvailableDatesDto; @@ -14,20 +27,7 @@ import com.asap.server.presentation.controller.dto.response.MeetingScheduleResponseDto; import com.asap.server.presentation.controller.dto.response.MeetingTitleResponseDto; import com.asap.server.presentation.controller.dto.response.TimeTableResponseDto; -import com.asap.server.persistence.domain.ConfirmedDateTime; -import com.asap.server.persistence.domain.Meeting; -import com.asap.server.persistence.domain.Place; -import com.asap.server.persistence.domain.User; -import com.asap.server.persistence.domain.enums.Role; -import com.asap.server.common.exception.Error; -import com.asap.server.common.exception.model.ConflictException; -import com.asap.server.common.exception.model.ForbiddenException; -import com.asap.server.common.exception.model.NotFoundException; -import com.asap.server.common.exception.model.UnauthorizedException; -import com.asap.server.persistence.repository.meeting.MeetingRepository; -import com.asap.server.persistence.repository.timeblock.TimeBlockRepository; -import com.asap.server.persistence.repository.timeblock.dto.TimeBlockDto; -import com.asap.server.service.meeting.MeetingTimeRecommendService; +import com.asap.server.service.meeting.recommend.MeetingTimeRecommendService; import com.asap.server.service.vo.BestMeetingTimeVo; import com.asap.server.service.vo.BestMeetingTimeWithUsersVo; import java.time.LocalDate; diff --git a/src/main/java/com/asap/server/service/meeting/FindBestMeetingTimeCasesStrategy.java b/src/main/java/com/asap/server/service/meeting/FindBestMeetingTimeCasesStrategy.java deleted file mode 100644 index c6175eb0..00000000 --- a/src/main/java/com/asap/server/service/meeting/FindBestMeetingTimeCasesStrategy.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.asap.server.service.meeting; - -import com.asap.server.persistence.domain.enums.Duration; -import com.asap.server.service.vo.PossibleTimeCaseVo; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; - -@Component -public class FindBestMeetingTimeCasesStrategy { - private static final Duration[] durations = Duration.values(); - - public List find(final Duration duration, int userCount) { - List timeCases = new ArrayList<>(); - while (userCount > 0) { - List possibleMeetingTimeCases = getPossibleMeetingTimeCases(duration, userCount); - timeCases.addAll(possibleMeetingTimeCases); - - userCount = userCount / 2; - } - return timeCases; - } - - private List getPossibleMeetingTimeCases(final Duration duration, final int userCount) { - List firstTimeCases = findFirstPossibleMeetingTimeCases(duration, userCount); - - if (duration.ordinal() < 2) return firstTimeCases; - - List secondTimeCases = findSecondPossibleMeetingTimeCases(duration, userCount); - firstTimeCases.addAll(secondTimeCases); - return firstTimeCases; - } - - private List findFirstPossibleMeetingTimeCases(final Duration duration, final int userCount) { - List timeCases = new ArrayList<>(); - - for (int count = userCount; count > userCount / 2; count--) { - timeCases.add(new PossibleTimeCaseVo(durations[duration.ordinal()], count)); - - if (duration.ordinal() < 1) continue; - - timeCases.add(new PossibleTimeCaseVo(durations[duration.ordinal() - 1], count)); - } - - return timeCases; - } - - private List findSecondPossibleMeetingTimeCases(final Duration duration, final int userCount) { - List timeCases = new ArrayList<>(); - - int secondDuration = duration.ordinal() - 2; - for (int durationCount = secondDuration; durationCount > -1; durationCount--) { - for (int count = userCount; count > userCount / 2; count--) { - timeCases.add(new PossibleTimeCaseVo(durations[durationCount], count)); - } - } - - return timeCases; - } -} diff --git a/src/main/java/com/asap/server/service/meeting/FindBestMeetingTimeStrategy.java b/src/main/java/com/asap/server/service/meeting/FindBestMeetingTimeStrategy.java deleted file mode 100644 index dfbfcbaa..00000000 --- a/src/main/java/com/asap/server/service/meeting/FindBestMeetingTimeStrategy.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.asap.server.service.meeting; - -import com.asap.server.persistence.domain.enums.TimeSlot; -import com.asap.server.persistence.repository.timeblock.dto.TimeBlockDto; -import com.asap.server.service.vo.BestMeetingTimeVo; -import com.asap.server.service.vo.PossibleTimeCaseVo; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; -import org.springframework.stereotype.Component; - -@Component -public class FindBestMeetingTimeStrategy { - public List find( - final List timeBlocks, - final PossibleTimeCaseVo timeCase - ) { - int needBlock = timeCase.duration().getNeedBlock(); - int userCount = timeCase.memberCnt(); - - List sortedTimeBlocks = timeBlocks.stream() - .filter(timeBlock -> timeBlock.userCount() == userCount) - .sorted(TimeBlockDto::compareTo) - .collect(Collectors.toList()); - - return getBestMeetingTime(sortedTimeBlocks, needBlock); - } - - private List getBestMeetingTime( - final List timeBlocks, - final int needTimeBlockCount - ) { - List bestMeetingTimes = new ArrayList<>(); - - int endIndex = timeBlocks.size() - needTimeBlockCount + 1; - for (int timeBlockIdx = 0; timeBlockIdx < endIndex; timeBlockIdx++) { - int endIdx = timeBlockIdx + needTimeBlockCount; - - if (!isBestMeetingTime(timeBlocks, timeBlockIdx, endIdx)) { - continue; - } - - int sumWeight = sumTimeBlocksWeight(timeBlocks, timeBlockIdx, endIdx); - - BestMeetingTimeVo bestMeetingTime = createBestMeetingTimeVo( - timeBlocks, - needTimeBlockCount, - timeBlockIdx, - sumWeight - ); - - bestMeetingTimes.add(bestMeetingTime); - } - return bestMeetingTimes - .stream() - .sorted(Comparator.comparing(BestMeetingTimeVo::weight, Comparator.reverseOrder())) - .toList(); - } - - private BestMeetingTimeVo createBestMeetingTimeVo( - List timeBlocks, - int needTimeBlockCount, - int timeBlockIdx, - int sumWeight - ) { - TimeBlockDto timeBlock = timeBlocks.get(timeBlockIdx); - - TimeSlot startTime = timeBlock.timeSlot(); - TimeSlot endTime = TimeSlot.getTimeSlot(startTime.ordinal() + needTimeBlockCount); - - return new BestMeetingTimeVo( - timeBlock.availableDate(), - startTime, - endTime, - sumWeight - ); - } - - private boolean isBestMeetingTime( - final List timeBlocks, - final int timeBlockIdx, - final int endIdx - ) { - boolean isBestMeetingTime = true; - TimeSlot nextTime = timeBlocks.get(timeBlockIdx).timeSlot(); - for (int i = timeBlockIdx + 1; i < endIdx; i++) { - if (nextTime.ordinal() + 1 != timeBlocks.get(i).timeSlot().ordinal()) { - return false; - } - - nextTime = timeBlocks.get(i).timeSlot(); - } - return isBestMeetingTime; - } - - private int sumTimeBlocksWeight( - final List timeBlocks, - final int startIdx, - final int endIdx - ) { - return timeBlocks - .subList(startIdx, endIdx) - .stream() - .map(TimeBlockDto::weight) - .reduce(0, Integer::sum); - } -} diff --git a/src/main/java/com/asap/server/service/meeting/MeetingTimeRecommendService.java b/src/main/java/com/asap/server/service/meeting/MeetingTimeRecommendService.java deleted file mode 100644 index 32eb618b..00000000 --- a/src/main/java/com/asap/server/service/meeting/MeetingTimeRecommendService.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.asap.server.service.meeting; - -import com.asap.server.persistence.domain.enums.Duration; -import com.asap.server.persistence.repository.timeblock.dto.TimeBlockDto; -import com.asap.server.service.vo.BestMeetingTimeVo; -import com.asap.server.service.vo.PossibleTimeCaseVo; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -@Component -@RequiredArgsConstructor -public class MeetingTimeRecommendService { - private static final int BEST_MEETING_TIME_SIZE = 3; - private final FindBestMeetingTimeCasesStrategy findBestMeetingTimeCasesStrategy; - private final FindBestMeetingTimeStrategy findBestMeetingTimeStrategy; - - public List getBestMeetingTime( - final List timeBlocks, - final Duration duration, - final int userCount - ) { - List timeCases = findBestMeetingTimeCasesStrategy.find(duration, userCount); - List bestMeetingTimes = findAllBestMeetingTimes(timeBlocks, timeCases); - - while (bestMeetingTimes.size() < BEST_MEETING_TIME_SIZE) { - bestMeetingTimes.add(null); - } - return bestMeetingTimes; - } - - public List findAllBestMeetingTimes( - final List timeBlocks, - final List timeCases - ) { - List bestMeetingTimes = new ArrayList<>(); - for (PossibleTimeCaseVo timeCase : timeCases) { - List bestMeetingTimesWithTimeCase = findBestMeetingTimeStrategy.find(timeBlocks, timeCase); - - bestMeetingTimes.addAll(bestMeetingTimesWithTimeCase); - - if (bestMeetingTimes.size() < BEST_MEETING_TIME_SIZE) continue; - - return bestMeetingTimes - .stream() - .limit(BEST_MEETING_TIME_SIZE) - .collect(Collectors.toList()); - } - return bestMeetingTimes; - } -} diff --git a/src/main/java/com/asap/server/service/meeting/recommend/MeetingTimeRecommendService.java b/src/main/java/com/asap/server/service/meeting/recommend/MeetingTimeRecommendService.java index 7b9d6a82..33a70357 100644 --- a/src/main/java/com/asap/server/service/meeting/recommend/MeetingTimeRecommendService.java +++ b/src/main/java/com/asap/server/service/meeting/recommend/MeetingTimeRecommendService.java @@ -11,7 +11,9 @@ import java.util.List; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +@Component @RequiredArgsConstructor public class MeetingTimeRecommendService { private static final int BEST_MEETING_TIME_SIZE = 3; diff --git a/src/test/java/com/asap/server/service/meeting/FindBestMeetingTimeCasesStrategyTest.java b/src/test/java/com/asap/server/service/meeting/FindBestMeetingTimeCasesStrategyTest.java deleted file mode 100644 index 416ff861..00000000 --- a/src/test/java/com/asap/server/service/meeting/FindBestMeetingTimeCasesStrategyTest.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.asap.server.service.meeting; - -import static com.asap.server.persistence.domain.enums.Duration.HALF; -import static com.asap.server.persistence.domain.enums.Duration.HOUR; -import static com.asap.server.persistence.domain.enums.Duration.HOUR_HALF; -import static com.asap.server.persistence.domain.enums.Duration.TWO_HOUR; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -import com.asap.server.persistence.domain.enums.Duration; -import com.asap.server.service.vo.PossibleTimeCaseVo; -import java.util.List; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -class FindBestMeetingTimeCasesStrategyTest { - private FindBestMeetingTimeCasesStrategy strategy; - - @BeforeEach - void setUp() { - strategy = new FindBestMeetingTimeCasesStrategy(); - } - - @DisplayName("회의 진행 시간이 2시간이고, 회의 참여 인원이 6명일 때 24개의 경우의 수가 나온다.") - @Test - void findOptimalMeetingTimeCasesTest() { - // given - Duration duration = TWO_HOUR; - int userCount = 6; - List response = List.of( - new PossibleTimeCaseVo(TWO_HOUR, 6), - new PossibleTimeCaseVo(HOUR_HALF, 6), - new PossibleTimeCaseVo(TWO_HOUR, 5), - new PossibleTimeCaseVo(HOUR_HALF, 5), - new PossibleTimeCaseVo(TWO_HOUR, 4), - new PossibleTimeCaseVo(HOUR_HALF, 4), - new PossibleTimeCaseVo(HOUR, 6), - new PossibleTimeCaseVo(HOUR, 5), - new PossibleTimeCaseVo(HOUR, 4), - new PossibleTimeCaseVo(HALF, 6), - new PossibleTimeCaseVo(HALF, 5), - new PossibleTimeCaseVo(HALF, 4), - new PossibleTimeCaseVo(TWO_HOUR, 3), - new PossibleTimeCaseVo(HOUR_HALF, 3), - new PossibleTimeCaseVo(TWO_HOUR, 2), - new PossibleTimeCaseVo(HOUR_HALF, 2), - new PossibleTimeCaseVo(HOUR, 3), - new PossibleTimeCaseVo(HOUR, 2), - new PossibleTimeCaseVo(HALF, 3), - new PossibleTimeCaseVo(HALF, 2), - new PossibleTimeCaseVo(TWO_HOUR, 1), - new PossibleTimeCaseVo(HOUR_HALF, 1), - new PossibleTimeCaseVo(HOUR, 1), - new PossibleTimeCaseVo(HALF, 1) - ); - - // when - List result = strategy.find(duration, userCount); - - // then - assertThat(result.size()).isEqualTo(response.size()); - assertThat(result).isEqualTo(response); - } - - @DisplayName("회의 진행 시간이 30분이고, 회의 참여 인원이 1명일 때 1개의 경우의 수가 나온다.") - @Test - void findOptimalMeetingTimeCasesTest2() { - // given - Duration duration = HALF; - int userCount = 1; - List response = List.of( - new PossibleTimeCaseVo(HALF, 1) - ); - - // when - List result = strategy.find(duration, userCount); - - // then - assertThat(result.size()).isEqualTo(response.size()); - assertThat(result).isEqualTo(response); - } - - @DisplayName("회의 진행 시간이 1시간이고, 회의 참여 인원이 1명일 때 2개의 경우의 수가 나온다.") - @Test - void findOptimalMeetingTimeCasesTest3() { - // given - Duration duration = HOUR; - int userCount = 1; - List response = List.of( - new PossibleTimeCaseVo(HOUR, 1), - new PossibleTimeCaseVo(HALF, 1) - ); - - // when - List result = strategy.find(duration, userCount); - - // then - assertThat(result.size()).isEqualTo(response.size()); - assertThat(result).isEqualTo(response); - } - - @DisplayName("회의 진행 시간이 1시간 30분이고, 회의 참여 인원이 2명일 때 6개의 경우의 수가 나온다.") - @Test - void findOptimalMeetingTimeCasesTest4() { - // given - Duration duration = HOUR_HALF; - int userCount = 2; - List response = List.of( - new PossibleTimeCaseVo(HOUR_HALF, 2), - new PossibleTimeCaseVo(HOUR, 2), - new PossibleTimeCaseVo(HALF, 2), - new PossibleTimeCaseVo(HOUR_HALF, 1), - new PossibleTimeCaseVo(HOUR, 1), - new PossibleTimeCaseVo(HALF, 1) - ); - - // when - List result = strategy.find(duration, userCount); - - // then - assertThat(result.size()).isEqualTo(response.size()); - assertThat(result).isEqualTo(response); - } -} \ No newline at end of file diff --git a/src/test/java/com/asap/server/service/meeting/FindBestMeetingTimeStrategyTest.java b/src/test/java/com/asap/server/service/meeting/FindBestMeetingTimeStrategyTest.java deleted file mode 100644 index 7531dbfb..00000000 --- a/src/test/java/com/asap/server/service/meeting/FindBestMeetingTimeStrategyTest.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.asap.server.service.meeting; - -import com.asap.server.persistence.repository.timeblock.dto.TimeBlockDto; -import com.asap.server.persistence.domain.enums.Duration; -import com.asap.server.service.vo.*; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_11_00; -import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_11_30; -import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_12_00; -import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_12_30; -import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_13_00; -import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_13_30; -import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_14_00; -import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_14_30; -import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_20_00; -import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_20_30; -import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_21_00; -import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_21_30; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -class FindBestMeetingTimeStrategyTest { - private FindBestMeetingTimeStrategy strategy; - - @BeforeEach - void setUp() { - strategy = new FindBestMeetingTimeStrategy(); - } - - @Test - @DisplayName("모든 유저들이 특정 날짜에 회의 시간이 가능할 경우") - public void getBestMeetingTime() { - // given - LocalDate availableDate = LocalDate.of(2023, 9, 8); - - TimeBlockDto timeBlock = new TimeBlockDto(availableDate, SLOT_11_00, 0, 2L); - TimeBlockDto timeBlock2 = new TimeBlockDto(availableDate, SLOT_11_30, 0, 2L); - TimeBlockDto timeBlock3 = new TimeBlockDto(availableDate, SLOT_12_00, 0, 2L); - TimeBlockDto timeBlock4 = new TimeBlockDto(availableDate, SLOT_12_30, 0, 2L); - TimeBlockDto timeBlock5 = new TimeBlockDto(availableDate, SLOT_13_00, 0, 2L); - TimeBlockDto timeBlock6 = new TimeBlockDto(availableDate, SLOT_13_30, 0, 2L); - TimeBlockDto timeBlock7 = new TimeBlockDto(availableDate, SLOT_14_00, 0, 2L); - List timeBlocks = new ArrayList<>(Arrays.asList(timeBlock, timeBlock2, timeBlock3, timeBlock4, timeBlock5, timeBlock6, timeBlock7)); - - BestMeetingTimeVo bestMeetingTime = new BestMeetingTimeVo(availableDate, SLOT_11_00, SLOT_13_00, 0); - BestMeetingTimeVo bestMeetingTime2 = new BestMeetingTimeVo(availableDate, SLOT_11_30, SLOT_13_30, 0); - BestMeetingTimeVo bestMeetingTime3 = new BestMeetingTimeVo(availableDate, SLOT_12_00, SLOT_14_00, 0); - BestMeetingTimeVo bestMeetingTime4 = new BestMeetingTimeVo(availableDate, SLOT_12_30, SLOT_14_30, 0); - List expected = new ArrayList<>(List.of(bestMeetingTime, bestMeetingTime2, bestMeetingTime3, bestMeetingTime4)); - - PossibleTimeCaseVo possibleTimeCaseVo = new PossibleTimeCaseVo(Duration.TWO_HOUR, 2); - - // when - List result = strategy.find(timeBlocks, possibleTimeCaseVo); - - // then - assertThat(result).isEqualTo(expected); - } - - @Test - @DisplayName("특정 날짜에 최적의 회의 시간대가 아침에 하나 저녁에 하나 있을 경우") - public void getBestMeetingTime2() { - // given - LocalDate availableDate = LocalDate.of(2023, 9, 8); - - TimeBlockDto timeBlock = new TimeBlockDto(availableDate, SLOT_11_00, 0, 2L); - TimeBlockDto timeBlock2 = new TimeBlockDto(availableDate, SLOT_11_30, 0, 2L); - TimeBlockDto timeBlock3 = new TimeBlockDto(availableDate, SLOT_12_00, 0, 2L); - TimeBlockDto timeBlock4 = new TimeBlockDto(availableDate, SLOT_12_30, 0, 1L); - TimeBlockDto timeBlock5 = new TimeBlockDto(availableDate, SLOT_13_00, 0, 1L); - TimeBlockDto timeBlock6 = new TimeBlockDto(availableDate, SLOT_13_30, 0, 1L); - TimeBlockDto timeBlock7 = new TimeBlockDto(availableDate, SLOT_20_00, 0, 2L); - TimeBlockDto timeBlock8 = new TimeBlockDto(availableDate, SLOT_20_30, 0, 2L); - TimeBlockDto timeBlock9 = new TimeBlockDto(availableDate, SLOT_21_00, 0, 2L); - List timeBlocks = new ArrayList<>(Arrays.asList(timeBlock, timeBlock2, timeBlock3, timeBlock4, timeBlock5, timeBlock6, timeBlock7, timeBlock8, timeBlock9)); - - BestMeetingTimeVo bestMeetingTime = new BestMeetingTimeVo(availableDate, SLOT_11_00, SLOT_12_00, 0); - BestMeetingTimeVo bestMeetingTime2 = new BestMeetingTimeVo(availableDate, SLOT_11_30, SLOT_12_30, 0); - BestMeetingTimeVo bestMeetingTime3 = new BestMeetingTimeVo(availableDate, SLOT_20_00, SLOT_21_00, 0); - BestMeetingTimeVo bestMeetingTime4 = new BestMeetingTimeVo(availableDate, SLOT_20_30, SLOT_21_30, 0); - List expected = new ArrayList<>(List.of(bestMeetingTime, bestMeetingTime2, bestMeetingTime3, bestMeetingTime4)); - - PossibleTimeCaseVo possibleTimeCaseVo = new PossibleTimeCaseVo(Duration.HOUR, 2); - - // when - List result = strategy.find(timeBlocks, possibleTimeCaseVo); - - // then - assertThat(result).isEqualTo(expected); - } -} \ No newline at end of file diff --git a/src/test/java/com/asap/server/service/meeting/MeetingTimeRecommendServiceTest.java b/src/test/java/com/asap/server/service/meeting/recommend/MeetingTimeRecommendServiceTest.java similarity index 72% rename from src/test/java/com/asap/server/service/meeting/MeetingTimeRecommendServiceTest.java rename to src/test/java/com/asap/server/service/meeting/recommend/MeetingTimeRecommendServiceTest.java index ca65e1ea..bae15c6c 100644 --- a/src/test/java/com/asap/server/service/meeting/MeetingTimeRecommendServiceTest.java +++ b/src/test/java/com/asap/server/service/meeting/recommend/MeetingTimeRecommendServiceTest.java @@ -1,19 +1,22 @@ -package com.asap.server.service.meeting; +package com.asap.server.service.meeting.recommend; +import static com.asap.server.persistence.domain.enums.TimeSlot.*; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import com.asap.server.common.generator.TimeBlockDtoGenerator; import com.asap.server.persistence.domain.enums.Duration; import com.asap.server.persistence.repository.timeblock.dto.TimeBlockDto; +import com.asap.server.service.meeting.recommend.strategy.impl.BestMeetingTimeStrategyImpl; +import com.asap.server.service.meeting.recommend.strategy.impl.ContinuousMeetingTimeStrategyImpl; +import com.asap.server.service.meeting.recommend.strategy.impl.MeetingTimeCasesStrategyImpl; import com.asap.server.service.vo.BestMeetingTimeVo; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import java.time.LocalDate; import java.util.ArrayList; import java.util.Arrays; import java.util.List; - -import static com.asap.server.persistence.domain.enums.TimeSlot.*; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; class MeetingTimeRecommendServiceTest { private MeetingTimeRecommendService meetingTimeRecommendService; @@ -21,8 +24,9 @@ class MeetingTimeRecommendServiceTest { @BeforeEach public void setUp() { meetingTimeRecommendService = new MeetingTimeRecommendService( - new FindBestMeetingTimeCasesStrategy(), - new FindBestMeetingTimeStrategy() + new MeetingTimeCasesStrategyImpl(), + new ContinuousMeetingTimeStrategyImpl(), + new BestMeetingTimeStrategyImpl() ); } @@ -32,7 +36,7 @@ public void getBestMeetingTime() { // given LocalDate availableDate = LocalDate.of(2023, 7, 10); TimeBlockDto timeBlock = new TimeBlockDto(availableDate, SLOT_12_00, 0, 1L); - List timeBlocks = new ArrayList<>(Arrays.asList(timeBlock)); + List timeBlocks = List.of(timeBlock); BestMeetingTimeVo expected = new BestMeetingTimeVo(availableDate, SLOT_12_00, SLOT_12_30, 0); @@ -52,15 +56,15 @@ public void getBestMeetingTime2() { TimeBlockDto timeBlock = new TimeBlockDto(availableDate, SLOT_12_00, 0, 1L); TimeBlockDto timeBlock2 = new TimeBlockDto(availableDate2, SLOT_12_30, 0, 1L); - List timeBlocks = new ArrayList<>(Arrays.asList(timeBlock, timeBlock2)); + List timeBlocks = List.of(timeBlock, timeBlock2); BestMeetingTimeVo e1 = new BestMeetingTimeVo(availableDate, SLOT_12_00, SLOT_12_30, 0); BestMeetingTimeVo e2 = new BestMeetingTimeVo(availableDate2, SLOT_12_30, SLOT_13_00, 0); List expected = Arrays.asList(e1, e2, null); // when - List bestMeetingTimes = meetingTimeRecommendService.getBestMeetingTime(timeBlocks, - Duration.HALF, 1); + List bestMeetingTimes = meetingTimeRecommendService + .getBestMeetingTime(timeBlocks, Duration.HALF, 1); // then assertThat(bestMeetingTimes).isEqualTo(expected); @@ -74,19 +78,19 @@ public void getBestMeetingTime3() { LocalDate availableDate2 = LocalDate.of(2023, 7, 11); TimeBlockDto timeBlock = new TimeBlockDto(availableDate, SLOT_12_00, 0, 2L); - TimeBlockDto timeBlock2 = new TimeBlockDto(availableDate, SLOT_12_30, 0, 2L); + TimeBlockDto timeBlock2 = new TimeBlockDto(availableDate, SLOT_13_00, 0, 2L); TimeBlockDto timeBlock3 = new TimeBlockDto(availableDate2, SLOT_12_30, 0, 2L); TimeBlockDto timeBlock4 = new TimeBlockDto(availableDate2, SLOT_13_00, 0, 2L); - List timeBlocks = new ArrayList<>(Arrays.asList(timeBlock, timeBlock2, timeBlock3, timeBlock4)); + List timeBlocks = List.of(timeBlock, timeBlock2, timeBlock3, timeBlock4); BestMeetingTimeVo e1 = new BestMeetingTimeVo(availableDate, SLOT_12_00, SLOT_12_30, 0); - BestMeetingTimeVo e2 = new BestMeetingTimeVo(availableDate, SLOT_12_30, SLOT_13_00, 0); + BestMeetingTimeVo e2 = new BestMeetingTimeVo(availableDate, SLOT_13_00, SLOT_13_30, 0); BestMeetingTimeVo e3 = new BestMeetingTimeVo(availableDate2, SLOT_12_30, SLOT_13_00, 0); - List expected = Arrays.asList(e1, e2, e3); + List expected = List.of(e1, e2, e3); // when - List bestMeetingTimes = meetingTimeRecommendService.getBestMeetingTime(timeBlocks, - Duration.HALF, 2); + List bestMeetingTimes = meetingTimeRecommendService + .getBestMeetingTime(timeBlocks, Duration.HALF, 2); // then assertThat(bestMeetingTimes).isEqualTo(expected); @@ -103,16 +107,16 @@ public void getBestMeetingTime4() { TimeBlockDto timeBlock2 = new TimeBlockDto(availableDate, SLOT_12_30, 0, 2L); TimeBlockDto timeBlock3 = new TimeBlockDto(availableDate2, SLOT_12_30, 0, 2L); TimeBlockDto timeBlock4 = new TimeBlockDto(availableDate2, SLOT_13_00, 0, 2L); - List timeBlocks = new ArrayList<>(Arrays.asList(timeBlock, timeBlock2, timeBlock3, timeBlock4)); + List timeBlocks = List.of(timeBlock, timeBlock2, timeBlock3, timeBlock4); BestMeetingTimeVo e1 = new BestMeetingTimeVo(availableDate, SLOT_12_00, SLOT_13_00, 0); BestMeetingTimeVo e2 = new BestMeetingTimeVo(availableDate2, SLOT_12_30, SLOT_13_30, 0); BestMeetingTimeVo e3 = new BestMeetingTimeVo(availableDate, SLOT_12_00, SLOT_12_30, 0); - List expected = Arrays.asList(e1, e2, e3); + List expected = List.of(e1, e2, e3); // when - List bestMeetingTimes = meetingTimeRecommendService.getBestMeetingTime(timeBlocks, - Duration.HOUR, 2); + List bestMeetingTimes = meetingTimeRecommendService + .getBestMeetingTime(timeBlocks, Duration.HOUR, 2); // then assertThat(bestMeetingTimes).isEqualTo(expected); @@ -125,26 +129,23 @@ public void getBestMeetingTime5() { LocalDate availableDate = LocalDate.of(2023, 7, 10); LocalDate availableDate2 = LocalDate.of(2023, 7, 11); - TimeBlockDto timeBlock = new TimeBlockDto(availableDate, SLOT_12_00, 0, 2L); - TimeBlockDto timeBlock2 = new TimeBlockDto(availableDate, SLOT_12_30, 0, 2L); - TimeBlockDto timeBlock3 = new TimeBlockDto(availableDate, SLOT_13_00, 0, 2L); - TimeBlockDto timeBlock4 = new TimeBlockDto(availableDate, SLOT_13_30, 0, 2L); - TimeBlockDto timeBlock5 = new TimeBlockDto(availableDate2, SLOT_12_30, 0, 2L); - TimeBlockDto timeBlock6 = new TimeBlockDto(availableDate2, SLOT_13_00, 6, 2L); - TimeBlockDto timeBlock7 = new TimeBlockDto(availableDate2, SLOT_13_30, 6, 2L); - TimeBlockDto timeBlock8 = new TimeBlockDto(availableDate2, SLOT_14_00, 6, 2L); - List timeBlocks = new ArrayList<>( - Arrays.asList(timeBlock, timeBlock2, timeBlock3, timeBlock4, timeBlock5, timeBlock6, timeBlock7, - timeBlock8)); - - BestMeetingTimeVo e1 = new BestMeetingTimeVo(availableDate2, SLOT_13_00, SLOT_14_30, 18); - BestMeetingTimeVo e2 = new BestMeetingTimeVo(availableDate2, SLOT_12_30, SLOT_14_00, 12); - BestMeetingTimeVo e3 = new BestMeetingTimeVo(availableDate, SLOT_12_00, SLOT_13_30, 0); + List tempTimeBlocks = TimeBlockDtoGenerator + .generator(availableDate, SLOT_12_00, SLOT_15_30, 0, 2L); + List tempTimeBlocks2 = TimeBlockDtoGenerator + .generator(availableDate2, SLOT_12_30, SLOT_13_00, 6, 2L); + List timeBlocks = new ArrayList<>() {{ + addAll(tempTimeBlocks); + addAll(tempTimeBlocks2); + }}; + + BestMeetingTimeVo e1 = new BestMeetingTimeVo(availableDate2, SLOT_12_30, SLOT_13_30, 6); + BestMeetingTimeVo e2 = new BestMeetingTimeVo(availableDate, SLOT_12_00, SLOT_13_00, 0); + BestMeetingTimeVo e3 = new BestMeetingTimeVo(availableDate, SLOT_15_00, SLOT_16_00, 0); List expected = Arrays.asList(e1, e2, e3); // when - List bestMeetingTimes = meetingTimeRecommendService.getBestMeetingTime(timeBlocks, - Duration.HOUR_HALF, 2); + List bestMeetingTimes = meetingTimeRecommendService + .getBestMeetingTime(timeBlocks, Duration.HOUR, 2); // then assertThat(bestMeetingTimes).isEqualTo(expected); @@ -156,8 +157,8 @@ public void getBestMeetingTime6() { // given LocalDate availableDate = LocalDate.of(2023, 7, 10); - TimeBlockDto timeBlock = new TimeBlockDto(availableDate, SLOT_12_00, 0, 1L); - List timeBlocks = new ArrayList<>(Arrays.asList(timeBlock)); + TimeBlockDto timeBlock = new TimeBlockDto(availableDate, SLOT_12_00, 0, 2L); + List timeBlocks = List.of(timeBlock); BestMeetingTimeVo e1 = new BestMeetingTimeVo(availableDate, SLOT_12_00, SLOT_12_30, 0); List expected = Arrays.asList(e1, null, null); @@ -174,22 +175,23 @@ public void getBestMeetingTime6() { public void getBestMeetingTime7() { // given LocalDate availableDate = LocalDate.of(2023, 7, 10); + LocalDate availableDate2 = LocalDate.of(2023, 7, 11); + LocalDate availableDate3 = LocalDate.of(2023, 7, 12); TimeBlockDto timeBlock = new TimeBlockDto(availableDate, SLOT_12_00, 3, 3L); - TimeBlockDto timeBlock2 = new TimeBlockDto(availableDate, SLOT_12_30, 4, 2L); - TimeBlockDto timeBlock3 = new TimeBlockDto(availableDate, SLOT_13_00, 4, 2L); - TimeBlockDto timeBlock4 = new TimeBlockDto(availableDate, SLOT_13_30, 4, 2L); - TimeBlockDto timeBlock5 = new TimeBlockDto(availableDate, SLOT_14_00, 4, 2L); - List timeBlocks = new ArrayList<>( - Arrays.asList(timeBlock, timeBlock2, timeBlock3, timeBlock4, timeBlock5)); - - BestMeetingTimeVo e1 = new BestMeetingTimeVo(availableDate, SLOT_12_00, SLOT_12_30, 3); - BestMeetingTimeVo e2 = new BestMeetingTimeVo(availableDate, SLOT_12_30, SLOT_13_00, 4); - BestMeetingTimeVo e3 = new BestMeetingTimeVo(availableDate, SLOT_13_00, SLOT_13_30, 4); + TimeBlockDto timeBlock2 = new TimeBlockDto(availableDate, SLOT_12_30, 3, 3L); + TimeBlockDto timeBlock3 = new TimeBlockDto(availableDate2, SLOT_12_00, 4, 3L); + TimeBlockDto timeBlock4 = new TimeBlockDto(availableDate3, SLOT_12_00, 4, 3L); + + List timeBlocks = List.of(timeBlock, timeBlock2, timeBlock3, timeBlock4); + + BestMeetingTimeVo e1 = new BestMeetingTimeVo(availableDate, SLOT_12_00, SLOT_13_00, 3); + BestMeetingTimeVo e2 = new BestMeetingTimeVo(availableDate2, SLOT_12_00, SLOT_12_30, 4); + BestMeetingTimeVo e3 = new BestMeetingTimeVo(availableDate3, SLOT_12_00, SLOT_12_30, 4); List expected = Arrays.asList(e1, e2, e3); // when - List result = meetingTimeRecommendService.getBestMeetingTime(timeBlocks, Duration.HALF, 3); + List result = meetingTimeRecommendService.getBestMeetingTime(timeBlocks, Duration.HOUR, 3); // then assertThat(result).isEqualTo(expected);