From e394dac164622fb97bf8b297484282f61663701d Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Sat, 24 Aug 2024 16:59:09 +0900 Subject: [PATCH 01/14] =?UTF-8?q?#317=20[chore]=20register=20dto=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../time/dto/{ => register}/UserMeetingScheduleRegisterDto.java | 2 +- .../service/time/dto/{ => register}/UserTimeRegisterDto.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/main/java/com/asap/server/service/time/dto/{ => register}/UserMeetingScheduleRegisterDto.java (81%) rename src/main/java/com/asap/server/service/time/dto/{ => register}/UserTimeRegisterDto.java (74%) diff --git a/src/main/java/com/asap/server/service/time/dto/UserMeetingScheduleRegisterDto.java b/src/main/java/com/asap/server/service/time/dto/register/UserMeetingScheduleRegisterDto.java similarity index 81% rename from src/main/java/com/asap/server/service/time/dto/UserMeetingScheduleRegisterDto.java rename to src/main/java/com/asap/server/service/time/dto/register/UserMeetingScheduleRegisterDto.java index cc08d525..f51031b2 100644 --- a/src/main/java/com/asap/server/service/time/dto/UserMeetingScheduleRegisterDto.java +++ b/src/main/java/com/asap/server/service/time/dto/register/UserMeetingScheduleRegisterDto.java @@ -1,4 +1,4 @@ -package com.asap.server.service.time.dto; +package com.asap.server.service.time.dto.register; import com.asap.server.persistence.domain.enums.TimeSlot; diff --git a/src/main/java/com/asap/server/service/time/dto/UserTimeRegisterDto.java b/src/main/java/com/asap/server/service/time/dto/register/UserTimeRegisterDto.java similarity index 74% rename from src/main/java/com/asap/server/service/time/dto/UserTimeRegisterDto.java rename to src/main/java/com/asap/server/service/time/dto/register/UserTimeRegisterDto.java index c156df25..dde9f91e 100644 --- a/src/main/java/com/asap/server/service/time/dto/UserTimeRegisterDto.java +++ b/src/main/java/com/asap/server/service/time/dto/register/UserTimeRegisterDto.java @@ -1,4 +1,4 @@ -package com.asap.server.service.time.dto; +package com.asap.server.service.time.dto.register; import java.util.List; From bb6d9ef691db863a1eec519ef143baea0df26b94 Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Sat, 24 Aug 2024 16:59:59 +0900 Subject: [PATCH 02/14] =?UTF-8?q?#317=20[chore]=20register=20dto=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/dto/request/AvailableTimeRequestDto.java | 2 +- .../controller/dto/request/UserMeetingTimeSaveRequestDto.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/asap/server/presentation/controller/dto/request/AvailableTimeRequestDto.java b/src/main/java/com/asap/server/presentation/controller/dto/request/AvailableTimeRequestDto.java index b1bf75d6..03888226 100644 --- a/src/main/java/com/asap/server/presentation/controller/dto/request/AvailableTimeRequestDto.java +++ b/src/main/java/com/asap/server/presentation/controller/dto/request/AvailableTimeRequestDto.java @@ -1,6 +1,6 @@ package com.asap.server.presentation.controller.dto.request; -import com.asap.server.service.time.dto.UserTimeRegisterDto; +import com.asap.server.service.time.dto.register.UserTimeRegisterDto; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.Valid; diff --git a/src/main/java/com/asap/server/presentation/controller/dto/request/UserMeetingTimeSaveRequestDto.java b/src/main/java/com/asap/server/presentation/controller/dto/request/UserMeetingTimeSaveRequestDto.java index c039e26a..f107c5d0 100644 --- a/src/main/java/com/asap/server/presentation/controller/dto/request/UserMeetingTimeSaveRequestDto.java +++ b/src/main/java/com/asap/server/presentation/controller/dto/request/UserMeetingTimeSaveRequestDto.java @@ -1,7 +1,7 @@ package com.asap.server.presentation.controller.dto.request; import com.asap.server.persistence.domain.enums.TimeSlot; -import com.asap.server.service.time.dto.UserMeetingScheduleRegisterDto; +import com.asap.server.service.time.dto.register.UserMeetingScheduleRegisterDto; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; From cf40a1e0d7f131a897dbeb006226f213d2d00a44 Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Sat, 24 Aug 2024 17:01:10 +0900 Subject: [PATCH 03/14] #317 [feat] Response Dto Class -> record MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 코드 때문에 Builder를 없애지 못했습니다. 전체 삭제 할 때 삭제하면 좋을 것 같습니다 --- .../dto/response/AvailableDatesDto.java | 27 ++++++++----- .../controller/dto/response/TimeSlotDto.java | 40 ++++++------------- .../dto/response/TimeTableResponseDto.java | 23 ++++++----- .../server/service/TimeBlockUserService.java | 1 - .../time/UserMeetingScheduleService.java | 2 +- 5 files changed, 42 insertions(+), 51 deletions(-) diff --git a/src/main/java/com/asap/server/presentation/controller/dto/response/AvailableDatesDto.java b/src/main/java/com/asap/server/presentation/controller/dto/response/AvailableDatesDto.java index e19efb9d..894f1274 100644 --- a/src/main/java/com/asap/server/presentation/controller/dto/response/AvailableDatesDto.java +++ b/src/main/java/com/asap/server/presentation/controller/dto/response/AvailableDatesDto.java @@ -1,19 +1,24 @@ package com.asap.server.presentation.controller.dto.response; -import lombok.AllArgsConstructor; +import com.asap.server.service.time.dto.retrieve.AvailableDatesRetrieveDto; import lombok.Builder; -import lombok.Getter; -import lombok.ToString; import java.util.List; -@Getter -@ToString -@AllArgsConstructor @Builder -public class AvailableDatesDto { - private String month; - private String day; - private String dayOfWeek; - private List timeSlots; +public record AvailableDatesDto( + String month, + String day, + String dayOfWeek, + List timeSlots +) { + public static List of(final List retrieveDtos) { + return retrieveDtos.stream().map( + dto -> new AvailableDatesDto( + dto.month(), + dto.day(), + dto.dayOfWeek(), + TimeSlotDto.of(dto.timeSlots()) + )).toList(); + } } diff --git a/src/main/java/com/asap/server/presentation/controller/dto/response/TimeSlotDto.java b/src/main/java/com/asap/server/presentation/controller/dto/response/TimeSlotDto.java index 71715ee4..3c2f9677 100644 --- a/src/main/java/com/asap/server/presentation/controller/dto/response/TimeSlotDto.java +++ b/src/main/java/com/asap/server/presentation/controller/dto/response/TimeSlotDto.java @@ -1,35 +1,19 @@ package com.asap.server.presentation.controller.dto.response; -import lombok.AllArgsConstructor; +import com.asap.server.service.time.dto.retrieve.TimeSlotRetrieveDto; import lombok.Builder; -import lombok.Getter; -import lombok.ToString; import java.util.List; -@Getter -@ToString -@AllArgsConstructor -@Builder -public class TimeSlotDto { - private String time; - private List userNames; - private int colorLevel; - - public void setColorLevel(final int memberCount) { - double ratio = (double) userNames.size() / memberCount; - if (ratio <= 0.2) { - this.colorLevel = 1; - } else if (ratio <= 0.4) { - this.colorLevel = 2; - } else if (ratio <= 0.6) { - this.colorLevel = 3; - } else if (ratio <= 0.8) { - this.colorLevel = 4; - } else if (ratio <= 1.0) { - this.colorLevel = 5; - } else { - this.colorLevel = 0; - } +@Builder +public record TimeSlotDto ( + String time, + List userNames, + int colorLevel +) { + public static List of(List retrieveDtos) { + return retrieveDtos.stream().map( + dto -> new TimeSlotDto(dto.time(), dto.userNames(), dto.colorLevel()) + ).toList(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/asap/server/presentation/controller/dto/response/TimeTableResponseDto.java b/src/main/java/com/asap/server/presentation/controller/dto/response/TimeTableResponseDto.java index 6e0bf1fc..dd855d66 100644 --- a/src/main/java/com/asap/server/presentation/controller/dto/response/TimeTableResponseDto.java +++ b/src/main/java/com/asap/server/presentation/controller/dto/response/TimeTableResponseDto.java @@ -1,17 +1,20 @@ package com.asap.server.presentation.controller.dto.response; -import lombok.AllArgsConstructor; +import com.asap.server.service.time.dto.retrieve.TimeTableRetrieveDto; import lombok.Builder; -import lombok.Getter; -import lombok.ToString; import java.util.List; -@Getter + @Builder -@ToString -@AllArgsConstructor -public class TimeTableResponseDto { - public int memberCount; - public List totalUserNames; - private List availableDateTimes; +public record TimeTableResponseDto( + int memberCount, + List totalUserNames, + List availableDateTimes +) { + public static TimeTableResponseDto of(final TimeTableRetrieveDto retrieveDto) { + return new TimeTableResponseDto( + retrieveDto.memberCount(), + retrieveDto.totalUserNames(), + AvailableDatesDto.of(retrieveDto.availableDateTimes())); + } } diff --git a/src/main/java/com/asap/server/service/TimeBlockUserService.java b/src/main/java/com/asap/server/service/TimeBlockUserService.java index 77f6567d..eeffb8f9 100644 --- a/src/main/java/com/asap/server/service/TimeBlockUserService.java +++ b/src/main/java/com/asap/server/service/TimeBlockUserService.java @@ -39,7 +39,6 @@ public TimeSlotDto getTimeSlotDto(final TimeBlock timeBlock, final int memberCou .time(timeBlock.getTimeSlot().getTime()) .userNames(findUsersByTimeBlock(timeBlock).stream().map(User::getName).collect(Collectors.toList())) .build(); - timeSlotDto.setColorLevel(memberCount); return timeSlotDto; } diff --git a/src/main/java/com/asap/server/service/time/UserMeetingScheduleService.java b/src/main/java/com/asap/server/service/time/UserMeetingScheduleService.java index b86f9830..e8400c1e 100644 --- a/src/main/java/com/asap/server/service/time/UserMeetingScheduleService.java +++ b/src/main/java/com/asap/server/service/time/UserMeetingScheduleService.java @@ -4,7 +4,7 @@ import com.asap.server.persistence.domain.enums.TimeSlot; import com.asap.server.persistence.domain.time.UserMeetingSchedule; import com.asap.server.persistence.repository.UserMeetingScheduleRepository; -import com.asap.server.service.time.dto.UserMeetingScheduleRegisterDto; +import com.asap.server.service.time.dto.register.UserMeetingScheduleRegisterDto; import com.asap.server.service.time.vo.TimeBlockVo; import com.asap.server.service.time.vo.UserScheduleByTimeSlotVo; import com.asap.server.service.time.vo.UserScheduleByTimeSlotVo.CompositeKey; From 35c020410329f50938102a1427ffd467dfbc1086 Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Sat, 24 Aug 2024 17:01:42 +0900 Subject: [PATCH 04/14] =?UTF-8?q?#317=20[feat]=20retrieve=20dto=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../retrieve/AvailableDatesRetrieveDto.java | 21 +++++++++++++++++++ .../dto/retrieve/TimeSlotRetrieveDto.java | 10 +++++++++ .../dto/retrieve/TimeTableRetrieveDto.java | 14 +++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 src/main/java/com/asap/server/service/time/dto/retrieve/AvailableDatesRetrieveDto.java create mode 100644 src/main/java/com/asap/server/service/time/dto/retrieve/TimeSlotRetrieveDto.java create mode 100644 src/main/java/com/asap/server/service/time/dto/retrieve/TimeTableRetrieveDto.java diff --git a/src/main/java/com/asap/server/service/time/dto/retrieve/AvailableDatesRetrieveDto.java b/src/main/java/com/asap/server/service/time/dto/retrieve/AvailableDatesRetrieveDto.java new file mode 100644 index 00000000..3530f4dd --- /dev/null +++ b/src/main/java/com/asap/server/service/time/dto/retrieve/AvailableDatesRetrieveDto.java @@ -0,0 +1,21 @@ +package com.asap.server.service.time.dto.retrieve; + +import com.asap.server.common.utils.DateUtil; + +import java.time.LocalDate; +import java.util.List; + +public record AvailableDatesRetrieveDto( + String month, + String day, + String dayOfWeek, + List timeSlots +) { + public static AvailableDatesRetrieveDto of(final LocalDate date, final List timeSlots) { + return new AvailableDatesRetrieveDto( + DateUtil.getMonth(date), + DateUtil.getDay(date), + DateUtil.getDayOfWeek(date), + timeSlots); + } +} diff --git a/src/main/java/com/asap/server/service/time/dto/retrieve/TimeSlotRetrieveDto.java b/src/main/java/com/asap/server/service/time/dto/retrieve/TimeSlotRetrieveDto.java new file mode 100644 index 00000000..2f039452 --- /dev/null +++ b/src/main/java/com/asap/server/service/time/dto/retrieve/TimeSlotRetrieveDto.java @@ -0,0 +1,10 @@ +package com.asap.server.service.time.dto.retrieve; + +import java.util.List; + +public record TimeSlotRetrieveDto( + String time, + List userNames, + int colorLevel +) { +} \ No newline at end of file diff --git a/src/main/java/com/asap/server/service/time/dto/retrieve/TimeTableRetrieveDto.java b/src/main/java/com/asap/server/service/time/dto/retrieve/TimeTableRetrieveDto.java new file mode 100644 index 00000000..66463ddb --- /dev/null +++ b/src/main/java/com/asap/server/service/time/dto/retrieve/TimeTableRetrieveDto.java @@ -0,0 +1,14 @@ +package com.asap.server.service.time.dto.retrieve; + + +import java.util.List; + +public record TimeTableRetrieveDto( + int memberCount, + List totalUserNames, + List availableDateTimes +) { + public static TimeTableRetrieveDto of(final List totalUserNames, final List availableDateTimes) { + return new TimeTableRetrieveDto(totalUserNames.size(), totalUserNames, availableDateTimes); + } +} From fce20b5e3c161186836ba1ca334c5ac4cfaaf3b7 Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Sat, 24 Aug 2024 17:02:55 +0900 Subject: [PATCH 05/14] =?UTF-8?q?#317=20[feat]=20=EC=A2=85=ED=95=A9=20?= =?UTF-8?q?=EC=9D=BC=EC=A0=95=20=EC=8B=9C=EA=B0=84=ED=91=9C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/user/UserRepository.java | 2 + .../meeting/MeetingRetrieveController.java | 5 +- .../meeting/MeetingRetrieveService.java | 71 +++++++++++++++++++ .../service/user/UserRetrieveService.java | 11 +++ 4 files changed, 88 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/asap/server/persistence/repository/user/UserRepository.java b/src/main/java/com/asap/server/persistence/repository/user/UserRepository.java index d0d8dba1..771357e4 100644 --- a/src/main/java/com/asap/server/persistence/repository/user/UserRepository.java +++ b/src/main/java/com/asap/server/persistence/repository/user/UserRepository.java @@ -14,6 +14,8 @@ public interface UserRepository extends Repository, UserRepositoryCu Optional findById(final Long id); + List findAllByIdIn(final List ids); + List findByMeeting(final Meeting meeting); int countByMeeting(final Meeting meeting); diff --git a/src/main/java/com/asap/server/presentation/controller/meeting/MeetingRetrieveController.java b/src/main/java/com/asap/server/presentation/controller/meeting/MeetingRetrieveController.java index e89302af..4ddfe726 100644 --- a/src/main/java/com/asap/server/presentation/controller/meeting/MeetingRetrieveController.java +++ b/src/main/java/com/asap/server/presentation/controller/meeting/MeetingRetrieveController.java @@ -52,7 +52,10 @@ public SuccessResponse getTimeTable( @MeetingPathVariable final Long meetingId, @UserId final Long userId ) { - return SuccessResponse.success(Success.FIND_TIME_TABLE_SUCCESS, meetingService.getTimeTable(userId, meetingId)); + return SuccessResponse.success( + Success.FIND_TIME_TABLE_SUCCESS, + TimeTableResponseDto.of(meetingRetrieveService.getTimeTable(userId, meetingId)) + ); } @GetMapping("/{meetingId}") diff --git a/src/main/java/com/asap/server/service/meeting/MeetingRetrieveService.java b/src/main/java/com/asap/server/service/meeting/MeetingRetrieveService.java index 9af95828..00836011 100644 --- a/src/main/java/com/asap/server/service/meeting/MeetingRetrieveService.java +++ b/src/main/java/com/asap/server/service/meeting/MeetingRetrieveService.java @@ -13,14 +13,22 @@ import com.asap.server.service.meeting.dto.UserDto; import com.asap.server.service.time.MeetingTimeRecommendService; import com.asap.server.service.time.UserMeetingScheduleService; +import com.asap.server.service.time.dto.retrieve.AvailableDatesRetrieveDto; +import com.asap.server.service.time.dto.retrieve.TimeSlotRetrieveDto; +import com.asap.server.service.time.dto.retrieve.TimeTableRetrieveDto; import com.asap.server.service.time.vo.BestMeetingTimeVo; import com.asap.server.service.time.vo.BestMeetingTimeWithUsers; import com.asap.server.service.time.vo.TimeBlockVo; import com.asap.server.service.user.UserRetrieveService; + +import java.time.LocalDate; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @@ -81,4 +89,67 @@ private BestMeetingTimeWithUsers mapToBestMeetingTimeWithUsers( userDtos ); } + + @Transactional(readOnly = true) + public TimeTableRetrieveDto getTimeTable(final Long meetingId, final Long userId) { + Meeting meeting = meetingRepository.findById(meetingId) + .orElseThrow(() -> new NotFoundException(Error.MEETING_NOT_FOUND_EXCEPTION)); + + if (!meeting.authenticateHost(userId)) { + throw new UnauthorizedException(Error.INVALID_MEETING_HOST_EXCEPTION); + } + if (meeting.isConfirmedMeeting()) { + throw new ConflictException(MEETING_VALIDATION_FAILED_EXCEPTION); + } + + List userNames = userRetrieveService.getUsersFromMeetingId(meetingId).stream().map(User::getName).toList(); + + return TimeTableRetrieveDto.of(userNames, getAvailableDatesDto(meetingId, userNames.size())); + + } + + private List getAvailableDatesDto(final Long meetingId, final int totalUserCount) { + List timeBlockVos = userMeetingScheduleService.getTimeBlocks(meetingId); + + Map> timeSlotDtoMappedByDate = getTimeTableMapFromTimeBlockVo(timeBlockVos, totalUserCount); + + return timeSlotDtoMappedByDate.keySet().stream().map( + date -> AvailableDatesRetrieveDto.of( + date, + timeSlotDtoMappedByDate.get(date) + ) + ).toList(); + } + + private Map> getTimeTableMapFromTimeBlockVo(final List timeBlockVo, final int totalUserCount) { + return timeBlockVo.stream() + .collect(Collectors.groupingBy( + TimeBlockVo::availableDate, + Collectors.mapping(t -> new TimeSlotRetrieveDto( + t.timeSlot().getTime(), + userRetrieveService.getUserNamesFromId(t.userIds()), + setColorLevel(totalUserCount, t.userIds().size()) + ), + Collectors.toList() + ) + )); + } + + public int setColorLevel(final int memberCount, final int availableUserCount) { + double ratio = (double) availableUserCount / memberCount; + + if (ratio <= 0.2) { + return 1; + } else if (ratio <= 0.4) { + return 2; + } else if (ratio <= 0.6) { + return 3; + } else if (ratio <= 0.8) { + return 4; + } else if (ratio <= 1.0) { + return 5; + } else { + return 0; + } + } } diff --git a/src/main/java/com/asap/server/service/user/UserRetrieveService.java b/src/main/java/com/asap/server/service/user/UserRetrieveService.java index 6d4afa78..0de490ae 100644 --- a/src/main/java/com/asap/server/service/user/UserRetrieveService.java +++ b/src/main/java/com/asap/server/service/user/UserRetrieveService.java @@ -3,8 +3,11 @@ import com.asap.server.persistence.domain.Meeting; import com.asap.server.persistence.domain.user.User; import com.asap.server.persistence.repository.user.UserRepository; + import java.util.Map; +import java.util.List; import java.util.stream.Collectors; + import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -22,4 +25,12 @@ public Map getUserIdToUserMap(final Long meetingId) { .findAllByMeetingId(meetingId).stream() .collect(Collectors.toMap(User::getId, user -> user)); } + + public List getUserNamesFromId(final List userIds) { + return userRepository.findAllByIdIn(userIds).stream().map(User::getName).toList(); + } + + public List getUsersFromMeetingId(final Long meetingId) { + return userRepository.findAllByMeetingId(meetingId); + } } From 9e40ecf53790c37461d5007be2b9b8239048cfd1 Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Sat, 24 Aug 2024 17:03:22 +0900 Subject: [PATCH 06/14] =?UTF-8?q?#317=20[test]=20=EC=A2=85=ED=95=A9=20?= =?UTF-8?q?=EC=9D=BC=EC=A0=95=20=EC=8B=9C=EA=B0=84=ED=91=9C=20test=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meeting/MeetingRetrieveServiceTest.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/test/java/com/asap/server/service/meeting/MeetingRetrieveServiceTest.java b/src/test/java/com/asap/server/service/meeting/MeetingRetrieveServiceTest.java index 25cc970c..3dedd1ee 100644 --- a/src/test/java/com/asap/server/service/meeting/MeetingRetrieveServiceTest.java +++ b/src/test/java/com/asap/server/service/meeting/MeetingRetrieveServiceTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.mockito.Mockito.when; +import com.asap.server.common.utils.DateUtil; import com.asap.server.persistence.domain.Meeting; import com.asap.server.persistence.domain.enums.Duration; import com.asap.server.persistence.domain.enums.TimeSlot; @@ -13,15 +14,20 @@ import com.asap.server.service.meeting.dto.UserDto; import com.asap.server.service.time.MeetingTimeRecommendService; import com.asap.server.service.time.UserMeetingScheduleService; +import com.asap.server.service.time.dto.retrieve.AvailableDatesRetrieveDto; +import com.asap.server.service.time.dto.retrieve.TimeSlotRetrieveDto; +import com.asap.server.service.time.dto.retrieve.TimeTableRetrieveDto; import com.asap.server.service.time.vo.TimeBlockVo; import com.asap.server.service.user.UserRetrieveService; import com.asap.server.service.time.vo.BestMeetingTimeVo; import com.asap.server.service.time.vo.BestMeetingTimeWithUsers; + import java.time.LocalDate; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Optional; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -247,4 +253,66 @@ void test3() { assertThat(expected).isEqualTo(result); } } + + @Nested + @DisplayName("회의 종합 일정 시간표 테스트") + class MeetingTimeTableTest { + + @Test + @DisplayName("회의 참여자 2명 중 2명이 가능한 시간대에 대해 colorLevel 5를, 1명이 가능한 시간대에 대해 1을 반환한다") + void testTimeTable() { + + // given + Meeting meeting = Meeting.builder() + .id(1L) + .host(User.builder().id(1L).build()) + .duration(Duration.HALF) + .build(); + User user = User.builder() + .id(1L) + .name(new Name("KWY")) + .build(); + User user2 = User.builder() + .id(2L) + .name(new Name("DSH")) + .build(); + LocalDate date = LocalDate.of(2024, 7, 9); + List timeBlocks = List.of( + new TimeBlockVo(date, TimeSlot.SLOT_12_00, 0, List.of(1L, 2L)), + new TimeBlockVo(date, TimeSlot.SLOT_13_00, 0, List.of(1L)), + new TimeBlockVo(date, TimeSlot.SLOT_14_00, 0, List.of(1L, 2L)) + ); + + when(meetingRepository.findById(1L)).thenReturn(Optional.of(meeting)); + when(userMeetingScheduleService.getTimeBlocks(1L)).thenReturn(timeBlocks); + when(userRetrieveService.getUsersFromMeetingId(1L)).thenReturn(List.of(user, user2)); + when(userRetrieveService.getUserNamesFromId(List.of(1L, 2L))).thenReturn(List.of(new String[]{"KWY", "DSH"})); + when(userRetrieveService.getUserNamesFromId(List.of(1L))).thenReturn(List.of(new String[]{"KWY"})); + + + List expectedTimeSlotDto = List.of( + new TimeSlotRetrieveDto("12:00", List.of("KWY", "DSH"), 5), + new TimeSlotRetrieveDto("13:00", List.of("KWY"), 3), + new TimeSlotRetrieveDto("14:00", List.of("KWY", "DSH"), 5) + ); + + List expectedAvailableDto = List.of( + new AvailableDatesRetrieveDto( + DateUtil.getMonth(date), + DateUtil.getDay(date), + DateUtil.getDayOfWeek(date), + expectedTimeSlotDto + ) + ); + TimeTableRetrieveDto expected = TimeTableRetrieveDto.of( + List.of(new String[]{"KWY", "DSH"}), + expectedAvailableDto + ); + + TimeTableRetrieveDto result = meetingRetrieveService.getTimeTable(1L, 1L); + + assertThat(expected).isEqualTo(result); + } + + } } \ No newline at end of file From 4d6a61bb87a70813aba27ea0f0f5409745042d5d Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Sat, 24 Aug 2024 17:04:30 +0900 Subject: [PATCH 07/14] =?UTF-8?q?#317=20[fix]=20weight=20=EB=B0=98?= =?UTF-8?q?=EC=98=81=20=EC=95=88=EB=90=A8=20=EC=98=A4=EB=A5=98=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/time/UserMeetingScheduleService.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/asap/server/service/time/UserMeetingScheduleService.java b/src/main/java/com/asap/server/service/time/UserMeetingScheduleService.java index e8400c1e..8636c733 100644 --- a/src/main/java/com/asap/server/service/time/UserMeetingScheduleService.java +++ b/src/main/java/com/asap/server/service/time/UserMeetingScheduleService.java @@ -8,13 +8,14 @@ import com.asap.server.service.time.vo.TimeBlockVo; import com.asap.server.service.time.vo.UserScheduleByTimeSlotVo; import com.asap.server.service.time.vo.UserScheduleByTimeSlotVo.CompositeKey; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + import java.util.List; import java.util.Map.Entry; import java.util.stream.Collectors; import java.util.stream.Stream; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @@ -33,6 +34,7 @@ public void createUserMeetingSchedule( .availableDate(DateUtil.transformLocalDate(registerDto.month(), registerDto.day())) .startTimeSlot(registerDto.startTime()) .endTimeSlot(registerDto.endTime()) + .weight(registerDto.priority()) .build(); userMeetingScheduleRepository.save(userMeetingSchedule); } From e051ed44c6f63a8a65a883437ff5805c49f66e88 Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Sat, 24 Aug 2024 17:12:33 +0900 Subject: [PATCH 08/14] =?UTF-8?q?#317=20[chore]=20register=20dto=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/asap/server/service/UserService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/asap/server/service/UserService.java b/src/main/java/com/asap/server/service/UserService.java index 4e1883b2..c9e52254 100644 --- a/src/main/java/com/asap/server/service/UserService.java +++ b/src/main/java/com/asap/server/service/UserService.java @@ -21,8 +21,8 @@ import com.asap.server.presentation.controller.dto.response.UserMeetingTimeResponseDto; import com.asap.server.presentation.controller.dto.response.UserTimeResponseDto; import com.asap.server.service.time.UserMeetingScheduleService; -import com.asap.server.service.time.dto.UserMeetingScheduleRegisterDto; -import com.asap.server.service.time.dto.UserTimeRegisterDto; +import com.asap.server.service.time.dto.register.UserMeetingScheduleRegisterDto; +import com.asap.server.service.time.dto.register.UserTimeRegisterDto; import java.util.HashMap; import java.util.List; import java.util.Map; From cf752a874f816fbee46f4e997fc97c49be612aa3 Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Sat, 24 Aug 2024 20:50:48 +0900 Subject: [PATCH 09/14] =?UTF-8?q?#317=20[test]=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meeting/MeetingRetrieveServiceTest.java | 45 +++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/test/java/com/asap/server/service/meeting/MeetingRetrieveServiceTest.java b/src/test/java/com/asap/server/service/meeting/MeetingRetrieveServiceTest.java index 3dedd1ee..26222885 100644 --- a/src/test/java/com/asap/server/service/meeting/MeetingRetrieveServiceTest.java +++ b/src/test/java/com/asap/server/service/meeting/MeetingRetrieveServiceTest.java @@ -15,7 +15,7 @@ import com.asap.server.service.time.MeetingTimeRecommendService; import com.asap.server.service.time.UserMeetingScheduleService; import com.asap.server.service.time.dto.retrieve.AvailableDatesRetrieveDto; -import com.asap.server.service.time.dto.retrieve.TimeSlotRetrieveDto; +import com.asap.server.service.time.dto.retrieve.TimeBlockRetrieveDto; import com.asap.server.service.time.dto.retrieve.TimeTableRetrieveDto; import com.asap.server.service.time.vo.TimeBlockVo; import com.asap.server.service.user.UserRetrieveService; @@ -276,24 +276,43 @@ void testTimeTable() { .id(2L) .name(new Name("DSH")) .build(); + User user3 = User.builder() + .id(3L) + .name(new Name("SJW")) + .build(); + User user4 = User.builder() + .id(4L) + .name(new Name("SCW")) + .build(); + User user5 = User.builder() + .id(5L) + .name(new Name("KTH")) + .build(); LocalDate date = LocalDate.of(2024, 7, 9); List timeBlocks = List.of( - new TimeBlockVo(date, TimeSlot.SLOT_12_00, 0, List.of(1L, 2L)), - new TimeBlockVo(date, TimeSlot.SLOT_13_00, 0, List.of(1L)), - new TimeBlockVo(date, TimeSlot.SLOT_14_00, 0, List.of(1L, 2L)) + new TimeBlockVo(date, TimeSlot.SLOT_12_00, 0, List.of(1L, 2L, 3L, 4L, 5L)), + new TimeBlockVo(date, TimeSlot.SLOT_13_00, 0, List.of(1L, 2L, 3L, 4L)), + new TimeBlockVo(date, TimeSlot.SLOT_14_00, 0, List.of(1L, 2L, 3L)), + new TimeBlockVo(date, TimeSlot.SLOT_15_00, 0, List.of(1L, 2L)), + new TimeBlockVo(date, TimeSlot.SLOT_16_00, 0, List.of(1L)) ); when(meetingRepository.findById(1L)).thenReturn(Optional.of(meeting)); when(userMeetingScheduleService.getTimeBlocks(1L)).thenReturn(timeBlocks); - when(userRetrieveService.getUsersFromMeetingId(1L)).thenReturn(List.of(user, user2)); - when(userRetrieveService.getUserNamesFromId(List.of(1L, 2L))).thenReturn(List.of(new String[]{"KWY", "DSH"})); - when(userRetrieveService.getUserNamesFromId(List.of(1L))).thenReturn(List.of(new String[]{"KWY"})); + when(userRetrieveService.getUsersFromMeetingId(1L)).thenReturn(List.of(user, user2, user3, user4, user5)); + when(userRetrieveService.getUserNamesFromId(List.of(1L, 2L, 3L, 4L, 5L))).thenReturn(List.of("KWY", "DSH", "SJW", "SCW", "KTH")); + when(userRetrieveService.getUserNamesFromId(List.of(1L, 2L, 3L, 4L))).thenReturn(List.of("KWY", "DSH", "SJW", "SCW")); + when(userRetrieveService.getUserNamesFromId(List.of(1L, 2L, 3L))).thenReturn(List.of("KWY", "DSH", "SJW")); + when(userRetrieveService.getUserNamesFromId(List.of(1L, 2L))).thenReturn(List.of("KWY", "DSH")); + when(userRetrieveService.getUserNamesFromId(List.of(1L))).thenReturn(List.of("KWY")); - List expectedTimeSlotDto = List.of( - new TimeSlotRetrieveDto("12:00", List.of("KWY", "DSH"), 5), - new TimeSlotRetrieveDto("13:00", List.of("KWY"), 3), - new TimeSlotRetrieveDto("14:00", List.of("KWY", "DSH"), 5) + List expectedTimeSlotDto = List.of( + new TimeBlockRetrieveDto("12:00", List.of("KWY", "DSH", "SJW", "SCW", "KTH"), 5), + new TimeBlockRetrieveDto("13:00", List.of("KWY", "DSH", "SJW", "SCW"), 4), + new TimeBlockRetrieveDto("14:00", List.of("KWY", "DSH", "SJW"), 3), + new TimeBlockRetrieveDto("15:00", List.of("KWY", "DSH"), 2), + new TimeBlockRetrieveDto("16:00", List.of("KWY"), 1) ); List expectedAvailableDto = List.of( @@ -305,13 +324,13 @@ void testTimeTable() { ) ); TimeTableRetrieveDto expected = TimeTableRetrieveDto.of( - List.of(new String[]{"KWY", "DSH"}), + List.of("KWY", "DSH", "SJW", "SCW", "KTH"), expectedAvailableDto ); TimeTableRetrieveDto result = meetingRetrieveService.getTimeTable(1L, 1L); - assertThat(expected).isEqualTo(result); + assertThat(result).isEqualTo(expected); } } From 17737551a385c6a7985b5af260ba7384d3815595 Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Sat, 24 Aug 2024 20:51:18 +0900 Subject: [PATCH 10/14] =?UTF-8?q?#317=20[refactor]=20TimeSlotRetrieve=20->?= =?UTF-8?q?=20TimeBlock=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 --- .../controller/dto/response/TimeSlotDto.java | 4 ++-- .../service/meeting/MeetingRetrieveService.java | 16 +++++++++------- .../dto/retrieve/AvailableDatesRetrieveDto.java | 4 ++-- ...etrieveDto.java => TimeBlockRetrieveDto.java} | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) rename src/main/java/com/asap/server/service/time/dto/retrieve/{TimeSlotRetrieveDto.java => TimeBlockRetrieveDto.java} (81%) diff --git a/src/main/java/com/asap/server/presentation/controller/dto/response/TimeSlotDto.java b/src/main/java/com/asap/server/presentation/controller/dto/response/TimeSlotDto.java index 3c2f9677..e29fd09b 100644 --- a/src/main/java/com/asap/server/presentation/controller/dto/response/TimeSlotDto.java +++ b/src/main/java/com/asap/server/presentation/controller/dto/response/TimeSlotDto.java @@ -1,6 +1,6 @@ package com.asap.server.presentation.controller.dto.response; -import com.asap.server.service.time.dto.retrieve.TimeSlotRetrieveDto; +import com.asap.server.service.time.dto.retrieve.TimeBlockRetrieveDto; import lombok.Builder; import java.util.List; @@ -11,7 +11,7 @@ public record TimeSlotDto ( List userNames, int colorLevel ) { - public static List of(List retrieveDtos) { + public static List of(List retrieveDtos) { return retrieveDtos.stream().map( dto -> new TimeSlotDto(dto.time(), dto.userNames(), dto.colorLevel()) ).toList(); diff --git a/src/main/java/com/asap/server/service/meeting/MeetingRetrieveService.java b/src/main/java/com/asap/server/service/meeting/MeetingRetrieveService.java index 00836011..dda14ca7 100644 --- a/src/main/java/com/asap/server/service/meeting/MeetingRetrieveService.java +++ b/src/main/java/com/asap/server/service/meeting/MeetingRetrieveService.java @@ -14,7 +14,7 @@ import com.asap.server.service.time.MeetingTimeRecommendService; import com.asap.server.service.time.UserMeetingScheduleService; import com.asap.server.service.time.dto.retrieve.AvailableDatesRetrieveDto; -import com.asap.server.service.time.dto.retrieve.TimeSlotRetrieveDto; +import com.asap.server.service.time.dto.retrieve.TimeBlockRetrieveDto; import com.asap.server.service.time.dto.retrieve.TimeTableRetrieveDto; import com.asap.server.service.time.vo.BestMeetingTimeVo; import com.asap.server.service.time.vo.BestMeetingTimeWithUsers; @@ -27,10 +27,12 @@ import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service +@Slf4j @RequiredArgsConstructor public class MeetingRetrieveService { private final MeetingRepository meetingRepository; @@ -110,9 +112,9 @@ public TimeTableRetrieveDto getTimeTable(final Long meetingId, final Long userId private List getAvailableDatesDto(final Long meetingId, final int totalUserCount) { List timeBlockVos = userMeetingScheduleService.getTimeBlocks(meetingId); - - Map> timeSlotDtoMappedByDate = getTimeTableMapFromTimeBlockVo(timeBlockVos, totalUserCount); - + log.info("Query----- Start"); + Map> timeSlotDtoMappedByDate = getTimeTableMapFromTimeBlockVo(timeBlockVos, totalUserCount); + log.info("Query----- Start"); return timeSlotDtoMappedByDate.keySet().stream().map( date -> AvailableDatesRetrieveDto.of( date, @@ -121,11 +123,11 @@ private List getAvailableDatesDto(final Long meetingI ).toList(); } - private Map> getTimeTableMapFromTimeBlockVo(final List timeBlockVo, final int totalUserCount) { + private Map> getTimeTableMapFromTimeBlockVo(final List timeBlockVo, final int totalUserCount) { return timeBlockVo.stream() .collect(Collectors.groupingBy( TimeBlockVo::availableDate, - Collectors.mapping(t -> new TimeSlotRetrieveDto( + Collectors.mapping(t -> new TimeBlockRetrieveDto( t.timeSlot().getTime(), userRetrieveService.getUserNamesFromId(t.userIds()), setColorLevel(totalUserCount, t.userIds().size()) @@ -135,7 +137,7 @@ private Map> getTimeTableMapFromTimeBlockVo )); } - public int setColorLevel(final int memberCount, final int availableUserCount) { + private int setColorLevel(final int memberCount, final int availableUserCount) { double ratio = (double) availableUserCount / memberCount; if (ratio <= 0.2) { diff --git a/src/main/java/com/asap/server/service/time/dto/retrieve/AvailableDatesRetrieveDto.java b/src/main/java/com/asap/server/service/time/dto/retrieve/AvailableDatesRetrieveDto.java index 3530f4dd..8dbab20f 100644 --- a/src/main/java/com/asap/server/service/time/dto/retrieve/AvailableDatesRetrieveDto.java +++ b/src/main/java/com/asap/server/service/time/dto/retrieve/AvailableDatesRetrieveDto.java @@ -9,9 +9,9 @@ public record AvailableDatesRetrieveDto( String month, String day, String dayOfWeek, - List timeSlots + List timeSlots ) { - public static AvailableDatesRetrieveDto of(final LocalDate date, final List timeSlots) { + public static AvailableDatesRetrieveDto of(final LocalDate date, final List timeSlots) { return new AvailableDatesRetrieveDto( DateUtil.getMonth(date), DateUtil.getDay(date), diff --git a/src/main/java/com/asap/server/service/time/dto/retrieve/TimeSlotRetrieveDto.java b/src/main/java/com/asap/server/service/time/dto/retrieve/TimeBlockRetrieveDto.java similarity index 81% rename from src/main/java/com/asap/server/service/time/dto/retrieve/TimeSlotRetrieveDto.java rename to src/main/java/com/asap/server/service/time/dto/retrieve/TimeBlockRetrieveDto.java index 2f039452..c9008fa0 100644 --- a/src/main/java/com/asap/server/service/time/dto/retrieve/TimeSlotRetrieveDto.java +++ b/src/main/java/com/asap/server/service/time/dto/retrieve/TimeBlockRetrieveDto.java @@ -2,7 +2,7 @@ import java.util.List; -public record TimeSlotRetrieveDto( +public record TimeBlockRetrieveDto( String time, List userNames, int colorLevel From a5824c4295d6703b5fc518b6f898930740dfdf6d Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Sat, 24 Aug 2024 21:26:30 +0900 Subject: [PATCH 11/14] =?UTF-8?q?#317=20[feat]=20=ED=9A=8C=EC=9D=98=20?= =?UTF-8?q?=EC=B0=B8=EC=97=AC=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meeting/MeetingRetrieveService.java | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/asap/server/service/meeting/MeetingRetrieveService.java b/src/main/java/com/asap/server/service/meeting/MeetingRetrieveService.java index dda14ca7..ab0142bb 100644 --- a/src/main/java/com/asap/server/service/meeting/MeetingRetrieveService.java +++ b/src/main/java/com/asap/server/service/meeting/MeetingRetrieveService.java @@ -1,7 +1,5 @@ package com.asap.server.service.meeting; -import static com.asap.server.common.exception.Error.MEETING_VALIDATION_FAILED_EXCEPTION; - import com.asap.server.common.exception.Error; import com.asap.server.common.exception.model.ConflictException; import com.asap.server.common.exception.model.NotFoundException; @@ -20,19 +18,19 @@ import com.asap.server.service.time.vo.BestMeetingTimeWithUsers; import com.asap.server.service.time.vo.TimeBlockVo; import com.asap.server.service.user.UserRetrieveService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; +import static com.asap.server.common.exception.Error.MEETING_VALIDATION_FAILED_EXCEPTION; +import static java.util.function.Predicate.isEqual; @Service -@Slf4j @RequiredArgsConstructor public class MeetingRetrieveService { private final MeetingRepository meetingRepository; @@ -93,7 +91,7 @@ private BestMeetingTimeWithUsers mapToBestMeetingTimeWithUsers( } @Transactional(readOnly = true) - public TimeTableRetrieveDto getTimeTable(final Long meetingId, final Long userId) { + public TimeTableRetrieveDto getTimeTable(final Long userId, final Long meetingId) { Meeting meeting = meetingRepository.findById(meetingId) .orElseThrow(() -> new NotFoundException(Error.MEETING_NOT_FOUND_EXCEPTION)); @@ -103,18 +101,20 @@ public TimeTableRetrieveDto getTimeTable(final Long meetingId, final Long userId if (meeting.isConfirmedMeeting()) { throw new ConflictException(MEETING_VALIDATION_FAILED_EXCEPTION); } + Map userIdToUserMap = userRetrieveService.getUserIdToUserMap(meetingId); - List userNames = userRetrieveService.getUsersFromMeetingId(meetingId).stream().map(User::getName).toList(); + List userNames = userIdToUserMap.keySet().stream() + .sorted() + .map(id -> userIdToUserMap.get(id).getName()) + .toList(); - return TimeTableRetrieveDto.of(userNames, getAvailableDatesDto(meetingId, userNames.size())); + return TimeTableRetrieveDto.of(userNames, getAvailableDatesDto(meetingId, userNames.size(), userIdToUserMap)); } - private List getAvailableDatesDto(final Long meetingId, final int totalUserCount) { + private List getAvailableDatesDto(final Long meetingId, final int totalUserCount, final Map userIdToUserMap) { List timeBlockVos = userMeetingScheduleService.getTimeBlocks(meetingId); - log.info("Query----- Start"); - Map> timeSlotDtoMappedByDate = getTimeTableMapFromTimeBlockVo(timeBlockVos, totalUserCount); - log.info("Query----- Start"); + Map> timeSlotDtoMappedByDate = getTimeTableMapFromTimeBlockVo(timeBlockVos, totalUserCount, userIdToUserMap); return timeSlotDtoMappedByDate.keySet().stream().map( date -> AvailableDatesRetrieveDto.of( date, @@ -123,13 +123,16 @@ private List getAvailableDatesDto(final Long meetingI ).toList(); } - private Map> getTimeTableMapFromTimeBlockVo(final List timeBlockVo, final int totalUserCount) { + private Map> getTimeTableMapFromTimeBlockVo(final List timeBlockVo, final int totalUserCount, final Map userIdToUserMap) { return timeBlockVo.stream() .collect(Collectors.groupingBy( TimeBlockVo::availableDate, Collectors.mapping(t -> new TimeBlockRetrieveDto( t.timeSlot().getTime(), - userRetrieveService.getUserNamesFromId(t.userIds()), + t.userIds().stream() + .filter(userIdToUserMap::containsKey) + .map(id -> userIdToUserMap.get(id).getName()) + .toList(), setColorLevel(totalUserCount, t.userIds().size()) ), Collectors.toList() From 45813c32affab681d6f698ac30e8584645206adf Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Sat, 24 Aug 2024 21:26:48 +0900 Subject: [PATCH 12/14] =?UTF-8?q?#317=20[test]=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=20stub=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/meeting/MeetingRetrieveServiceTest.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/asap/server/service/meeting/MeetingRetrieveServiceTest.java b/src/test/java/com/asap/server/service/meeting/MeetingRetrieveServiceTest.java index 26222885..64007826 100644 --- a/src/test/java/com/asap/server/service/meeting/MeetingRetrieveServiceTest.java +++ b/src/test/java/com/asap/server/service/meeting/MeetingRetrieveServiceTest.java @@ -259,7 +259,7 @@ void test3() { class MeetingTimeTableTest { @Test - @DisplayName("회의 참여자 2명 중 2명이 가능한 시간대에 대해 colorLevel 5를, 1명이 가능한 시간대에 대해 1을 반환한다") + @DisplayName("각 참여자 수에 맞는 colorLevel을 반환한다.") void testTimeTable() { // given @@ -299,12 +299,7 @@ void testTimeTable() { when(meetingRepository.findById(1L)).thenReturn(Optional.of(meeting)); when(userMeetingScheduleService.getTimeBlocks(1L)).thenReturn(timeBlocks); - when(userRetrieveService.getUsersFromMeetingId(1L)).thenReturn(List.of(user, user2, user3, user4, user5)); - when(userRetrieveService.getUserNamesFromId(List.of(1L, 2L, 3L, 4L, 5L))).thenReturn(List.of("KWY", "DSH", "SJW", "SCW", "KTH")); - when(userRetrieveService.getUserNamesFromId(List.of(1L, 2L, 3L, 4L))).thenReturn(List.of("KWY", "DSH", "SJW", "SCW")); - when(userRetrieveService.getUserNamesFromId(List.of(1L, 2L, 3L))).thenReturn(List.of("KWY", "DSH", "SJW")); - when(userRetrieveService.getUserNamesFromId(List.of(1L, 2L))).thenReturn(List.of("KWY", "DSH")); - when(userRetrieveService.getUserNamesFromId(List.of(1L))).thenReturn(List.of("KWY")); + when(userRetrieveService.getUserIdToUserMap(1L)).thenReturn(Map.of(1L, user, 2L, user2, 3L, user3, 4L, user4, 5L, user5)); List expectedTimeSlotDto = List.of( From f8b661e194ddb243219ff2978f1acd8716793e67 Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Sat, 24 Aug 2024 21:26:59 +0900 Subject: [PATCH 13/14] =?UTF-8?q?#317=20[feat]=20=EB=AF=B8=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=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 --- .../com/asap/server/service/user/UserRetrieveService.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/java/com/asap/server/service/user/UserRetrieveService.java b/src/main/java/com/asap/server/service/user/UserRetrieveService.java index 0de490ae..3f8b4bba 100644 --- a/src/main/java/com/asap/server/service/user/UserRetrieveService.java +++ b/src/main/java/com/asap/server/service/user/UserRetrieveService.java @@ -25,12 +25,4 @@ public Map getUserIdToUserMap(final Long meetingId) { .findAllByMeetingId(meetingId).stream() .collect(Collectors.toMap(User::getId, user -> user)); } - - public List getUserNamesFromId(final List userIds) { - return userRepository.findAllByIdIn(userIds).stream().map(User::getName).toList(); - } - - public List getUsersFromMeetingId(final Long meetingId) { - return userRepository.findAllByMeetingId(meetingId); - } } From 2402bcb961ac9a2eecab3afce9defe706cf0d15e Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Sat, 24 Aug 2024 21:30:28 +0900 Subject: [PATCH 14/14] =?UTF-8?q?#317=20[refactor]=20=EB=AF=B8=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=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 --- .../asap/server/persistence/repository/user/UserRepository.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/asap/server/persistence/repository/user/UserRepository.java b/src/main/java/com/asap/server/persistence/repository/user/UserRepository.java index 771357e4..d0d8dba1 100644 --- a/src/main/java/com/asap/server/persistence/repository/user/UserRepository.java +++ b/src/main/java/com/asap/server/persistence/repository/user/UserRepository.java @@ -14,8 +14,6 @@ public interface UserRepository extends Repository, UserRepositoryCu Optional findById(final Long id); - List findAllByIdIn(final List ids); - List findByMeeting(final Meeting meeting); int countByMeeting(final Meeting meeting);