diff --git a/src/main/java/com/moabam/api/application/member/MemberService.java b/src/main/java/com/moabam/api/application/member/MemberService.java index 01b3201e..b54bdfc6 100644 --- a/src/main/java/com/moabam/api/application/member/MemberService.java +++ b/src/main/java/com/moabam/api/application/member/MemberService.java @@ -83,7 +83,7 @@ public MemberInfoResponse searchInfo(AuthMember authMember, Long memberId) { } private List getDefaultSkin(Long searchId) { - List inventories = inventorySearchRepository.findBirdsDefaultSkin(searchId); + List inventories = inventorySearchRepository.findDefaultSkin(searchId); if (inventories.size() != GlobalConstant.DEFAULT_SKIN_SIZE) { throw new BadRequestException(INVALID_DEFAULT_SKIN_SIZE); } diff --git a/src/main/java/com/moabam/api/application/room/RoomCertificationService.java b/src/main/java/com/moabam/api/application/room/CertificationService.java similarity index 70% rename from src/main/java/com/moabam/api/application/room/RoomCertificationService.java rename to src/main/java/com/moabam/api/application/room/CertificationService.java index 0c3a82c9..60d4b56d 100644 --- a/src/main/java/com/moabam/api/application/room/RoomCertificationService.java +++ b/src/main/java/com/moabam/api/application/room/CertificationService.java @@ -1,7 +1,9 @@ package com.moabam.api.application.room; -import static com.moabam.api.domain.image.ImageType.*; -import static com.moabam.global.error.model.ErrorMessage.*; +import static com.moabam.global.error.model.ErrorMessage.DUPLICATED_DAILY_MEMBER_CERTIFICATION; +import static com.moabam.global.error.model.ErrorMessage.INVALID_CERTIFY_TIME; +import static com.moabam.global.error.model.ErrorMessage.PARTICIPANT_NOT_FOUND; +import static com.moabam.global.error.model.ErrorMessage.ROUTINE_NOT_FOUND; import java.time.LocalDate; import java.time.LocalDateTime; @@ -12,9 +14,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; -import com.moabam.api.application.image.ImageService; import com.moabam.api.application.member.MemberService; import com.moabam.api.application.room.mapper.CertificationsMapper; import com.moabam.api.domain.bug.BugType; @@ -42,7 +42,9 @@ @Service @RequiredArgsConstructor @Transactional(readOnly = true) -public class RoomCertificationService { +public class CertificationService { + + private static final int REQUIRED_ROOM_CERTIFICATION = 75; private final RoutineRepository routineRepository; private final CertificationRepository certificationRepository; @@ -51,12 +53,11 @@ public class RoomCertificationService { private final DailyRoomCertificationRepository dailyRoomCertificationRepository; private final DailyMemberCertificationRepository dailyMemberCertificationRepository; private final MemberService memberService; - private final ImageService imageService; private final ClockHolder clockHolder; @Transactional - public void certifyRoom(Long memberId, Long roomId, List multipartFiles) { - LocalDate today = LocalDate.now(); + public void certifyRoom(Long memberId, Long roomId, List imageUrls) { + LocalDate today = clockHolder.date(); Participant participant = participantSearchRepository.findOne(memberId, roomId) .orElseThrow(() -> new NotFoundException(PARTICIPANT_NOT_FOUND)); Room room = participant.getRoom(); @@ -70,47 +71,17 @@ public void certifyRoom(Long memberId, Long roomId, List multipar validateCertifyTime(clockHolder.times(), room.getCertifyTime()); validateAlreadyCertified(memberId, roomId, today); - DailyMemberCertification dailyMemberCertification = CertificationsMapper.toDailyMemberCertification(memberId, - roomId, participant); - dailyMemberCertificationRepository.save(dailyMemberCertification); - - member.increaseTotalCertifyCount(); - participant.updateCertifyCount(); - - List result = imageService.uploadImages(multipartFiles, CERTIFICATION); - saveNewCertifications(result, memberId); + certifyMember(memberId, roomId, participant, member, imageUrls); Optional dailyRoomCertification = certificationsSearchRepository.findDailyRoomCertification(roomId, today); if (dailyRoomCertification.isEmpty()) { - List dailyMemberCertifications = - certificationsSearchRepository.findSortedDailyMemberCertifications(roomId, today); - double completePercentage = calculateCompletePercentage(dailyMemberCertifications.size(), - room.getCurrentUserCount()); - - if (completePercentage >= 75) { - DailyRoomCertification createDailyRoomCertification = CertificationsMapper.toDailyRoomCertification( - roomId, today); - - dailyRoomCertificationRepository.save(createDailyRoomCertification); - - int expAppliedRoomLevel = getRoomLevelAfterExpApply(roomLevel, room); - - List memberIds = dailyMemberCertifications.stream() - .map(DailyMemberCertification::getMemberId) - .toList(); - - memberService.getRoomMembers(memberIds) - .forEach(completedMember -> completedMember.getBug().increaseBug(bugType, expAppliedRoomLevel)); - - return; - } + certifyRoomIfAvailable(roomId, today, room, bugType, roomLevel); + return; } - if (dailyRoomCertification.isPresent()) { - member.getBug().increaseBug(bugType, roomLevel); - } + member.getBug().increaseBug(bugType, roomLevel); } public boolean existsMemberCertification(Long memberId, Long roomId, LocalDate date) { @@ -138,7 +109,17 @@ private void validateAlreadyCertified(Long memberId, Long roomId, LocalDate toda } } - private void saveNewCertifications(List imageUrls, Long memberId) { + private void certifyMember(Long memberId, Long roomId, Participant participant, Member member, List urls) { + DailyMemberCertification dailyMemberCertification = CertificationsMapper.toDailyMemberCertification(memberId, + roomId, participant); + dailyMemberCertificationRepository.save(dailyMemberCertification); + member.increaseTotalCertifyCount(); + participant.updateCertifyCount(); + + saveNewCertifications(memberId, urls); + } + + private void saveNewCertifications(Long memberId, List imageUrls) { List certifications = new ArrayList<>(); for (String imageUrl : imageUrls) { @@ -153,6 +134,23 @@ private void saveNewCertifications(List imageUrls, Long memberId) { certificationRepository.saveAll(certifications); } + private void certifyRoomIfAvailable(Long roomId, LocalDate today, Room room, BugType bugType, int roomLevel) { + List dailyMemberCertifications = + certificationsSearchRepository.findSortedDailyMemberCertifications(roomId, today); + double completePercentage = calculateCompletePercentage(dailyMemberCertifications.size(), + room.getCurrentUserCount()); + + if (completePercentage >= REQUIRED_ROOM_CERTIFICATION) { + DailyRoomCertification createDailyRoomCertification = CertificationsMapper.toDailyRoomCertification( + roomId, today); + + dailyRoomCertificationRepository.save(createDailyRoomCertification); + int expAppliedRoomLevel = getRoomLevelAfterExpApply(roomLevel, room); + + provideBugToCompletedMembers(bugType, dailyMemberCertifications, expAppliedRoomLevel); + } + } + private double calculateCompletePercentage(int certifiedMembersCount, int currentsMembersCount) { double completePercentage = ((double)certifiedMembersCount / currentsMembersCount) * 100; @@ -169,4 +167,14 @@ private int getRoomLevelAfterExpApply(int roomLevel, Room room) { return room.getLevel(); } + + private void provideBugToCompletedMembers(BugType bugType, List dailyMemberCertifications, + int expAppliedRoomLevel) { + List memberIds = dailyMemberCertifications.stream() + .map(DailyMemberCertification::getMemberId) + .toList(); + + memberService.getRoomMembers(memberIds) + .forEach(completedMember -> completedMember.getBug().increaseBug(bugType, expAppliedRoomLevel)); + } } diff --git a/src/main/java/com/moabam/api/application/room/RoomService.java b/src/main/java/com/moabam/api/application/room/RoomService.java index 4775031f..50592ead 100644 --- a/src/main/java/com/moabam/api/application/room/RoomService.java +++ b/src/main/java/com/moabam/api/application/room/RoomService.java @@ -1,7 +1,14 @@ package com.moabam.api.application.room; -import static com.moabam.api.domain.room.RoomType.*; -import static com.moabam.global.error.model.ErrorMessage.*; +import static com.moabam.api.domain.room.RoomType.MORNING; +import static com.moabam.api.domain.room.RoomType.NIGHT; +import static com.moabam.global.error.model.ErrorMessage.MEMBER_ROOM_EXCEED; +import static com.moabam.global.error.model.ErrorMessage.PARTICIPANT_NOT_FOUND; +import static com.moabam.global.error.model.ErrorMessage.ROOM_EXIT_MANAGER_FAIL; +import static com.moabam.global.error.model.ErrorMessage.ROOM_MAX_USER_REACHED; +import static com.moabam.global.error.model.ErrorMessage.ROOM_MODIFY_UNAUTHORIZED_REQUEST; +import static com.moabam.global.error.model.ErrorMessage.ROOM_NOT_FOUND; +import static com.moabam.global.error.model.ErrorMessage.WRONG_ROOM_PASSWORD; import java.util.List; @@ -10,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional; import com.moabam.api.application.member.MemberService; +import com.moabam.api.application.room.mapper.ParticipantMapper; import com.moabam.api.application.room.mapper.RoomMapper; import com.moabam.api.application.room.mapper.RoutineMapper; import com.moabam.api.domain.member.Member; @@ -21,7 +29,6 @@ import com.moabam.api.domain.room.repository.ParticipantSearchRepository; import com.moabam.api.domain.room.repository.RoomRepository; import com.moabam.api.domain.room.repository.RoutineRepository; -import com.moabam.api.domain.room.repository.RoutineSearchRepository; import com.moabam.api.dto.room.CreateRoomRequest; import com.moabam.api.dto.room.EnterRoomRequest; import com.moabam.api.dto.room.ModifyRoomRequest; @@ -38,7 +45,6 @@ public class RoomService { private final RoomRepository roomRepository; private final RoutineRepository routineRepository; - private final RoutineSearchRepository routineSearchRepository; private final ParticipantRepository participantRepository; private final ParticipantSearchRepository participantSearchRepository; private final MemberService memberService; @@ -47,19 +53,15 @@ public class RoomService { public Long createRoom(Long memberId, String nickname, CreateRoomRequest createRoomRequest) { Room room = RoomMapper.toRoomEntity(createRoomRequest); List routines = RoutineMapper.toRoutineEntities(room, createRoomRequest.routines()); - Participant participant = Participant.builder() - .room(room) - .memberId(memberId) - .build(); + Participant participant = ParticipantMapper.toParticipant(room, memberId); - if (!isEnterRoomAvailable(memberId, room.getRoomType())) { - throw new BadRequestException(MEMBER_ROOM_EXCEED); - } - - increaseRoomCount(memberId, room.getRoomType()); + validateEnteredRoomCount(memberId, room.getRoomType()); + Member member = memberService.getById(memberId); + member.enterRoom(room.getRoomType()); participant.enableManager(); room.changeManagerNickname(nickname); + Room savedRoom = roomRepository.save(room); routineRepository.saveAll(routines); participantRepository.save(participant); @@ -79,7 +81,7 @@ public void modifyRoom(Long memberId, Long roomId, ModifyRoomRequest modifyRoomR room.changeCertifyTime(modifyRoomRequest.certifyTime()); room.changeMaxCount(modifyRoomRequest.maxUserCount()); - List routines = routineSearchRepository.findAllByRoomId(roomId); + List routines = routineRepository.findAllByRoomId(roomId); routineRepository.deleteAll(routines); List newRoutines = RoutineMapper.toRoutineEntities(room, modifyRoomRequest.routines()); @@ -91,13 +93,11 @@ public void enterRoom(Long memberId, Long roomId, EnterRoomRequest enterRoomRequ Room room = roomRepository.findById(roomId).orElseThrow(() -> new NotFoundException(ROOM_NOT_FOUND)); validateRoomEnter(memberId, enterRoomRequest.password(), room); + Member member = memberService.getById(memberId); + member.enterRoom(room.getRoomType()); room.increaseCurrentUserCount(); - increaseRoomCount(memberId, room.getRoomType()); - Participant participant = Participant.builder() - .room(room) - .memberId(memberId) - .build(); + Participant participant = ParticipantMapper.toParticipant(room, memberId); participantRepository.save(participant); } @@ -106,11 +106,11 @@ public void exitRoom(Long memberId, Long roomId) { Participant participant = getParticipant(memberId, roomId); Room room = participant.getRoom(); - if (participant.isManager() && room.getCurrentUserCount() != 1) { - throw new BadRequestException(ROOM_EXIT_MANAGER_FAIL); - } + validateRoomExit(participant, room); + + Member member = memberService.getById(memberId); + member.exitRoom(room.getRoomType()); - decreaseRoomCount(memberId, room.getRoomType()); participant.removeRoom(); participantRepository.flush(); participantRepository.delete(participant); @@ -124,7 +124,7 @@ public void exitRoom(Long memberId, Long roomId) { } @Transactional - public void mandateRoomManager(Long managerId, Long roomId, Long memberId) { + public void mandateManager(Long managerId, Long roomId, Long memberId) { Participant managerParticipant = getParticipant(managerId, roomId); Participant memberParticipant = getParticipant(memberId, roomId); validateManagerAuthorization(managerParticipant); @@ -141,13 +141,14 @@ public void mandateRoomManager(Long managerId, Long roomId, Long memberId) { public void deportParticipant(Long managerId, Long roomId, Long memberId) { Participant managerParticipant = getParticipant(managerId, roomId); Participant memberParticipant = getParticipant(memberId, roomId); - Room room = managerParticipant.getRoom(); - validateManagerAuthorization(managerParticipant); + Room room = managerParticipant.getRoom(); participantRepository.delete(memberParticipant); room.decreaseCurrentUserCount(); - decreaseRoomCount(memberId, room.getRoomType()); + + Member member = memberService.getById(memberId); + member.exitRoom(room.getRoomType()); } public void validateRoomById(Long roomId) { @@ -168,9 +169,8 @@ private void validateManagerAuthorization(Participant participant) { } private void validateRoomEnter(Long memberId, String requestPassword, Room room) { - if (!isEnterRoomAvailable(memberId, room.getRoomType())) { - throw new BadRequestException(MEMBER_ROOM_EXCEED); - } + validateEnteredRoomCount(memberId, room.getRoomType()); + if (!StringUtils.isEmpty(requestPassword) && !room.getPassword().equals(requestPassword)) { throw new BadRequestException(WRONG_ROOM_PASSWORD); } @@ -179,38 +179,20 @@ private void validateRoomEnter(Long memberId, String requestPassword, Room room) } } - private boolean isEnterRoomAvailable(Long memberId, RoomType roomType) { + private void validateEnteredRoomCount(Long memberId, RoomType roomType) { Member member = memberService.getById(memberId); if (roomType.equals(MORNING) && member.getCurrentMorningCount() >= 3) { - return false; + throw new BadRequestException(MEMBER_ROOM_EXCEED); } if (roomType.equals(NIGHT) && member.getCurrentNightCount() >= 3) { - return false; - } - - return true; - } - - private void increaseRoomCount(Long memberId, RoomType roomType) { - Member member = memberService.getById(memberId); - - if (roomType.equals(MORNING)) { - member.enterMorningRoom(); - return; + throw new BadRequestException(MEMBER_ROOM_EXCEED); } - - member.enterNightRoom(); } - private void decreaseRoomCount(Long memberId, RoomType roomType) { - Member member = memberService.getById(memberId); - - if (roomType.equals(MORNING)) { - member.exitMorningRoom(); - return; + private void validateRoomExit(Participant participant, Room room) { + if (participant.isManager() && room.getCurrentUserCount() != 1) { + throw new BadRequestException(ROOM_EXIT_MANAGER_FAIL); } - - member.exitNightRoom(); } } diff --git a/src/main/java/com/moabam/api/application/room/RoomSearchService.java b/src/main/java/com/moabam/api/application/room/SearchService.java similarity index 61% rename from src/main/java/com/moabam/api/application/room/RoomSearchService.java rename to src/main/java/com/moabam/api/application/room/SearchService.java index fad7eaa8..73ee5cb9 100644 --- a/src/main/java/com/moabam/api/application/room/RoomSearchService.java +++ b/src/main/java/com/moabam/api/application/room/SearchService.java @@ -1,8 +1,12 @@ package com.moabam.api.application.room; -import static com.moabam.global.common.util.GlobalConstant.*; -import static com.moabam.global.error.model.ErrorMessage.*; -import static org.apache.commons.lang3.StringUtils.*; +import static com.moabam.global.common.util.GlobalConstant.NOT_COMPLETED_RANK; +import static com.moabam.global.common.util.GlobalConstant.ROOM_FIXED_SEARCH_SIZE; +import static com.moabam.global.error.model.ErrorMessage.INVENTORY_NOT_FOUND; +import static com.moabam.global.error.model.ErrorMessage.PARTICIPANT_NOT_FOUND; +import static com.moabam.global.error.model.ErrorMessage.ROOM_DETAILS_ERROR; +import static com.moabam.global.error.model.ErrorMessage.ROOM_MODIFY_UNAUTHORIZED_REQUEST; +import static org.apache.commons.lang3.StringUtils.isEmpty; import java.time.LocalDate; import java.time.Period; @@ -19,6 +23,8 @@ import com.moabam.api.application.room.mapper.ParticipantMapper; import com.moabam.api.application.room.mapper.RoomMapper; import com.moabam.api.application.room.mapper.RoutineMapper; +import com.moabam.api.domain.item.Inventory; +import com.moabam.api.domain.item.repository.InventorySearchRepository; import com.moabam.api.domain.member.Member; import com.moabam.api.domain.room.Certification; import com.moabam.api.domain.room.DailyMemberCertification; @@ -31,8 +37,11 @@ import com.moabam.api.domain.room.repository.ParticipantSearchRepository; import com.moabam.api.domain.room.repository.RoomRepository; import com.moabam.api.domain.room.repository.RoomSearchRepository; -import com.moabam.api.domain.room.repository.RoutineSearchRepository; +import com.moabam.api.domain.room.repository.RoutineRepository; import com.moabam.api.dto.room.CertificationImageResponse; +import com.moabam.api.dto.room.CertificationImagesResponse; +import com.moabam.api.dto.room.GetAllRoomResponse; +import com.moabam.api.dto.room.GetAllRoomsResponse; import com.moabam.api.dto.room.ManageRoomResponse; import com.moabam.api.dto.room.MyRoomResponse; import com.moabam.api.dto.room.MyRoomsResponse; @@ -41,8 +50,6 @@ import com.moabam.api.dto.room.RoomHistoryResponse; import com.moabam.api.dto.room.RoomsHistoryResponse; import com.moabam.api.dto.room.RoutineResponse; -import com.moabam.api.dto.room.SearchAllRoomResponse; -import com.moabam.api.dto.room.SearchAllRoomsResponse; import com.moabam.api.dto.room.TodayCertificateRankResponse; import com.moabam.global.common.util.ClockHolder; import com.moabam.global.error.exception.ForbiddenException; @@ -54,15 +61,16 @@ @Service @RequiredArgsConstructor @Transactional(readOnly = true) -public class RoomSearchService { +public class SearchService { - private final CertificationsSearchRepository certificationsSearchRepository; - private final ParticipantSearchRepository participantSearchRepository; - private final RoutineSearchRepository routineSearchRepository; - private final RoomSearchRepository roomSearchRepository; private final RoomRepository roomRepository; + private final RoomSearchRepository roomSearchRepository; + private final RoutineRepository routineRepository; + private final ParticipantSearchRepository participantSearchRepository; + private final CertificationsSearchRepository certificationsSearchRepository; + private final InventorySearchRepository inventorySearchRepository; + private final CertificationService certificationService; private final MemberService memberService; - private final RoomCertificationService roomCertificationService; private final NotificationService notificationService; private final ClockHolder clockHolder; @@ -76,7 +84,7 @@ public RoomDetailsResponse getRoomDetails(Long memberId, Long roomId, LocalDate certificationsSearchRepository.findSortedDailyMemberCertifications(roomId, date); List routineResponses = getRoutineResponses(roomId); List todayCertificateRankResponses = getTodayCertificateRankResponses(memberId, - roomId, dailyMemberCertifications, date); + roomId, dailyMemberCertifications, date, room.getRoomType()); List certifiedDates = getCertifiedDatesBeforeWeek(roomId); double completePercentage = calculateCompletePercentage(dailyMemberCertifications.size(), room.getCurrentUserCount()); @@ -86,15 +94,14 @@ public RoomDetailsResponse getRoomDetails(Long memberId, Long roomId, LocalDate } public MyRoomsResponse getMyRooms(Long memberId) { - LocalDate today = clockHolder.times().toLocalDate(); + LocalDate today = clockHolder.date(); List myRoomResponses = new ArrayList<>(); List participants = participantSearchRepository.findNotDeletedParticipantsByMemberId(memberId); for (Participant participant : participants) { Room room = participant.getRoom(); - boolean isMemberCertified = roomCertificationService.existsMemberCertification(memberId, room.getId(), - today); - boolean isRoomCertified = roomCertificationService.existsRoomCertification(room.getId(), today); + boolean isMemberCertified = certificationService.existsMemberCertification(memberId, room.getId(), today); + boolean isRoomCertified = certificationService.existsRoomCertification(room.getId(), today); myRoomResponses.add(RoomMapper.toMyRoomResponse(room, isMemberCertified, isRoomCertified)); } @@ -104,24 +111,22 @@ public MyRoomsResponse getMyRooms(Long memberId) { public RoomsHistoryResponse getJoinHistory(Long memberId) { List participants = participantSearchRepository.findAllParticipantsByMemberId(memberId); - List roomHistoryResponses = new ArrayList<>(); + List roomHistoryResponses = participants.stream() + .map(participant -> { + if (participant.getRoom() == null) { + return RoomMapper.toRoomHistoryResponse(null, participant.getDeletedRoomTitle(), participant); + } - for (Participant participant : participants) { - if (participant.getRoom() == null) { - roomHistoryResponses.add(RoomMapper.toRoomHistoryResponse(null, - participant.getDeletedRoomTitle(), participant)); - - continue; - } + Room room = participant.getRoom(); - roomHistoryResponses.add(RoomMapper.toRoomHistoryResponse(participant.getRoom().getId(), - participant.getRoom().getTitle(), participant)); - } + return RoomMapper.toRoomHistoryResponse(room.getId(), room.getTitle(), participant); + }) + .toList(); return RoomMapper.toRoomsHistoryResponse(roomHistoryResponses); } - public ManageRoomResponse getRoomDetailsBeforeModification(Long memberId, Long roomId) { + public ManageRoomResponse getRoomForModification(Long memberId, Long roomId) { Participant participant = participantSearchRepository.findOne(memberId, roomId) .orElseThrow(() -> new NotFoundException(PARTICIPANT_NOT_FOUND)); @@ -132,13 +137,14 @@ public ManageRoomResponse getRoomDetailsBeforeModification(Long memberId, Long r Room room = participant.getRoom(); List routineResponses = getRoutineResponses(roomId); List participants = participantSearchRepository.findParticipantsByRoomId(roomId); - List memberIds = participants.stream().map(Participant::getMemberId).toList(); + List memberIds = participants.stream() + .map(Participant::getMemberId) + .toList(); List members = memberService.getRoomMembers(memberIds); List participantResponses = new ArrayList<>(); for (Member member : members) { - int contributionPoint = calculateContributionPoint(member.getId(), participants, - clockHolder.times().toLocalDate()); + int contributionPoint = calculateContributionPoint(member.getId(), participants, clockHolder.date()); participantResponses.add(ParticipantMapper.toParticipantResponse(member, contributionPoint)); } @@ -146,16 +152,17 @@ public ManageRoomResponse getRoomDetailsBeforeModification(Long memberId, Long r return RoomMapper.toManageRoomResponse(room, routineResponses, participantResponses); } - public SearchAllRoomsResponse searchAllRooms(@Nullable RoomType roomType, @Nullable Long roomId) { - List searchAllRoomResponses = new ArrayList<>(); + public GetAllRoomsResponse getAllRooms(@Nullable RoomType roomType, @Nullable Long roomId) { + List getAllRoomResponse = new ArrayList<>(); List rooms = new ArrayList<>(roomSearchRepository.findAllWithNoOffset(roomType, roomId)); - boolean hasNext = isHasNext(searchAllRoomResponses, rooms); + boolean hasNext = isHasNext(getAllRoomResponse, rooms); - return RoomMapper.toSearchAllRoomsResponse(hasNext, searchAllRoomResponses); + return RoomMapper.toSearchAllRoomsResponse(hasNext, getAllRoomResponse); } - public SearchAllRoomsResponse search(String keyword, @Nullable RoomType roomType, @Nullable Long roomId) { - List searchAllRoomResponses = new ArrayList<>(); + // TODO: full-text search 로 바꾸면서 리팩토링 예정 + public GetAllRoomsResponse searchRooms(String keyword, @Nullable RoomType roomType, @Nullable Long roomId) { + List getAllRoomResponse = new ArrayList<>(); List rooms = new ArrayList<>(); if (roomId == null && roomType == null) { @@ -175,12 +182,12 @@ public SearchAllRoomsResponse search(String keyword, @Nullable RoomType roomType roomRepository.searchByKeywordAndRoomIdAndRoomType(keyword, roomType.name(), roomId)); } - boolean hasNext = isHasNext(searchAllRoomResponses, rooms); + boolean hasNext = isHasNext(getAllRoomResponse, rooms); - return RoomMapper.toSearchAllRoomsResponse(hasNext, searchAllRoomResponses); + return RoomMapper.toSearchAllRoomsResponse(hasNext, getAllRoomResponse); } - private boolean isHasNext(List searchAllRoomResponses, List rooms) { + private boolean isHasNext(List getAllRoomResponse, List rooms) { boolean hasNext = false; if (rooms.size() > ROOM_FIXED_SEARCH_SIZE) { @@ -188,31 +195,32 @@ private boolean isHasNext(List searchAllRoomResponses, Li rooms.remove(ROOM_FIXED_SEARCH_SIZE); } - List roomIds = rooms.stream().map(Room::getId).toList(); - List routines = routineSearchRepository.findAllByRoomIds(roomIds); + List roomIds = rooms.stream() + .map(Room::getId) + .toList(); + List routines = routineRepository.findAllByRoomIdIn(roomIds); for (Room room : rooms) { List filteredRoutines = routines.stream() .filter(routine -> routine.getRoom().getId().equals(room.getId())) .toList(); - + List filteredResponses = RoutineMapper.toRoutineResponses(filteredRoutines); boolean isPassword = !isEmpty(room.getPassword()); - searchAllRoomResponses.add( - RoomMapper.toSearchAllRoomResponse(room, RoutineMapper.toRoutineResponses(filteredRoutines), - isPassword)); + getAllRoomResponse.add(RoomMapper.toSearchAllRoomResponse(room, filteredResponses, isPassword)); } + return hasNext; } private List getRoutineResponses(Long roomId) { - List roomRoutines = routineSearchRepository.findAllByRoomId(roomId); + List roomRoutines = routineRepository.findAllByRoomId(roomId); return RoutineMapper.toRoutineResponses(roomRoutines); } private List getTodayCertificateRankResponses(Long memberId, Long roomId, - List dailyMemberCertifications, LocalDate date) { + List dailyMemberCertifications, LocalDate date, RoomType roomType) { List responses = new ArrayList<>(); List certifications = certificationsSearchRepository.findCertifications(roomId, date); @@ -221,22 +229,27 @@ private List getTodayCertificateRankResponses(Long .map(Participant::getMemberId) .toList()); - List myKnockedNotificationStatusInRoom = notificationService.getMyKnockStatusInRoom( - memberId, roomId, participants); + List knocks = notificationService.getMyKnockStatusInRoom(memberId, roomId, participants); + + List memberIds = members.stream() + .map(Member::getId) + .toList(); + List inventories = inventorySearchRepository.findDefaultInventories(memberIds, roomType.name()); - addCompletedMembers(responses, dailyMemberCertifications, members, certifications, participants, date, - myKnockedNotificationStatusInRoom); - addUncompletedMembers(responses, dailyMemberCertifications, members, participants, date, - myKnockedNotificationStatusInRoom); + responses.addAll(completedMembers(dailyMemberCertifications, members, certifications, participants, date, + knocks, inventories)); + responses.addAll(uncompletedMembers(dailyMemberCertifications, members, participants, date, knocks, + inventories)); return responses; } - private void addCompletedMembers(List responses, + private List completedMembers( List dailyMemberCertifications, List members, - List certifications, List participants, LocalDate date, - List myKnockedNotificationStatusInRoom) { + List certifications, List participants, LocalDate date, List knocks, + List inventories) { + List responses = new ArrayList<>(); int rank = 1; for (DailyMemberCertification certification : dailyMemberCertifications) { @@ -245,24 +258,33 @@ private void addCompletedMembers(List responses, .findAny() .orElseThrow(() -> new NotFoundException(ROOM_DETAILS_ERROR)); - int contributionPoint = calculateContributionPoint(member.getId(), participants, date); - List certificationImageResponses = - CertificationsMapper.toCertificateImageResponses(member.getId(), certifications); + Inventory inventory = inventories.stream() + .filter(i -> i.getMemberId().equals(member.getId())) + .findAny() + .orElseThrow(() -> new NotFoundException(INVENTORY_NOT_FOUND)); - boolean isNotificationSent = myKnockedNotificationStatusInRoom.contains(member.getId()); + String awakeImage = inventory.getItem().getImage(); + String sleepImage = inventory.getItem().getImage(); - TodayCertificateRankResponse response = CertificationsMapper.toTodayCertificateRankResponse( - rank, member, contributionPoint, "https://~awake", "https://~sleep", certificationImageResponses, - isNotificationSent); + int contributionPoint = calculateContributionPoint(member.getId(), participants, date); + CertificationImagesResponse certificationImages = getCertificationImages(member.getId(), certifications); + boolean isNotificationSent = knocks.contains(member.getId()); + + TodayCertificateRankResponse response = CertificationsMapper.toTodayCertificateRankResponse(rank, member, + contributionPoint, awakeImage, sleepImage, certificationImages, isNotificationSent); rank += 1; responses.add(response); } + + return responses; } - private void addUncompletedMembers(List responses, - List dailyMemberCertifications, List members, - List participants, LocalDate date, List myKnockedNotificationStatusInRoom) { + private List uncompletedMembers( + List dailyMemberCertifications, List members, List participants, + LocalDate date, List knocks, List inventories) { + + List responses = new ArrayList<>(); List allMemberIds = participants.stream() .map(Participant::getMemberId) @@ -280,14 +302,35 @@ private void addUncompletedMembers(List responses, .findAny() .orElseThrow(() -> new NotFoundException(ROOM_DETAILS_ERROR)); + Inventory inventory = inventories.stream() + .filter(i -> i.getMemberId().equals(member.getId())) + .findAny() + .orElseThrow(() -> new NotFoundException(INVENTORY_NOT_FOUND)); + + String awakeImage = inventory.getItem().getImage(); + String sleepImage = inventory.getItem().getImage(); + int contributionPoint = calculateContributionPoint(memberId, participants, date); - boolean isNotificationSent = myKnockedNotificationStatusInRoom.contains(member.getId()); + boolean isNotificationSent = knocks.contains(member.getId()); - TodayCertificateRankResponse response = CertificationsMapper.toTodayCertificateRankResponse(500, member, - contributionPoint, "https://~awake", "https://~sleep", null, isNotificationSent); + TodayCertificateRankResponse response = CertificationsMapper.toTodayCertificateRankResponse( + NOT_COMPLETED_RANK, member, contributionPoint, awakeImage, sleepImage, null, + isNotificationSent); responses.add(response); } + + return responses; + } + + private CertificationImagesResponse getCertificationImages(Long memberId, List certifications) { + List certificationImageResponses = certifications.stream() + .filter(certification -> certification.getMemberId().equals(memberId)) + .map(certification -> CertificationsMapper.toCertificateImageResponse(certification.getRoutine().getId(), + certification.getImage())) + .toList(); + + return CertificationsMapper.toCertificateImagesResponse(certificationImageResponses); } private int calculateContributionPoint(Long memberId, List participants, LocalDate date) { @@ -303,9 +346,11 @@ private int calculateContributionPoint(Long memberId, List particip private List getCertifiedDatesBeforeWeek(Long roomId) { List certifications = certificationsSearchRepository.findDailyRoomCertifications( - roomId, clockHolder.times().toLocalDate()); + roomId, clockHolder.date()); - return certifications.stream().map(DailyRoomCertification::getCertifiedAt).toList(); + return certifications.stream() + .map(DailyRoomCertification::getCertifiedAt) + .toList(); } private double calculateCompletePercentage(int certifiedMembersCount, int currentsMembersCount) { diff --git a/src/main/java/com/moabam/api/application/room/mapper/CertificationsMapper.java b/src/main/java/com/moabam/api/application/room/mapper/CertificationsMapper.java index 788c03d2..060e3478 100644 --- a/src/main/java/com/moabam/api/application/room/mapper/CertificationsMapper.java +++ b/src/main/java/com/moabam/api/application/room/mapper/CertificationsMapper.java @@ -1,7 +1,6 @@ package com.moabam.api.application.room.mapper; import java.time.LocalDate; -import java.util.ArrayList; import java.util.List; import com.moabam.api.domain.member.Member; @@ -11,6 +10,7 @@ import com.moabam.api.domain.room.Participant; import com.moabam.api.domain.room.Routine; import com.moabam.api.dto.room.CertificationImageResponse; +import com.moabam.api.dto.room.CertificationImagesResponse; import com.moabam.api.dto.room.TodayCertificateRankResponse; import lombok.AccessLevel; @@ -19,29 +19,22 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class CertificationsMapper { - public static List toCertificateImageResponses(Long memberId, - List certifications) { - - List cftImageResponses = new ArrayList<>(); - List filteredCertifications = certifications.stream() - .filter(certification -> certification.getMemberId().equals(memberId)) - .toList(); - - for (Certification certification : filteredCertifications) { - CertificationImageResponse cftImageResponse = CertificationImageResponse.builder() - .routineId(certification.getRoutine().getId()) - .image(certification.getImage()) - .build(); - - cftImageResponses.add(cftImageResponse); - } + public static CertificationImageResponse toCertificateImageResponse(Long routineId, String image) { + return CertificationImageResponse.builder() + .routineId(routineId) + .image(image) + .build(); + } - return cftImageResponses; + public static CertificationImagesResponse toCertificateImagesResponse(List images) { + return CertificationImagesResponse.builder() + .images(images) + .build(); } public static TodayCertificateRankResponse toTodayCertificateRankResponse(int rank, Member member, int contributionPoint, String awakeImage, String sleepImage, - List certificationImageResponses, boolean isNotificationSent) { + CertificationImagesResponse certificationImagesResponses, boolean isNotificationSent) { return TodayCertificateRankResponse.builder() .rank(rank) @@ -52,13 +45,12 @@ public static TodayCertificateRankResponse toTodayCertificateRankResponse(int ra .contributionPoint(contributionPoint) .awakeImage(awakeImage) .sleepImage(sleepImage) - .certificationImage(certificationImageResponses) + .certificationImage(certificationImagesResponses) .build(); } public static DailyMemberCertification toDailyMemberCertification(Long memberId, Long roomId, Participant participant) { - return DailyMemberCertification.builder() .memberId(memberId) .roomId(roomId) diff --git a/src/main/java/com/moabam/api/application/room/mapper/ParticipantMapper.java b/src/main/java/com/moabam/api/application/room/mapper/ParticipantMapper.java index 0a566e70..3a4ec1da 100644 --- a/src/main/java/com/moabam/api/application/room/mapper/ParticipantMapper.java +++ b/src/main/java/com/moabam/api/application/room/mapper/ParticipantMapper.java @@ -1,6 +1,8 @@ package com.moabam.api.application.room.mapper; import com.moabam.api.domain.member.Member; +import com.moabam.api.domain.room.Participant; +import com.moabam.api.domain.room.Room; import com.moabam.api.dto.room.ParticipantResponse; import lombok.AccessLevel; @@ -9,6 +11,13 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ParticipantMapper { + public static Participant toParticipant(Room room, Long memberId) { + return Participant.builder() + .room(room) + .memberId(memberId) + .build(); + } + public static ParticipantResponse toParticipantResponse(Member member, int contributionPoint) { return ParticipantResponse.builder() .memberId(member.getId()) diff --git a/src/main/java/com/moabam/api/application/room/mapper/RoomMapper.java b/src/main/java/com/moabam/api/application/room/mapper/RoomMapper.java index 353c2f99..7e7a9d0c 100644 --- a/src/main/java/com/moabam/api/application/room/mapper/RoomMapper.java +++ b/src/main/java/com/moabam/api/application/room/mapper/RoomMapper.java @@ -6,6 +6,8 @@ import com.moabam.api.domain.room.Participant; import com.moabam.api.domain.room.Room; import com.moabam.api.dto.room.CreateRoomRequest; +import com.moabam.api.dto.room.GetAllRoomResponse; +import com.moabam.api.dto.room.GetAllRoomsResponse; import com.moabam.api.dto.room.ManageRoomResponse; import com.moabam.api.dto.room.MyRoomResponse; import com.moabam.api.dto.room.MyRoomsResponse; @@ -14,8 +16,6 @@ import com.moabam.api.dto.room.RoomHistoryResponse; import com.moabam.api.dto.room.RoomsHistoryResponse; import com.moabam.api.dto.room.RoutineResponse; -import com.moabam.api.dto.room.SearchAllRoomResponse; -import com.moabam.api.dto.room.SearchAllRoomsResponse; import com.moabam.api.dto.room.TodayCertificateRankResponse; import lombok.AccessLevel; @@ -107,9 +107,9 @@ public static ManageRoomResponse toManageRoomResponse(Room room, List routineResponses, + public static GetAllRoomResponse toSearchAllRoomResponse(Room room, List routineResponses, boolean isPassword) { - return SearchAllRoomResponse.builder() + return GetAllRoomResponse.builder() .id(room.getId()) .title(room.getTitle()) .image(room.getRoomImage()) @@ -124,11 +124,11 @@ public static SearchAllRoomResponse toSearchAllRoomResponse(Room room, List searchAllRoomResponses) { - return SearchAllRoomsResponse.builder() + public static GetAllRoomsResponse toSearchAllRoomsResponse(boolean hasNext, + List getAllRoomResponse) { + return GetAllRoomsResponse.builder() .hasNext(hasNext) - .rooms(searchAllRoomResponses) + .rooms(getAllRoomResponse) .build(); } } diff --git a/src/main/java/com/moabam/api/domain/item/repository/InventorySearchRepository.java b/src/main/java/com/moabam/api/domain/item/repository/InventorySearchRepository.java index c4f85cb5..431cf898 100644 --- a/src/main/java/com/moabam/api/domain/item/repository/InventorySearchRepository.java +++ b/src/main/java/com/moabam/api/domain/item/repository/InventorySearchRepository.java @@ -54,13 +54,24 @@ public List findItems(Long memberId, ItemType type) { .fetch(); } - public List findBirdsDefaultSkin(Long searchId) { + public List findDefaultSkin(Long memberId) { return jpaQueryFactory.selectFrom(inventory) .join(inventory.item) .on(inventory.item.id.eq(item.id)) .where( - inventory.memberId.eq(searchId), + inventory.memberId.eq(memberId), inventory.isDefault.isTrue() ).fetch(); } + + public List findDefaultInventories(List memberId, String roomType) { + return jpaQueryFactory.selectFrom(inventory) + .join(inventory.item, item).fetchJoin() + .where( + inventory.memberId.in(memberId), + inventory.isDefault.isTrue(), + inventory.item.type.eq(ItemType.valueOf(roomType)) + ) + .fetch(); + } } diff --git a/src/main/java/com/moabam/api/domain/member/Member.java b/src/main/java/com/moabam/api/domain/member/Member.java index 668ea534..b013d7fc 100644 --- a/src/main/java/com/moabam/api/domain/member/Member.java +++ b/src/main/java/com/moabam/api/domain/member/Member.java @@ -10,6 +10,7 @@ import org.hibernate.annotations.SQLDelete; import com.moabam.api.domain.bug.Bug; +import com.moabam.api.domain.room.RoomType; import com.moabam.global.common.entity.BaseTimeEntity; import com.moabam.global.common.util.BaseImageUrl; @@ -83,28 +84,30 @@ private Member(Long id, String socialId, Bug bug) { this.id = id; this.socialId = requireNonNull(socialId); this.nickname = createNickName(); - this.profileImage = BaseImageUrl.PROFILE_URL; + this.profileImage = BaseImageUrl.MEMBER_PROFILE_URL; this.bug = requireNonNull(bug); this.role = Role.USER; } - public void enterMorningRoom() { - currentMorningCount++; - } + public void enterRoom(RoomType roomType) { + if (roomType.equals(RoomType.MORNING)) { + this.currentMorningCount++; + return; + } - public void enterNightRoom() { - currentNightCount++; + if (roomType.equals(RoomType.NIGHT)) { + this.currentNightCount++; + } } - public void exitMorningRoom() { - if (currentMorningCount > 0) { - currentMorningCount--; + public void exitRoom(RoomType roomType) { + if (roomType.equals(RoomType.MORNING) && currentMorningCount > 0) { + this.currentMorningCount--; + return; } - } - public void exitNightRoom() { - if (currentNightCount > 0) { - currentNightCount--; + if (roomType.equals(RoomType.NIGHT) && currentNightCount > 0) { + this.currentNightCount--; } } diff --git a/src/main/java/com/moabam/api/domain/room/repository/RoutineRepository.java b/src/main/java/com/moabam/api/domain/room/repository/RoutineRepository.java index d4f0e1b9..add3c3be 100644 --- a/src/main/java/com/moabam/api/domain/room/repository/RoutineRepository.java +++ b/src/main/java/com/moabam/api/domain/room/repository/RoutineRepository.java @@ -1,9 +1,14 @@ package com.moabam.api.domain.room.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; import com.moabam.api.domain.room.Routine; public interface RoutineRepository extends JpaRepository { + List findAllByRoomId(Long roomId); + + List findAllByRoomIdIn(List roomIds); } diff --git a/src/main/java/com/moabam/api/domain/room/repository/RoutineSearchRepository.java b/src/main/java/com/moabam/api/domain/room/repository/RoutineSearchRepository.java deleted file mode 100644 index 087d22b6..00000000 --- a/src/main/java/com/moabam/api/domain/room/repository/RoutineSearchRepository.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.moabam.api.domain.room.repository; - -import static com.moabam.api.domain.room.QRoutine.*; - -import java.util.List; - -import org.springframework.stereotype.Repository; - -import com.moabam.api.domain.room.Routine; -import com.querydsl.jpa.impl.JPAQueryFactory; - -import lombok.RequiredArgsConstructor; - -@Repository -@RequiredArgsConstructor -public class RoutineSearchRepository { - - private final JPAQueryFactory jpaQueryFactory; - - public List findAllByRoomId(Long roomId) { - return jpaQueryFactory - .selectFrom(routine) - .where( - routine.room.id.eq(roomId) - ) - .fetch(); - } - - public List findAllByRoomIds(List roomIds) { - return jpaQueryFactory - .selectFrom(routine) - .where( - routine.room.id.in(roomIds) - ) - .fetch(); - } -} diff --git a/src/main/java/com/moabam/api/dto/room/CertificationImagesResponse.java b/src/main/java/com/moabam/api/dto/room/CertificationImagesResponse.java new file mode 100644 index 00000000..7de93159 --- /dev/null +++ b/src/main/java/com/moabam/api/dto/room/CertificationImagesResponse.java @@ -0,0 +1,12 @@ +package com.moabam.api.dto.room; + +import java.util.List; + +import lombok.Builder; + +@Builder +public record CertificationImagesResponse( + List images +) { + +} diff --git a/src/main/java/com/moabam/api/dto/room/SearchAllRoomResponse.java b/src/main/java/com/moabam/api/dto/room/GetAllRoomResponse.java similarity index 90% rename from src/main/java/com/moabam/api/dto/room/SearchAllRoomResponse.java rename to src/main/java/com/moabam/api/dto/room/GetAllRoomResponse.java index cdb35ab4..bff4f0ba 100644 --- a/src/main/java/com/moabam/api/dto/room/SearchAllRoomResponse.java +++ b/src/main/java/com/moabam/api/dto/room/GetAllRoomResponse.java @@ -7,7 +7,7 @@ import lombok.Builder; @Builder -public record SearchAllRoomResponse( +public record GetAllRoomResponse( Long id, String title, String image, diff --git a/src/main/java/com/moabam/api/dto/room/SearchAllRoomsResponse.java b/src/main/java/com/moabam/api/dto/room/GetAllRoomsResponse.java similarity index 61% rename from src/main/java/com/moabam/api/dto/room/SearchAllRoomsResponse.java rename to src/main/java/com/moabam/api/dto/room/GetAllRoomsResponse.java index 1d2eb960..bb648e72 100644 --- a/src/main/java/com/moabam/api/dto/room/SearchAllRoomsResponse.java +++ b/src/main/java/com/moabam/api/dto/room/GetAllRoomsResponse.java @@ -5,9 +5,9 @@ import lombok.Builder; @Builder -public record SearchAllRoomsResponse( +public record GetAllRoomsResponse( boolean hasNext, - List rooms + List rooms ) { } diff --git a/src/main/java/com/moabam/api/dto/room/TodayCertificateRankResponse.java b/src/main/java/com/moabam/api/dto/room/TodayCertificateRankResponse.java index 414be53a..c35829d4 100644 --- a/src/main/java/com/moabam/api/dto/room/TodayCertificateRankResponse.java +++ b/src/main/java/com/moabam/api/dto/room/TodayCertificateRankResponse.java @@ -1,7 +1,5 @@ package com.moabam.api.dto.room; -import java.util.List; - import lombok.Builder; @Builder @@ -14,7 +12,7 @@ public record TodayCertificateRankResponse( int contributionPoint, String awakeImage, String sleepImage, - List certificationImage + CertificationImagesResponse certificationImage ) { } diff --git a/src/main/java/com/moabam/api/presentation/RoomController.java b/src/main/java/com/moabam/api/presentation/RoomController.java index 9229e9df..c3d720fd 100644 --- a/src/main/java/com/moabam/api/presentation/RoomController.java +++ b/src/main/java/com/moabam/api/presentation/RoomController.java @@ -17,18 +17,20 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import com.moabam.api.application.room.RoomCertificationService; -import com.moabam.api.application.room.RoomSearchService; +import com.moabam.api.application.image.ImageService; +import com.moabam.api.application.room.CertificationService; import com.moabam.api.application.room.RoomService; +import com.moabam.api.application.room.SearchService; +import com.moabam.api.domain.image.ImageType; import com.moabam.api.domain.room.RoomType; import com.moabam.api.dto.room.CreateRoomRequest; import com.moabam.api.dto.room.EnterRoomRequest; +import com.moabam.api.dto.room.GetAllRoomsResponse; import com.moabam.api.dto.room.ManageRoomResponse; import com.moabam.api.dto.room.ModifyRoomRequest; import com.moabam.api.dto.room.MyRoomsResponse; import com.moabam.api.dto.room.RoomDetailsResponse; import com.moabam.api.dto.room.RoomsHistoryResponse; -import com.moabam.api.dto.room.SearchAllRoomsResponse; import com.moabam.global.auth.annotation.Auth; import com.moabam.global.auth.model.AuthMember; @@ -41,30 +43,33 @@ public class RoomController { private final RoomService roomService; - private final RoomSearchService roomSearchService; - private final RoomCertificationService roomCertificationService; + private final SearchService searchService; + private final CertificationService certificationService; + private final ImageService imageService; @PostMapping @ResponseStatus(HttpStatus.CREATED) - public Long createRoom(@Auth AuthMember authMember, - @Valid @RequestBody CreateRoomRequest createRoomRequest) { - + public Long createRoom(@Auth AuthMember authMember, @Valid @RequestBody CreateRoomRequest createRoomRequest) { return roomService.createRoom(authMember.id(), authMember.nickname(), createRoomRequest); } - @GetMapping("/{roomId}") + @GetMapping @ResponseStatus(HttpStatus.OK) - public ManageRoomResponse getRoomDetailsBeforeModification(@Auth AuthMember authMember, - @PathVariable("roomId") Long roomId) { + public GetAllRoomsResponse getAllRooms(@RequestParam(value = "roomType", required = false) RoomType roomType, + @RequestParam(value = "roomId", required = false) Long roomId) { + return searchService.getAllRooms(roomType, roomId); + } - return roomSearchService.getRoomDetailsBeforeModification(authMember.id(), roomId); + @GetMapping("/{roomId}") + @ResponseStatus(HttpStatus.OK) + public ManageRoomResponse getRoomForModification(@Auth AuthMember authMember, @PathVariable("roomId") Long roomId) { + return searchService.getRoomForModification(authMember.id(), roomId); } @PutMapping("/{roomId}") @ResponseStatus(HttpStatus.OK) - public void modifyRoom(@Auth AuthMember authMember, - @Valid @RequestBody ModifyRoomRequest modifyRoomRequest, @PathVariable("roomId") Long roomId) { - + public void modifyRoom(@Auth AuthMember authMember, @Valid @RequestBody ModifyRoomRequest modifyRoomRequest, + @PathVariable("roomId") Long roomId) { roomService.modifyRoom(authMember.id(), roomId, modifyRoomRequest); } @@ -72,7 +77,6 @@ public void modifyRoom(@Auth AuthMember authMember, @ResponseStatus(HttpStatus.OK) public void enterRoom(@Auth AuthMember authMember, @PathVariable("roomId") Long roomId, @Valid @RequestBody EnterRoomRequest enterRoomRequest) { - roomService.enterRoom(authMember.id(), roomId, enterRoomRequest); } @@ -84,62 +88,50 @@ public void exitRoom(@Auth AuthMember authMember, @PathVariable("roomId") Long r @GetMapping("/{roomId}/{date}") @ResponseStatus(HttpStatus.OK) - public RoomDetailsResponse getRoomDetails(@Auth AuthMember authMember, - @PathVariable("roomId") Long roomId, @PathVariable("date") LocalDate date) { - - return roomSearchService.getRoomDetails(authMember.id(), roomId, date); + public RoomDetailsResponse getRoomDetails(@Auth AuthMember authMember, @PathVariable("roomId") Long roomId, + @PathVariable("date") LocalDate date) { + return searchService.getRoomDetails(authMember.id(), roomId, date); } @PostMapping("/{roomId}/certification") @ResponseStatus(HttpStatus.CREATED) public void certifyRoom(@Auth AuthMember authMember, @PathVariable("roomId") Long roomId, @RequestPart List multipartFiles) { - - roomCertificationService.certifyRoom(authMember.id(), roomId, multipartFiles); + List imageUrls = imageService.uploadImages(multipartFiles, ImageType.CERTIFICATION); + certificationService.certifyRoom(authMember.id(), roomId, imageUrls); } @PutMapping("/{roomId}/members/{memberId}/mandate") @ResponseStatus(HttpStatus.OK) - public void mandateManager(@Auth AuthMember authMember, - @PathVariable("roomId") Long roomId, @PathVariable("memberId") Long memberId) { - - roomService.mandateRoomManager(authMember.id(), roomId, memberId); + public void mandateManager(@Auth AuthMember authMember, @PathVariable("roomId") Long roomId, + @PathVariable("memberId") Long memberId) { + roomService.mandateManager(authMember.id(), roomId, memberId); } @DeleteMapping("/{roomId}/members/{memberId}") @ResponseStatus(HttpStatus.OK) - public void deportParticipant(@Auth AuthMember authMember, - @PathVariable("roomId") Long roomId, @PathVariable("memberId") Long memberId) { - + public void deportParticipant(@Auth AuthMember authMember, @PathVariable("roomId") Long roomId, + @PathVariable("memberId") Long memberId) { roomService.deportParticipant(authMember.id(), roomId, memberId); } @GetMapping("/my-join") @ResponseStatus(HttpStatus.OK) public MyRoomsResponse getMyRooms(@Auth AuthMember authMember) { - return roomSearchService.getMyRooms(authMember.id()); + return searchService.getMyRooms(authMember.id()); } @GetMapping("/join-history") @ResponseStatus(HttpStatus.OK) public RoomsHistoryResponse getJoinHistory(@Auth AuthMember authMember) { - return roomSearchService.getJoinHistory(authMember.id()); - } - - @GetMapping - @ResponseStatus(HttpStatus.OK) - public SearchAllRoomsResponse searchAllRooms(@RequestParam(value = "roomType", required = false) RoomType roomType, - @RequestParam(value = "roomId", required = false) Long roomId) { - - return roomSearchService.searchAllRooms(roomType, roomId); + return searchService.getJoinHistory(authMember.id()); } @GetMapping("/search") @ResponseStatus(HttpStatus.OK) - public SearchAllRoomsResponse search(@RequestParam(value = "keyword") String keyword, + public GetAllRoomsResponse searchRooms(@RequestParam(value = "keyword") String keyword, @RequestParam(value = "roomType", required = false) RoomType roomType, @RequestParam(value = "roomId", required = false) Long roomId) { - - return roomSearchService.search(keyword, roomType, roomId); + return searchService.searchRooms(keyword, roomType, roomId); } } diff --git a/src/main/java/com/moabam/global/common/util/BaseImageUrl.java b/src/main/java/com/moabam/global/common/util/BaseImageUrl.java index d13f36ff..99544648 100644 --- a/src/main/java/com/moabam/global/common/util/BaseImageUrl.java +++ b/src/main/java/com/moabam/global/common/util/BaseImageUrl.java @@ -6,5 +6,11 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class BaseImageUrl { - public static final String PROFILE_URL = "/profile/baseUrl"; + public static final String DEFAULT_SKIN_URL = ""; + public static final String DEFAULT_MORNING_AWAKE_SKIN_URL = ""; + public static final String DEFAULT_MORNING_SLEEP_SKIN_URL = ""; + public static final String DEFAULT_NIGHT_AWAKE_SKIN_URL = ""; + public static final String DEFAULT_NIGHT_SLEEP_SKIN_URL = ""; + + public static final String MEMBER_PROFILE_URL = "/profile/baseUrl"; } diff --git a/src/main/java/com/moabam/global/common/util/ClockHolder.java b/src/main/java/com/moabam/global/common/util/ClockHolder.java index 414ce25c..1ba7a0c5 100644 --- a/src/main/java/com/moabam/global/common/util/ClockHolder.java +++ b/src/main/java/com/moabam/global/common/util/ClockHolder.java @@ -1,8 +1,11 @@ package com.moabam.global.common.util; +import java.time.LocalDate; import java.time.LocalDateTime; public interface ClockHolder { LocalDateTime times(); + + LocalDate date(); } diff --git a/src/main/java/com/moabam/global/common/util/GlobalConstant.java b/src/main/java/com/moabam/global/common/util/GlobalConstant.java index 19e2a26d..ec45d2ec 100644 --- a/src/main/java/com/moabam/global/common/util/GlobalConstant.java +++ b/src/main/java/com/moabam/global/common/util/GlobalConstant.java @@ -14,6 +14,7 @@ public class GlobalConstant { public static final String SPACE = " "; public static final int ONE_HOUR = 1; public static final int HOURS_IN_A_DAY = 24; + public static final int NOT_COMPLETED_RANK = 500; public static final int ROOM_FIXED_SEARCH_SIZE = 10; public static final int LEVEL_DIVISOR = 10; diff --git a/src/main/java/com/moabam/global/common/util/SystemClockHolder.java b/src/main/java/com/moabam/global/common/util/SystemClockHolder.java index 8662d0da..79396d91 100644 --- a/src/main/java/com/moabam/global/common/util/SystemClockHolder.java +++ b/src/main/java/com/moabam/global/common/util/SystemClockHolder.java @@ -1,5 +1,6 @@ package com.moabam.global.common.util; +import java.time.LocalDate; import java.time.LocalDateTime; import org.springframework.stereotype.Component; @@ -11,4 +12,9 @@ public class SystemClockHolder implements ClockHolder { public LocalDateTime times() { return LocalDateTime.now(); } + + @Override + public LocalDate date() { + return LocalDate.now(); + } } diff --git a/src/test/java/com/moabam/api/application/member/MemberServiceTest.java b/src/test/java/com/moabam/api/application/member/MemberServiceTest.java index 8db4966b..c1d9025c 100644 --- a/src/test/java/com/moabam/api/application/member/MemberServiceTest.java +++ b/src/test/java/com/moabam/api/application/member/MemberServiceTest.java @@ -147,7 +147,7 @@ void search_my_info_success(@WithMember AuthMember authMember) { given(memberSearchRepository.findMemberAndBadges(authMember.id(), true)) .willReturn(MemberInfoSearchFixture.friendMemberInfo(total)); - given(inventorySearchRepository.findBirdsDefaultSkin(authMember.id())) + given(inventorySearchRepository.findDefaultSkin(authMember.id())) .willReturn(List.of( InventoryFixture.inventory(authMember.id(), morning), InventoryFixture.inventory(authMember.id(), night))); @@ -177,7 +177,7 @@ void success(@WithMember AuthMember authMember) { given(memberSearchRepository.findMemberAndBadges(anyLong(), anyBoolean())) .willReturn(MemberInfoSearchFixture.myInfo()); - given(inventorySearchRepository.findBirdsDefaultSkin(searchId)).willReturn(List.of(morningSkin, nightSkin)); + given(inventorySearchRepository.findDefaultSkin(searchId)).willReturn(List.of(morningSkin, nightSkin)); // when MemberInfoResponse memberInfoResponse = memberService.searchInfo(authMember, null); @@ -193,7 +193,7 @@ void failBy_underSize(@WithMember AuthMember authMember) { // given given(memberSearchRepository.findMemberAndBadges(anyLong(), anyBoolean())) .willReturn(MemberInfoSearchFixture.friendMemberInfo()); - given(inventorySearchRepository.findBirdsDefaultSkin(anyLong())).willReturn(List.of()); + given(inventorySearchRepository.findDefaultSkin(anyLong())).willReturn(List.of()); // when assertThatThrownBy(() -> memberService.searchInfo(authMember, 123L)) @@ -215,7 +215,7 @@ void failBy_overSize(@WithMember AuthMember authMember) { given(memberSearchRepository.findMemberAndBadges(anyLong(), anyBoolean())) .willReturn(MemberInfoSearchFixture.myInfo()); - given(inventorySearchRepository.findBirdsDefaultSkin(searchId)) + given(inventorySearchRepository.findDefaultSkin(searchId)) .willReturn(List.of(morningSkin, nightSkin, killSkin)); // when diff --git a/src/test/java/com/moabam/api/application/room/RoomCertificationServiceTest.java b/src/test/java/com/moabam/api/application/room/CertificationServiceTest.java similarity index 86% rename from src/test/java/com/moabam/api/application/room/RoomCertificationServiceTest.java rename to src/test/java/com/moabam/api/application/room/CertificationServiceTest.java index a103d1e9..ee3bacb1 100644 --- a/src/test/java/com/moabam/api/application/room/RoomCertificationServiceTest.java +++ b/src/test/java/com/moabam/api/application/room/CertificationServiceTest.java @@ -1,8 +1,10 @@ package com.moabam.api.application.room; -import static org.assertj.core.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.BDDMockito.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.lenient; +import static org.mockito.BDDMockito.spy; import java.time.LocalDate; import java.time.LocalDateTime; @@ -18,12 +20,9 @@ import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.mock.web.MockMultipartFile; -import org.springframework.web.multipart.MultipartFile; import com.moabam.api.application.image.ImageService; import com.moabam.api.application.member.MemberService; -import com.moabam.api.domain.image.ImageType; import com.moabam.api.domain.member.Member; import com.moabam.api.domain.room.DailyMemberCertification; import com.moabam.api.domain.room.DailyRoomCertification; @@ -43,10 +42,10 @@ import com.moabam.support.fixture.RoomFixture; @ExtendWith(MockitoExtension.class) -class RoomCertificationServiceTest { +class CertificationServiceTest { @InjectMocks - private RoomCertificationService roomCertificationService; + private CertificationService certificationService; @Mock private MemberService memberService; @@ -118,14 +117,12 @@ void already_certified_room_routine_success() { // given List routines = RoomFixture.routines(room); DailyRoomCertification dailyRoomCertification = RoomFixture.dailyRoomCertification(roomId, today); - MockMultipartFile image = RoomFixture.makeMultipartFile1(); - List images = List.of(image, image, image); List uploadImages = new ArrayList<>(); uploadImages.add("https://image.moabam.com/certifications/20231108/1_asdfsdfxcv-4815vcx-asfd"); uploadImages.add("https://image.moabam.com/certifications/20231108/2_asdfsdfxcv-4815vcx-asfd"); - given(imageService.uploadImages(images, ImageType.CERTIFICATION)).willReturn(uploadImages); given(clockHolder.times()).willReturn(LocalDateTime.now().withHour(9).withMinute(58)); + given(clockHolder.date()).willReturn(today); given(participantSearchRepository.findOne(memberId, roomId)).willReturn(Optional.of(participant)); given(memberService.getById(memberId)).willReturn(member1); given(routineRepository.findById(1L)).willReturn(Optional.of(routines.get(0))); @@ -134,7 +131,7 @@ void already_certified_room_routine_success() { Optional.of(dailyRoomCertification)); // when - roomCertificationService.certifyRoom(memberId, roomId, images); + certificationService.certifyRoom(memberId, roomId, uploadImages); // then assertThat(member1.getBug().getMorningBug()).isEqualTo(12); @@ -146,16 +143,14 @@ void already_certified_room_routine_success() { void not_certified_room_routine_success() { // given List routines = RoomFixture.routines(room); - MockMultipartFile image = RoomFixture.makeMultipartFile1(); List dailyMemberCertifications = RoomFixture.dailyMemberCertifications(roomId, participant); - List images = List.of(image, image, image); List uploadImages = new ArrayList<>(); uploadImages.add("https://image.moabam.com/certifications/20231108/1_asdfsdfxcv-4815vcx-asfd"); uploadImages.add("https://image.moabam.com/certifications/20231108/2_asdfsdfxcv-4815vcx-asfd"); - given(imageService.uploadImages(images, ImageType.CERTIFICATION)).willReturn(uploadImages); given(clockHolder.times()).willReturn(LocalDateTime.now().withHour(9).withMinute(58)); + given(clockHolder.date()).willReturn(today); given(participantSearchRepository.findOne(memberId, roomId)).willReturn(Optional.of(participant)); given(memberService.getById(memberId)).willReturn(member1); given(routineRepository.findById(1L)).willReturn(Optional.of(routines.get(0))); @@ -167,7 +162,7 @@ void not_certified_room_routine_success() { given(memberService.getRoomMembers(anyList())).willReturn(List.of(member1, member2, member3)); // when - roomCertificationService.certifyRoom(memberId, roomId, images); + certificationService.certifyRoom(memberId, roomId, uploadImages); // then assertThat(member1.getBug().getMorningBug()).isEqualTo(12); diff --git a/src/test/java/com/moabam/api/application/room/RoomServiceTest.java b/src/test/java/com/moabam/api/application/room/RoomServiceTest.java index fdecd0e5..b0038193 100644 --- a/src/test/java/com/moabam/api/application/room/RoomServiceTest.java +++ b/src/test/java/com/moabam/api/application/room/RoomServiceTest.java @@ -131,7 +131,7 @@ void room_manager_mandate_success() { given(memberService.getById(2L)).willReturn(member); // when - roomService.mandateRoomManager(managerId, room.getId(), memberId); + roomService.mandateManager(managerId, room.getId(), memberId); // then assertThat(managerParticipant.isManager()).isFalse(); @@ -157,7 +157,7 @@ void room_manager_mandate_fail() { Optional.of(managerParticipant)); // when, then - assertThatThrownBy(() -> roomService.mandateRoomManager(managerId, 1L, memberId)) + assertThatThrownBy(() -> roomService.mandateManager(managerId, 1L, memberId)) .isInstanceOf(ForbiddenException.class); } } diff --git a/src/test/java/com/moabam/api/application/room/RoomSearchServiceTest.java b/src/test/java/com/moabam/api/application/room/SearchServiceTest.java similarity index 91% rename from src/test/java/com/moabam/api/application/room/RoomSearchServiceTest.java rename to src/test/java/com/moabam/api/application/room/SearchServiceTest.java index f1239539..70e26d2f 100644 --- a/src/test/java/com/moabam/api/application/room/RoomSearchServiceTest.java +++ b/src/test/java/com/moabam/api/application/room/SearchServiceTest.java @@ -26,18 +26,18 @@ import com.moabam.api.domain.room.repository.ParticipantSearchRepository; import com.moabam.api.domain.room.repository.RoomRepository; import com.moabam.api.domain.room.repository.RoomSearchRepository; -import com.moabam.api.domain.room.repository.RoutineSearchRepository; +import com.moabam.api.domain.room.repository.RoutineRepository; +import com.moabam.api.dto.room.GetAllRoomsResponse; import com.moabam.api.dto.room.MyRoomsResponse; import com.moabam.api.dto.room.RoomsHistoryResponse; -import com.moabam.api.dto.room.SearchAllRoomsResponse; import com.moabam.global.common.util.ClockHolder; import com.moabam.support.fixture.RoomFixture; @ExtendWith(MockitoExtension.class) -class RoomSearchServiceTest { +class SearchServiceTest { @InjectMocks - private RoomSearchService roomSearchService; + private SearchService searchService; @Mock private CertificationsSearchRepository certificationsSearchRepository; @@ -46,7 +46,7 @@ class RoomSearchServiceTest { private ParticipantSearchRepository participantSearchRepository; @Mock - private RoutineSearchRepository routineSearchRepository; + private RoutineRepository routineRepository; @Mock private RoomSearchRepository roomSearchRepository; @@ -55,7 +55,7 @@ class RoomSearchServiceTest { private MemberService memberService; @Mock - private RoomCertificationService certificationService; + private CertificationService certificationService; @Mock private RoomRepository roomRepository; @@ -91,10 +91,10 @@ void get_my_rooms_success() { given(certificationService.existsRoomCertification(room2.getId(), today)).willReturn(false); given(certificationService.existsRoomCertification(room3.getId(), today)).willReturn(false); - given(clockHolder.times()).willReturn(LocalDateTime.now()); + given(clockHolder.date()).willReturn(LocalDate.now()); // when - MyRoomsResponse myRooms = roomSearchService.getMyRooms(memberId); + MyRoomsResponse myRooms = searchService.getMyRooms(memberId); // then assertThat(myRooms.participatingRooms()).hasSize(3); @@ -133,7 +133,7 @@ void get_my_join_history_success() { given(participantSearchRepository.findAllParticipantsByMemberId(memberId)).willReturn(participants); // when - RoomsHistoryResponse response = roomSearchService.getJoinHistory(memberId); + RoomsHistoryResponse response = searchService.getJoinHistory(memberId); // then assertThat(response.roomHistory()).hasSize(3); @@ -253,16 +253,16 @@ void search_all_morning_night_rooms_success() { routine28); given(roomSearchRepository.findAllWithNoOffset(null, null)).willReturn(rooms); - given(routineSearchRepository.findAllByRoomIds(anyList())).willReturn(routines); + given(routineRepository.findAllByRoomIdIn(anyList())).willReturn(routines); // when - SearchAllRoomsResponse searchAllRoomsResponse = roomSearchService.searchAllRooms(null, null); + GetAllRoomsResponse getAllRoomsResponse = searchService.getAllRooms(null, null); // then - assertThat(searchAllRoomsResponse.hasNext()).isTrue(); - assertThat(searchAllRoomsResponse.rooms()).hasSize(10); - assertThat(searchAllRoomsResponse.rooms().get(0).id()).isEqualTo(1L); - assertThat(searchAllRoomsResponse.rooms().get(9).id()).isEqualTo(10L); + assertThat(getAllRoomsResponse.hasNext()).isTrue(); + assertThat(getAllRoomsResponse.rooms()).hasSize(10); + assertThat(getAllRoomsResponse.rooms().get(0).id()).isEqualTo(1L); + assertThat(getAllRoomsResponse.rooms().get(9).id()).isEqualTo(10L); } @DisplayName("아침, 저녁 전체 방 조회 성공, 마지막 페이 조회, 다음 페이지 없음") @@ -306,16 +306,16 @@ void search_last_page_all_morning_night_rooms_success() { routine28); given(roomSearchRepository.findAllWithNoOffset(null, 10L)).willReturn(rooms); - given(routineSearchRepository.findAllByRoomIds(anyList())).willReturn(routines); + given(routineRepository.findAllByRoomIdIn(anyList())).willReturn(routines); // when - SearchAllRoomsResponse searchAllRoomsResponse = roomSearchService.searchAllRooms(null, 10L); + GetAllRoomsResponse getAllRoomsResponse = searchService.getAllRooms(null, 10L); // then - assertThat(searchAllRoomsResponse.hasNext()).isFalse(); - assertThat(searchAllRoomsResponse.rooms()).hasSize(4); - assertThat(searchAllRoomsResponse.rooms().get(0).id()).isEqualTo(11L); - assertThat(searchAllRoomsResponse.rooms().get(3).id()).isEqualTo(14L); + assertThat(getAllRoomsResponse.hasNext()).isFalse(); + assertThat(getAllRoomsResponse.rooms()).hasSize(4); + assertThat(getAllRoomsResponse.rooms().get(0).id()).isEqualTo(11L); + assertThat(getAllRoomsResponse.rooms().get(3).id()).isEqualTo(14L); } @DisplayName("전체 방 제목, 방장 이름, 루틴 내용으로 검색 성공 - 최초 조회") @@ -405,13 +405,13 @@ void search_room_by_title_manager_nickname_routine_success() { routine25, routine26, routine27, routine28); given(roomRepository.searchByKeyword("번째")).willReturn(rooms); - given(routineSearchRepository.findAllByRoomIds(anyList())).willReturn(routines); + given(routineRepository.findAllByRoomIdIn(anyList())).willReturn(routines); // when - SearchAllRoomsResponse searchAllRoomsResponse = roomSearchService.search("번째", null, null); + GetAllRoomsResponse getAllRoomsResponse = searchService.searchRooms("번째", null, null); // then - assertThat(searchAllRoomsResponse.hasNext()).isTrue(); - assertThat(searchAllRoomsResponse.rooms()).hasSize(10); + assertThat(getAllRoomsResponse.hasNext()).isTrue(); + assertThat(getAllRoomsResponse.rooms()).hasSize(10); } } diff --git a/src/test/java/com/moabam/api/domain/entity/MemberTest.java b/src/test/java/com/moabam/api/domain/entity/MemberTest.java index 8e3ae4f8..b3168af3 100644 --- a/src/test/java/com/moabam/api/domain/entity/MemberTest.java +++ b/src/test/java/com/moabam/api/domain/entity/MemberTest.java @@ -10,6 +10,7 @@ import com.moabam.api.domain.bug.Bug; import com.moabam.api.domain.member.Member; import com.moabam.api.domain.member.Role; +import com.moabam.api.domain.room.RoomType; import com.moabam.global.common.util.BaseImageUrl; import com.moabam.support.fixture.MemberFixture; @@ -40,7 +41,7 @@ void create_member_noImage_success() { .build(); assertAll( - () -> assertThat(member.getProfileImage()).isEqualTo(BaseImageUrl.PROFILE_URL), + () -> assertThat(member.getProfileImage()).isEqualTo(BaseImageUrl.MEMBER_PROFILE_URL), () -> assertThat(member.getRole()).isEqualTo(Role.USER), () -> assertThat(member.getBug().getNightBug()).isZero(), () -> assertThat(member.getBug().getGoldenBug()).isZero(), @@ -82,10 +83,10 @@ void member_room_enter_success() { // when int beforeMorningCount = member.getCurrentMorningCount(); - member.enterMorningRoom(); + member.enterRoom(RoomType.MORNING); int beforeNightCount = member.getCurrentNightCount(); - member.enterNightRoom(); + member.enterRoom(RoomType.NIGHT); // then assertThat(member.getCurrentMorningCount()).isEqualTo(beforeMorningCount + 1); @@ -99,12 +100,12 @@ void member_room_exit_success() { Member member = MemberFixture.member(); // when - member.exitMorningRoom(); - member.exitNightRoom(); + member.exitRoom(RoomType.MORNING); + member.exitRoom(RoomType.NIGHT); // then assertThat(member.getCurrentMorningCount()).isZero(); - assertThat(member.getCurrentMorningCount()).isZero(); + assertThat(member.getCurrentNightCount()).isZero(); } } } diff --git a/src/test/java/com/moabam/api/domain/item/repository/InventorySearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/item/repository/InventorySearchRepositoryTest.java index cfeddcea..2fdd57e9 100644 --- a/src/test/java/com/moabam/api/domain/item/repository/InventorySearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/item/repository/InventorySearchRepositoryTest.java @@ -18,6 +18,7 @@ import com.moabam.api.domain.item.ItemType; import com.moabam.api.domain.member.Member; import com.moabam.api.domain.member.repository.MemberRepository; +import com.moabam.api.domain.room.RoomType; import com.moabam.support.annotation.QuerydslRepositoryTest; import com.moabam.support.fixture.InventoryFixture; import com.moabam.support.fixture.ItemFixture; @@ -111,6 +112,27 @@ void find_default_success() { assertThat(actual).isPresent().contains(inventory); } + @DisplayName("여러 회원의 밤 타입에 적용된 인벤토리를 조회한다.") + @Test + void find_all_default_type_night_success() { + // given + Member member1 = memberRepository.save(member("1", "회원1")); + Member member2 = memberRepository.save(member("2", "회원2")); + Item item = itemRepository.save(nightMageSkin()); + Inventory inventory1 = inventoryRepository.save(inventory(member1.getId(), item)); + Inventory inventory2 = inventoryRepository.save(inventory(member2.getId(), item)); + inventory1.select(); + inventory2.select(); + + // when + List actual = inventorySearchRepository.findDefaultInventories(List.of(member1.getId(), + member2.getId()), RoomType.NIGHT.name()); + + // then + assertThat(actual).hasSize(2); + assertThat(actual.get(0).getItem().getName()).isEqualTo(nightMageSkin().getName()); + } + @DisplayName("기본 새 찾는 쿼리") @Nested class FindDefaultBird { @@ -120,7 +142,7 @@ class FindDefaultBird { void bird_find_success() { // given Member member = MemberFixture.member(); - member.enterMorningRoom(); + member.exitRoom(RoomType.MORNING); memberRepository.save(member); Item night = ItemFixture.nightMageSkin(); @@ -138,7 +160,7 @@ void bird_find_success() { inventoryRepository.saveAll(List.of(nightInven, morningInven, killerInven)); // when - List inventories = inventorySearchRepository.findBirdsDefaultSkin(member.getId()); + List inventories = inventorySearchRepository.findDefaultSkin(member.getId()); // then assertThat(inventories).hasSize(2); diff --git a/src/test/java/com/moabam/api/domain/member/MemberRepositoryTest.java b/src/test/java/com/moabam/api/domain/member/MemberRepositoryTest.java index 071605d1..ff6d4403 100644 --- a/src/test/java/com/moabam/api/domain/member/MemberRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/member/MemberRepositoryTest.java @@ -16,6 +16,7 @@ import com.moabam.api.domain.member.repository.MemberSearchRepository; import com.moabam.api.domain.room.Participant; import com.moabam.api.domain.room.Room; +import com.moabam.api.domain.room.RoomType; import com.moabam.api.domain.room.repository.ParticipantRepository; import com.moabam.api.domain.room.repository.RoomRepository; import com.moabam.api.dto.member.MemberInfo; @@ -124,7 +125,7 @@ void member_not_found() { void search_info_success() { // given Member member = MemberFixture.member(); - member.enterMorningRoom(); + member.enterRoom(RoomType.MORNING); memberRepository.save(member); Badge morningBirth = BadgeFixture.badge(member.getId(), BadgeType.MORNING_BIRTH); @@ -149,7 +150,7 @@ void search_info_success() { void no_badges_search_success() { // given Member member = MemberFixture.member(); - member.enterMorningRoom(); + member.enterRoom(RoomType.MORNING); memberRepository.save(member); // when diff --git a/src/test/java/com/moabam/api/presentation/RoomControllerTest.java b/src/test/java/com/moabam/api/presentation/RoomControllerTest.java index 14d9049d..1e812e7b 100644 --- a/src/test/java/com/moabam/api/presentation/RoomControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/RoomControllerTest.java @@ -1,11 +1,16 @@ package com.moabam.api.presentation; -import static com.moabam.api.domain.room.RoomType.*; -import static org.assertj.core.api.Assertions.*; -import static org.springframework.http.MediaType.*; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static com.moabam.api.domain.room.RoomType.MORNING; +import static com.moabam.api.domain.room.RoomType.NIGHT; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import java.time.LocalDate; import java.util.ArrayList; @@ -25,6 +30,10 @@ import org.springframework.transaction.annotation.Transactional; import com.fasterxml.jackson.databind.ObjectMapper; +import com.moabam.api.domain.item.Inventory; +import com.moabam.api.domain.item.Item; +import com.moabam.api.domain.item.repository.InventoryRepository; +import com.moabam.api.domain.item.repository.ItemRepository; import com.moabam.api.domain.member.Member; import com.moabam.api.domain.member.repository.MemberRepository; import com.moabam.api.domain.room.Certification; @@ -41,13 +50,14 @@ import com.moabam.api.domain.room.repository.ParticipantSearchRepository; import com.moabam.api.domain.room.repository.RoomRepository; import com.moabam.api.domain.room.repository.RoutineRepository; -import com.moabam.api.domain.room.repository.RoutineSearchRepository; import com.moabam.api.dto.room.CreateRoomRequest; import com.moabam.api.dto.room.EnterRoomRequest; import com.moabam.api.dto.room.ModifyRoomRequest; import com.moabam.support.annotation.WithMember; import com.moabam.support.common.WithoutFilterSupporter; import com.moabam.support.fixture.BugFixture; +import com.moabam.support.fixture.InventoryFixture; +import com.moabam.support.fixture.ItemFixture; import com.moabam.support.fixture.MemberFixture; import com.moabam.support.fixture.RoomFixture; @@ -69,9 +79,6 @@ class RoomControllerTest extends WithoutFilterSupporter { @Autowired private RoutineRepository routineRepository; - @Autowired - private RoutineSearchRepository routineSearchRepository; - @Autowired private ParticipantRepository participantRepository; @@ -90,6 +97,12 @@ class RoomControllerTest extends WithoutFilterSupporter { @Autowired private ParticipantSearchRepository participantSearchRepository; + @Autowired + private ItemRepository itemRepository; + + @Autowired + private InventoryRepository inventoryRepository; + Member member; @BeforeAll @@ -101,11 +114,11 @@ void setUp() { @AfterEach void cleanUp() { while (member.getCurrentMorningCount() > 0) { - member.exitMorningRoom(); + member.exitRoom(MORNING); } while (member.getCurrentNightCount() > 0) { - member.exitNightRoom(); + member.exitRoom(NIGHT); } } @@ -310,7 +323,7 @@ void modify_room_success() throws Exception { .andDo(print()); Room modifiedRoom = roomRepository.findById(room.getId()).orElseThrow(); - List modifiedRoutines = routineSearchRepository.findAllByRoomId(room.getId()); + List modifiedRoutines = routineRepository.findAllByRoomId(room.getId()); assertThat(modifiedRoom.getTitle()).isEqualTo("수정할 방임!"); assertThat(modifiedRoom.getCertifyTime()).isEqualTo(10); @@ -500,7 +513,7 @@ void enter_and_morning_room_over_three_fail() throws Exception { .build(); for (int i = 0; i < 3; i++) { - member.enterMorningRoom(); + member.enterRoom(MORNING); } memberRepository.save(member); @@ -528,7 +541,7 @@ void enter_and_night_room_over_three_fail() throws Exception { .build(); for (int i = 0; i < 3; i++) { - member.enterNightRoom(); + member.enterRoom(NIGHT); } memberRepository.save(member); @@ -715,7 +728,7 @@ void exit_and_decrease_morning_room_count() throws Exception { Participant participant = RoomFixture.participant(room, 1L); for (int i = 0; i < 3; i++) { - member.enterMorningRoom(); + member.enterRoom(RoomType.MORNING); } memberRepository.save(member); @@ -748,7 +761,7 @@ void exit_and_decrease_night_room_count() throws Exception { Participant participant = RoomFixture.participant(room, 1L); for (int i = 0; i < 3; i++) { - member.enterNightRoom(); + member.enterRoom(NIGHT); } memberRepository.save(member); @@ -791,8 +804,20 @@ void get_room_details_test() throws Exception { roomRepository.save(room); routineRepository.saveAll(routines); - memberRepository.save(member2); - memberRepository.save(member3); + member2 = memberRepository.save(member2); + member3 = memberRepository.save(member3); + + Item item = ItemFixture.nightMageSkin(); + + Inventory inventory1 = InventoryFixture.inventory(1L, item); + Inventory inventory2 = InventoryFixture.inventory(member2.getId(), item); + Inventory inventory3 = InventoryFixture.inventory(member3.getId(), item); + inventory1.select(); + inventory2.select(); + inventory3.select(); + + itemRepository.save(item); + inventoryRepository.saveAll(List.of(inventory1, inventory2, inventory3)); Participant participant2 = RoomFixture.participant(room, member2.getId()); Participant participant3 = RoomFixture.participant(room, member3.getId());