From 3b28b7cfd26297a1f984f62db1a3289479ed7399 Mon Sep 17 00:00:00 2001 From: ymkim97 Date: Fri, 17 Nov 2023 20:14:22 +0900 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20=EB=B0=A9=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/moabam/api/presentation/RoomController.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/moabam/api/presentation/RoomController.java b/src/main/java/com/moabam/api/presentation/RoomController.java index 44f642b6..f28277eb 100644 --- a/src/main/java/com/moabam/api/presentation/RoomController.java +++ b/src/main/java/com/moabam/api/presentation/RoomController.java @@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; @@ -18,12 +19,14 @@ import com.moabam.api.application.room.RoomCertificationService; import com.moabam.api.application.room.RoomSearchService; import com.moabam.api.application.room.RoomService; +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.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.CurrentMember; import com.moabam.global.auth.model.AuthorizationMember; @@ -44,7 +47,7 @@ public class RoomController { public Long createRoom(@CurrentMember AuthorizationMember authorizationMember, @Valid @RequestBody CreateRoomRequest createRoomRequest) { - return roomService.createRoom(authorizationMember.id(), createRoomRequest); + return roomService.createRoom(authorizationMember.id(), authorizationMember.nickname(), createRoomRequest); } @PutMapping("/{roomId}") @@ -112,4 +115,12 @@ public MyRoomsResponse getMyRooms(@CurrentMember AuthorizationMember authorizati public RoomsHistoryResponse getJoinHistory(@CurrentMember AuthorizationMember authorizationMember) { return roomSearchService.getJoinHistory(authorizationMember.id()); } + + @GetMapping + @ResponseStatus(HttpStatus.OK) + public SearchAllRoomsResponse searchAllRooms(@RequestParam(value = "type") RoomType roomType, + @RequestParam(value = "roomId", required = false) Long roomId) { + + return roomSearchService.searchAllRooms(roomType, roomId); + } } From 9acb1e3b782cba87c33450384c084be22daf425f Mon Sep 17 00:00:00 2001 From: ymkim97 Date: Fri, 17 Nov 2023 20:15:11 +0900 Subject: [PATCH 2/8] =?UTF-8?q?refactor:=20=EB=B0=A9=EC=9E=A5=20member=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=20=EA=B8=B0=EB=8A=A5=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/application/member/MemberService.java | 7 ---- .../repository/MemberSearchRepository.java | 33 ------------------- 2 files changed, 40 deletions(-) delete mode 100644 src/main/java/com/moabam/api/domain/member/repository/MemberSearchRepository.java 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 7e984867..09190e18 100644 --- a/src/main/java/com/moabam/api/application/member/MemberService.java +++ b/src/main/java/com/moabam/api/application/member/MemberService.java @@ -13,7 +13,6 @@ import com.moabam.api.application.auth.mapper.AuthMapper; import com.moabam.api.domain.member.Member; import com.moabam.api.domain.member.repository.MemberRepository; -import com.moabam.api.domain.member.repository.MemberSearchRepository; import com.moabam.api.dto.auth.AuthorizationTokenInfoResponse; import com.moabam.api.dto.auth.LoginResponse; import com.moabam.global.error.exception.NotFoundException; @@ -26,7 +25,6 @@ public class MemberService { private final MemberRepository memberRepository; - private final MemberSearchRepository memberSearchRepository; public Member getById(Long memberId) { return memberRepository.findById(memberId) @@ -53,11 +51,6 @@ private String createRandomNickName() { new SecureRandom()); } - public Member getManager(Long roomId) { - return memberSearchRepository.findManager(roomId) - .orElseThrow(() -> new NotFoundException(MEMBER_NOT_FOUND)); - } - public List getRoomMembers(List memberIds) { return memberRepository.findAllById(memberIds); } diff --git a/src/main/java/com/moabam/api/domain/member/repository/MemberSearchRepository.java b/src/main/java/com/moabam/api/domain/member/repository/MemberSearchRepository.java deleted file mode 100644 index 47ff7ab8..00000000 --- a/src/main/java/com/moabam/api/domain/member/repository/MemberSearchRepository.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.moabam.api.domain.member.repository; - -import static com.moabam.api.domain.member.QMember.*; -import static com.moabam.api.domain.room.QParticipant.*; - -import java.util.Optional; - -import org.springframework.stereotype.Repository; - -import com.moabam.api.domain.member.Member; -import com.querydsl.jpa.impl.JPAQueryFactory; - -import lombok.RequiredArgsConstructor; - -@Repository -@RequiredArgsConstructor -public class MemberSearchRepository { - - private final JPAQueryFactory jpaQueryFactory; - - public Optional findManager(Long roomId) { - return Optional.ofNullable( - jpaQueryFactory - .selectFrom(member) - .innerJoin(participant).on(member.id.eq(participant.memberId)) - .where( - participant.isManager.eq(true), - participant.room.id.eq(roomId) - ) - .fetchOne() - ); - } -} From 47686c4aefb09ebb40397efd674ec670a993d7b8 Mon Sep 17 00:00:00 2001 From: ymkim97 Date: Fri, 17 Nov 2023 20:16:45 +0900 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20=EB=B0=A9=20=EA=B2=80=EC=83=89=20dt?= =?UTF-8?q?o=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/room/mapper/RoomMapper.java | 27 +++++++++++++++++++ .../api/dto/room/SearchAllRoomResponse.java | 24 +++++++++++++++++ .../api/dto/room/SearchAllRoomsResponse.java | 13 +++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/main/java/com/moabam/api/dto/room/SearchAllRoomResponse.java create mode 100644 src/main/java/com/moabam/api/dto/room/SearchAllRoomsResponse.java 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 6435531f..7f6abdf8 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 @@ -12,6 +12,8 @@ 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; @@ -86,4 +88,29 @@ public static RoomsHistoryResponse toRoomsHistoryResponse(List routineResponses, + boolean isPassword) { + return SearchAllRoomResponse.builder() + .id(room.getId()) + .title(room.getTitle()) + .image(room.getRoomImage()) + .isPassword(isPassword) + .managerNickname(room.getManagerNickname()) + .level(room.getLevel()) + .roomType(room.getRoomType()) + .certifyTime(room.getCertifyTime()) + .currentUserCount(room.getCurrentUserCount()) + .maxUserCount(room.getMaxUserCount()) + .routine(routineResponses) + .build(); + } + + public static SearchAllRoomsResponse toSearchAllRoomsResponse(boolean hasNext, + List searchAllRoomResponses) { + return SearchAllRoomsResponse.builder() + .hasNext(hasNext) + .rooms(searchAllRoomResponses) + .build(); + } } diff --git a/src/main/java/com/moabam/api/dto/room/SearchAllRoomResponse.java b/src/main/java/com/moabam/api/dto/room/SearchAllRoomResponse.java new file mode 100644 index 00000000..1960f105 --- /dev/null +++ b/src/main/java/com/moabam/api/dto/room/SearchAllRoomResponse.java @@ -0,0 +1,24 @@ +package com.moabam.api.dto.room; + +import java.util.List; + +import com.moabam.api.domain.room.RoomType; + +import lombok.Builder; + +@Builder +public record SearchAllRoomResponse( + Long id, + String title, + String image, + boolean isPassword, + String managerNickname, + int level, + RoomType roomType, + int certifyTime, + int currentUserCount, + int maxUserCount, + List routine +) { + +} diff --git a/src/main/java/com/moabam/api/dto/room/SearchAllRoomsResponse.java b/src/main/java/com/moabam/api/dto/room/SearchAllRoomsResponse.java new file mode 100644 index 00000000..1d2eb960 --- /dev/null +++ b/src/main/java/com/moabam/api/dto/room/SearchAllRoomsResponse.java @@ -0,0 +1,13 @@ +package com.moabam.api.dto.room; + +import java.util.List; + +import lombok.Builder; + +@Builder +public record SearchAllRoomsResponse( + boolean hasNext, + List rooms +) { + +} From dc4e0408c7d22b830d6695ef0d7f3e85d992d248 Mon Sep 17 00:00:00 2001 From: ymkim97 Date: Fri, 17 Nov 2023 20:17:32 +0900 Subject: [PATCH 4/8] =?UTF-8?q?feat:=20=EB=B0=A9=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/room/RoomSearchService.java | 42 +++++++++++++++++-- .../api/application/room/RoomService.java | 7 +++- .../java/com/moabam/api/domain/room/Room.java | 7 ++++ .../room/repository/RoomSearchRepository.java | 33 +++++++++++++++ .../repository/RoutineSearchRepository.java | 9 ++++ .../global/common/util/GlobalConstant.java | 2 +- 6 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/moabam/api/domain/room/repository/RoomSearchRepository.java diff --git a/src/main/java/com/moabam/api/application/room/RoomSearchService.java b/src/main/java/com/moabam/api/application/room/RoomSearchService.java index ec6fddc9..4e1d9d42 100644 --- a/src/main/java/com/moabam/api/application/room/RoomSearchService.java +++ b/src/main/java/com/moabam/api/application/room/RoomSearchService.java @@ -1,7 +1,8 @@ package com.moabam.api.application.room; -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.common.util.GlobalConstant.*; +import static com.moabam.global.error.model.ErrorMessage.*; +import static org.apache.commons.lang3.StringUtils.*; import java.time.LocalDate; import java.time.Period; @@ -22,9 +23,11 @@ import com.moabam.api.domain.room.DailyRoomCertification; 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.Routine; import com.moabam.api.domain.room.repository.CertificationsSearchRepository; import com.moabam.api.domain.room.repository.ParticipantSearchRepository; +import com.moabam.api.domain.room.repository.RoomSearchRepository; import com.moabam.api.domain.room.repository.RoutineSearchRepository; import com.moabam.api.dto.room.CertificationImageResponse; import com.moabam.api.dto.room.MyRoomResponse; @@ -33,9 +36,12 @@ 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.error.exception.NotFoundException; +import jakarta.annotation.Nullable; import lombok.RequiredArgsConstructor; @Service @@ -46,6 +52,7 @@ public class RoomSearchService { private final CertificationsSearchRepository certificationsSearchRepository; private final ParticipantSearchRepository participantSearchRepository; private final RoutineSearchRepository routineSearchRepository; + private final RoomSearchRepository roomSearchRepository; private final MemberService memberService; private final RoomCertificationService roomCertificationService; @@ -55,7 +62,7 @@ public RoomDetailsResponse getRoomDetails(Long memberId, Long roomId) { .orElseThrow(() -> new NotFoundException(PARTICIPANT_NOT_FOUND)); Room room = participant.getRoom(); - String managerNickname = memberService.getManager(roomId).getNickname(); + String managerNickname = room.getManagerNickname(); List dailyMemberCertifications = certificationsSearchRepository.findSortedDailyMemberCertifications(roomId, today); List routineResponses = getRoutineResponses(roomId); @@ -105,6 +112,35 @@ public RoomsHistoryResponse getJoinHistory(Long memberId) { return RoomMapper.toRoomsHistoryResponse(roomHistoryResponses); } + public SearchAllRoomsResponse searchAllRooms(@Nullable RoomType roomType, @Nullable Long roomId) { + List searchAllRoomResponses = new ArrayList<>(); + List rooms = roomSearchRepository.findAllWithNoOffset(roomType, roomId); + + boolean hasNext = false; + + if (rooms.size() > ROOM_FIXED_SEARCH_SIZE) { + hasNext = true; + rooms.remove(ROOM_FIXED_SEARCH_SIZE); + } + + List roomIds = rooms.stream().map(Room::getId).toList(); + List routines = routineSearchRepository.findAllByRoomIds(roomIds); + + for (Room room : rooms) { + List filteredRoutines = routines.stream() + .filter(routine -> routine.getRoom().getId().equals(room.getId())) + .toList(); + + boolean isPassword = !isEmpty(room.getPassword()); + + searchAllRoomResponses.add( + RoomMapper.toSearchAllRoomResponse(room, RoutineMapper.toRoutineResponses(filteredRoutines), + isPassword)); + } + + return RoomMapper.toSearchAllRoomsResponse(hasNext, searchAllRoomResponses); + } + private List getRoutineResponses(Long roomId) { List roomRoutines = routineSearchRepository.findAllByRoomId(roomId); 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 c7c217e3..4775031f 100644 --- a/src/main/java/com/moabam/api/application/room/RoomService.java +++ b/src/main/java/com/moabam/api/application/room/RoomService.java @@ -44,7 +44,7 @@ public class RoomService { private final MemberService memberService; @Transactional - public Long createRoom(Long memberId, CreateRoomRequest createRoomRequest) { + 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() @@ -59,6 +59,7 @@ public Long createRoom(Long memberId, CreateRoomRequest createRoomRequest) { increaseRoomCount(memberId, room.getRoomType()); participant.enableManager(); + room.changeManagerNickname(nickname); Room savedRoom = roomRepository.save(room); routineRepository.saveAll(routines); participantRepository.save(participant); @@ -128,6 +129,10 @@ public void mandateRoomManager(Long managerId, Long roomId, Long memberId) { Participant memberParticipant = getParticipant(memberId, roomId); validateManagerAuthorization(managerParticipant); + Room room = managerParticipant.getRoom(); + Member member = memberService.getById(memberParticipant.getMemberId()); + room.changeManagerNickname(member.getNickname()); + managerParticipant.disableManager(); memberParticipant.enableManager(); } diff --git a/src/main/java/com/moabam/api/domain/room/Room.java b/src/main/java/com/moabam/api/domain/room/Room.java index 4608ced6..a1d93c20 100644 --- a/src/main/java/com/moabam/api/domain/room/Room.java +++ b/src/main/java/com/moabam/api/domain/room/Room.java @@ -76,6 +76,9 @@ public class Room extends BaseTimeEntity { @Column(name = "room_image", length = 500) private String roomImage; + @Column(name = "manager_nickname", length = 30) + private String managerNickname; + @Builder private Room(Long id, String title, String password, RoomType roomType, int certifyTime, int maxUserCount) { this.id = id; @@ -111,6 +114,10 @@ public void changePassword(String password) { this.password = password; } + public void changeManagerNickname(String managerNickname) { + this.managerNickname = managerNickname; + } + public void changeMaxCount(int maxUserCount) { if (maxUserCount < this.currentUserCount) { throw new BadRequestException(ROOM_MAX_USER_COUNT_MODIFY_FAIL); diff --git a/src/main/java/com/moabam/api/domain/room/repository/RoomSearchRepository.java b/src/main/java/com/moabam/api/domain/room/repository/RoomSearchRepository.java new file mode 100644 index 00000000..3fc64784 --- /dev/null +++ b/src/main/java/com/moabam/api/domain/room/repository/RoomSearchRepository.java @@ -0,0 +1,33 @@ +package com.moabam.api.domain.room.repository; + +import static com.moabam.api.domain.room.QRoom.*; +import static com.moabam.global.common.util.GlobalConstant.*; + +import java.util.List; + +import org.springframework.stereotype.Repository; + +import com.moabam.api.domain.room.Room; +import com.moabam.api.domain.room.RoomType; +import com.moabam.global.common.util.DynamicQuery; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import lombok.RequiredArgsConstructor; + +@Repository +@RequiredArgsConstructor +public class RoomSearchRepository { + + private final JPAQueryFactory jpaQueryFactory; + + public List findAllWithNoOffset(RoomType roomType, Long roomId) { + return jpaQueryFactory.selectFrom(room) + .where( + DynamicQuery.generateEq(roomType, room.roomType::eq), + DynamicQuery.generateEq(roomId, room.id::lt) + ) + .orderBy(room.id.desc()) + .limit(ROOM_FIXED_SEARCH_SIZE + 1) + .fetch(); + } +} 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 index 827e1b0d..087d22b6 100644 --- a/src/main/java/com/moabam/api/domain/room/repository/RoutineSearchRepository.java +++ b/src/main/java/com/moabam/api/domain/room/repository/RoutineSearchRepository.java @@ -25,4 +25,13 @@ public List findAllByRoomId(Long 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/global/common/util/GlobalConstant.java b/src/main/java/com/moabam/global/common/util/GlobalConstant.java index 8f43ec67..81a059ac 100644 --- a/src/main/java/com/moabam/global/common/util/GlobalConstant.java +++ b/src/main/java/com/moabam/global/common/util/GlobalConstant.java @@ -16,6 +16,6 @@ public class GlobalConstant { public static final int HOURS_IN_A_DAY = 24; public static final String KNOCK_KEY = "room_%s_member_%s_knocks_%s"; public static final String FIREBASE_PATH = "config/moabam-firebase.json"; - + public static final int ROOM_FIXED_SEARCH_SIZE = 10; public static final int LEVEL_DIVISOR = 10; } From 7a47230adeb57a496e9303d9f9a5eaaee48445d3 Mon Sep 17 00:00:00 2001 From: ymkim97 Date: Sat, 18 Nov 2023 13:10:48 +0900 Subject: [PATCH 5/8] =?UTF-8?q?fix:=20=EC=84=9C=EB=B9=84=EC=8A=A4,=20?= =?UTF-8?q?=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/application/room/RoomSearchService.java | 2 +- .../com/moabam/api/presentation/RoomController.java | 2 +- src/main/resources/static/docs/coupon.html | 12 ++++++------ src/main/resources/static/docs/index.html | 2 +- src/main/resources/static/docs/notification.html | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/moabam/api/application/room/RoomSearchService.java b/src/main/java/com/moabam/api/application/room/RoomSearchService.java index 4e1d9d42..59dee5ba 100644 --- a/src/main/java/com/moabam/api/application/room/RoomSearchService.java +++ b/src/main/java/com/moabam/api/application/room/RoomSearchService.java @@ -114,7 +114,7 @@ public RoomsHistoryResponse getJoinHistory(Long memberId) { public SearchAllRoomsResponse searchAllRooms(@Nullable RoomType roomType, @Nullable Long roomId) { List searchAllRoomResponses = new ArrayList<>(); - List rooms = roomSearchRepository.findAllWithNoOffset(roomType, roomId); + List rooms = new ArrayList<>(roomSearchRepository.findAllWithNoOffset(roomType, roomId)); boolean hasNext = false; diff --git a/src/main/java/com/moabam/api/presentation/RoomController.java b/src/main/java/com/moabam/api/presentation/RoomController.java index f28277eb..0d1dd917 100644 --- a/src/main/java/com/moabam/api/presentation/RoomController.java +++ b/src/main/java/com/moabam/api/presentation/RoomController.java @@ -118,7 +118,7 @@ public RoomsHistoryResponse getJoinHistory(@CurrentMember AuthorizationMember au @GetMapping @ResponseStatus(HttpStatus.OK) - public SearchAllRoomsResponse searchAllRooms(@RequestParam(value = "type") RoomType roomType, + public SearchAllRoomsResponse searchAllRooms(@RequestParam(value = "type", required = false) RoomType roomType, @RequestParam(value = "roomId", required = false) Long roomId) { return roomSearchService.searchAllRooms(roomType, roomId); diff --git a/src/main/resources/static/docs/coupon.html b/src/main/resources/static/docs/coupon.html index c9cdad6e..406bcda8 100644 --- a/src/main/resources/static/docs/coupon.html +++ b/src/main/resources/static/docs/coupon.html @@ -461,7 +461,7 @@

요청

POST /admins/coupons HTTP/1.1
 Content-Type: application/json;charset=UTF-8
-Content-Length: 200
+Content-Length: 192
 Host: localhost:8080
 
 {
@@ -483,7 +483,7 @@ 

응답

Vary: Access-Control-Request-Method Vary: Access-Control-Request-Headers Content-Type: application/json -Content-Length: 64 +Content-Length: 62 { "message" : "쿠폰의 이름이 중복되었습니다." @@ -514,7 +514,7 @@

응답

Vary: Access-Control-Request-Method Vary: Access-Control-Request-Headers Content-Type: application/json -Content-Length: 58 +Content-Length: 56 { "message" : "존재하지 않는 쿠폰입니다." @@ -546,7 +546,7 @@

응답

Vary: Access-Control-Request-Method Vary: Access-Control-Request-Headers Content-Type: application/json -Content-Length: 58 +Content-Length: 56 { "message" : "존재하지 않는 쿠폰입니다." @@ -569,7 +569,7 @@

요청

POST /coupons/search HTTP/1.1
 Content-Type: application/json;charset=UTF-8
-Content-Length: 88
+Content-Length: 84
 Host: localhost:8080
 
 {
@@ -627,7 +627,7 @@ 

쿠폰 사용 (진행 중)

diff --git a/src/main/resources/static/docs/index.html b/src/main/resources/static/docs/index.html index b31d0579..8f28a0c8 100644 --- a/src/main/resources/static/docs/index.html +++ b/src/main/resources/static/docs/index.html @@ -616,7 +616,7 @@

diff --git a/src/main/resources/static/docs/notification.html b/src/main/resources/static/docs/notification.html index c15a126c..0673186a 100644 --- a/src/main/resources/static/docs/notification.html +++ b/src/main/resources/static/docs/notification.html @@ -473,7 +473,7 @@

응답

Vary: Access-Control-Request-Method Vary: Access-Control-Request-Headers Content-Type: application/json -Content-Length: 66 +Content-Length: 64 { "message" : "이미 콕 알림을 보낸 대상입니다." @@ -487,7 +487,7 @@

응답

From 962c5102ff4a8f6ea5bd86a038a830185ec45aec Mon Sep 17 00:00:00 2001 From: ymkim97 Date: Sat, 18 Nov 2023 13:11:38 +0900 Subject: [PATCH 6/8] =?UTF-8?q?test:=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EB=8B=A8=EC=9C=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../room/RoomSearchServiceTest.java | 182 +++++++++++++++++- .../api/application/room/RoomServiceTest.java | 7 +- .../moabam/support/fixture/RoomFixture.java | 21 +- 3 files changed, 198 insertions(+), 12 deletions(-) diff --git a/src/test/java/com/moabam/api/application/room/RoomSearchServiceTest.java b/src/test/java/com/moabam/api/application/room/RoomSearchServiceTest.java index ff9663a9..23d136da 100644 --- a/src/test/java/com/moabam/api/application/room/RoomSearchServiceTest.java +++ b/src/test/java/com/moabam/api/application/room/RoomSearchServiceTest.java @@ -1,9 +1,7 @@ package com.moabam.api.application.room; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.spy; -import static org.mockito.Mockito.when; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.BDDMockito.*; import java.time.LocalDate; import java.time.LocalDateTime; @@ -20,11 +18,14 @@ 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.Routine; import com.moabam.api.domain.room.repository.CertificationsSearchRepository; import com.moabam.api.domain.room.repository.ParticipantSearchRepository; +import com.moabam.api.domain.room.repository.RoomSearchRepository; import com.moabam.api.domain.room.repository.RoutineSearchRepository; import com.moabam.api.dto.room.MyRoomsResponse; import com.moabam.api.dto.room.RoomsHistoryResponse; +import com.moabam.api.dto.room.SearchAllRoomsResponse; import com.moabam.support.fixture.RoomFixture; @ExtendWith(MockitoExtension.class) @@ -42,6 +43,9 @@ class RoomSearchServiceTest { @Mock private RoutineSearchRepository routineSearchRepository; + @Mock + private RoomSearchRepository roomSearchRepository; + @Mock private MemberService memberService; @@ -130,4 +134,174 @@ void get_my_join_history_success() { assertThat(response.roomHistory().get(2).deletedAt()).isNotNull(); assertThat(response.roomHistory().get(2).title()).isEqualTo(participant3.getDeletedRoomTitle()); } + + @DisplayName("아침, 저녁 전체 방 조회 성공, 첫 번째 조회, 다음 페이지 있음") + @Test + void search_all_morning_night_rooms_success() { + // given + Room room1 = spy(RoomFixture.room("아침 - 첫 번째 방", RoomType.MORNING, 10, "1234")); + Room room2 = spy(RoomFixture.room("아침 - 두 번째 방", RoomType.MORNING, 9)); + Room room3 = spy(RoomFixture.room("밤 - 세 번째 방", RoomType.NIGHT, 22)); + Room room4 = spy(RoomFixture.room("아침 - 네 번째 방", RoomType.MORNING, 7)); + Room room5 = spy(RoomFixture.room("밤 - 다섯 번째 방", RoomType.NIGHT, 23, "5869")); + Room room6 = spy(RoomFixture.room("아침 - 여섯 번째 방", RoomType.MORNING, 8)); + Room room7 = spy(RoomFixture.room("밤 - 일곱 번째 방", RoomType.NIGHT, 20)); + Room room8 = spy(RoomFixture.room("밤 - 여덟 번째 방", RoomType.NIGHT, 1, "5236")); + Room room9 = spy(RoomFixture.room("아침 - 아홉 번째 방", RoomType.MORNING, 4)); + Room room10 = spy(RoomFixture.room("밤 - 열 번째 방", RoomType.NIGHT, 1, "97979")); + Room room11 = spy(RoomFixture.room("밤 - 열하나 번째 방", RoomType.NIGHT, 22)); + Room room12 = spy(RoomFixture.room("아침 - 열둘 번째 방", RoomType.MORNING, 10)); + Room room13 = spy(RoomFixture.room("밤 - 열셋 번째 방", RoomType.NIGHT, 2)); + Room room14 = spy(RoomFixture.room("밤 - 열넷 번째 방", RoomType.NIGHT, 21)); + + given(room1.getId()).willReturn(1L); + given(room2.getId()).willReturn(2L); + given(room3.getId()).willReturn(3L); + given(room4.getId()).willReturn(4L); + given(room5.getId()).willReturn(5L); + given(room6.getId()).willReturn(6L); + given(room7.getId()).willReturn(7L); + given(room8.getId()).willReturn(8L); + given(room9.getId()).willReturn(9L); + given(room10.getId()).willReturn(10L); + given(room11.getId()).willReturn(11L); + given(room12.getId()).willReturn(12L); + given(room13.getId()).willReturn(13L); + given(room14.getId()).willReturn(14L); + + List rooms = List.of(room1, room2, room3, room4, room5, room6, room7, room8, room9, room10, room11); + + Routine routine1 = spy(RoomFixture.routine(room1, "방1의 루틴1")); + Routine routine2 = spy(RoomFixture.routine(room1, "방1의 루틴2")); + + Routine routine3 = spy(RoomFixture.routine(room2, "방2의 루틴1")); + Routine routine4 = spy(RoomFixture.routine(room2, "방2의 루틴2")); + + Routine routine5 = spy(RoomFixture.routine(room3, "방3의 루틴1")); + Routine routine6 = spy(RoomFixture.routine(room3, "방3의 루틴2")); + + Routine routine7 = spy(RoomFixture.routine(room4, "방4의 루틴1")); + Routine routine8 = spy(RoomFixture.routine(room4, "방4의 루틴2")); + + Routine routine9 = spy(RoomFixture.routine(room5, "방5의 루틴1")); + Routine routine10 = spy(RoomFixture.routine(room5, "방5의 루틴2")); + + Routine routine11 = spy(RoomFixture.routine(room6, "방6의 루틴1")); + Routine routine12 = spy(RoomFixture.routine(room6, "방6의 루틴2")); + + Routine routine13 = spy(RoomFixture.routine(room7, "방7의 루틴1")); + Routine routine14 = spy(RoomFixture.routine(room7, "방7의 루틴2")); + + Routine routine15 = spy(RoomFixture.routine(room8, "방8의 루틴1")); + Routine routine16 = spy(RoomFixture.routine(room8, "방8의 루틴2")); + + Routine routine17 = spy(RoomFixture.routine(room9, "방9의 루틴1")); + Routine routine18 = spy(RoomFixture.routine(room9, "방9의 루틴2")); + + Routine routine19 = spy(RoomFixture.routine(room10, "방10의 루틴1")); + Routine routine20 = spy(RoomFixture.routine(room10, "방10의 루틴2")); + + Routine routine21 = spy(RoomFixture.routine(room11, "방11의 루틴1")); + Routine routine22 = spy(RoomFixture.routine(room11, "방11의 루틴2")); + + Routine routine23 = spy(RoomFixture.routine(room12, "방12의 루틴1")); + Routine routine24 = spy(RoomFixture.routine(room12, "방12의 루틴2")); + + Routine routine25 = spy(RoomFixture.routine(room13, "방13의 루틴1")); + Routine routine26 = spy(RoomFixture.routine(room13, "방13의 루틴2")); + + Routine routine27 = spy(RoomFixture.routine(room14, "방14의 루틴1")); + Routine routine28 = spy(RoomFixture.routine(room14, "방14의 루틴2")); + + given(routine1.getId()).willReturn(1L); + given(routine2.getId()).willReturn(2L); + given(routine3.getId()).willReturn(3L); + given(routine4.getId()).willReturn(4L); + given(routine5.getId()).willReturn(5L); + given(routine6.getId()).willReturn(6L); + given(routine7.getId()).willReturn(7L); + given(routine8.getId()).willReturn(8L); + given(routine9.getId()).willReturn(9L); + given(routine10.getId()).willReturn(10L); + given(routine11.getId()).willReturn(11L); + given(routine12.getId()).willReturn(12L); + given(routine13.getId()).willReturn(13L); + given(routine14.getId()).willReturn(14L); + given(routine15.getId()).willReturn(15L); + given(routine16.getId()).willReturn(16L); + given(routine17.getId()).willReturn(17L); + given(routine18.getId()).willReturn(18L); + given(routine19.getId()).willReturn(19L); + given(routine20.getId()).willReturn(20L); + + List routines = List.of(routine1, routine2, routine3, routine4, routine5, routine6, routine7, routine8, + routine9, routine10, routine11, routine12, routine13, routine14, routine15, routine16, routine17, routine18, + routine19, routine20, routine21, routine22, routine23, routine24, routine25, routine26, routine27, + routine28); + + given(roomSearchRepository.findAllWithNoOffset(null, null)).willReturn(rooms); + given(routineSearchRepository.findAllByRoomIds(anyList())).willReturn(routines); + + // when + SearchAllRoomsResponse searchAllRoomsResponse = roomSearchService.searchAllRooms(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); + } + + @DisplayName("아침, 저녁 전체 방 조회 성공, 마지막 페이 조회, 다음 페이지 없음") + @Test + void search_last_page_all_morning_night_rooms_success() { + // given + Room room11 = spy(RoomFixture.room("밤 - 열하나 번째 방", RoomType.NIGHT, 22)); + Room room12 = spy(RoomFixture.room("아침 - 열둘 번째 방", RoomType.MORNING, 10)); + Room room13 = spy(RoomFixture.room("밤 - 열셋 번째 방", RoomType.NIGHT, 2)); + Room room14 = spy(RoomFixture.room("밤 - 열넷 번째 방", RoomType.NIGHT, 21)); + + given(room11.getId()).willReturn(11L); + given(room12.getId()).willReturn(12L); + given(room13.getId()).willReturn(13L); + given(room14.getId()).willReturn(14L); + + List rooms = List.of(room11, room12, room13, room14); + + Routine routine21 = spy(RoomFixture.routine(room11, "방11의 루틴1")); + Routine routine22 = spy(RoomFixture.routine(room11, "방11의 루틴2")); + + Routine routine23 = spy(RoomFixture.routine(room12, "방12의 루틴1")); + Routine routine24 = spy(RoomFixture.routine(room12, "방12의 루틴2")); + + Routine routine25 = spy(RoomFixture.routine(room13, "방13의 루틴1")); + Routine routine26 = spy(RoomFixture.routine(room13, "방13의 루틴2")); + + Routine routine27 = spy(RoomFixture.routine(room14, "방14의 루틴1")); + Routine routine28 = spy(RoomFixture.routine(room14, "방14의 루틴2")); + + given(routine21.getId()).willReturn(21L); + given(routine22.getId()).willReturn(22L); + given(routine23.getId()).willReturn(23L); + given(routine24.getId()).willReturn(24L); + given(routine25.getId()).willReturn(25L); + given(routine26.getId()).willReturn(26L); + given(routine27.getId()).willReturn(27L); + given(routine28.getId()).willReturn(28L); + + List routines = List.of(routine21, routine22, routine23, routine24, routine25, routine26, routine27, + routine28); + + given(roomSearchRepository.findAllWithNoOffset(null, 10L)).willReturn(rooms); + given(routineSearchRepository.findAllByRoomIds(anyList())).willReturn(routines); + + // when + SearchAllRoomsResponse searchAllRoomsResponse = roomSearchService.searchAllRooms(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); + } } 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 d6f8089b..e55710bc 100644 --- a/src/test/java/com/moabam/api/application/room/RoomServiceTest.java +++ b/src/test/java/com/moabam/api/application/room/RoomServiceTest.java @@ -70,7 +70,7 @@ void create_room_no_password_success() { given(memberService.getById(1L)).willReturn(member); // when - Long result = roomService.createRoom(1L, createRoomRequest); + Long result = roomService.createRoom(1L, "닉네임", createRoomRequest); // then verify(roomRepository).save(any(Room.class)); @@ -98,7 +98,7 @@ void create_room_with_password_success() { given(memberService.getById(1L)).willReturn(member); // when - Long result = roomService.createRoom(1L, createRoomRequest); + Long result = roomService.createRoom(1L, "닉네임", createRoomRequest); // then verify(roomRepository).save(any(Room.class)); @@ -115,6 +115,8 @@ void room_manager_mandate_success() { Long managerId = 1L; Long memberId = 2L; + Member member = MemberFixture.member(1234L, "닉네임"); + Room room = spy(RoomFixture.room()); given(room.getId()).willReturn(1L); @@ -126,6 +128,7 @@ void room_manager_mandate_success() { Optional.of(memberParticipant)); given(participantSearchRepository.findOne(managerId, room.getId())).willReturn( Optional.of(managerParticipant)); + given(memberService.getById(2L)).willReturn(member); // when roomService.mandateRoomManager(managerId, room.getId(), memberId); diff --git a/src/test/java/com/moabam/support/fixture/RoomFixture.java b/src/test/java/com/moabam/support/fixture/RoomFixture.java index ccdce73f..dbe7213d 100644 --- a/src/test/java/com/moabam/support/fixture/RoomFixture.java +++ b/src/test/java/com/moabam/support/fixture/RoomFixture.java @@ -46,12 +46,14 @@ public static Room room(String title, RoomType roomType, int certifyTime) { .build(); } - public static List rooms() { - return List.of( - room("아침 - 첫 번째 방", RoomType.MORNING, 10), - room("아침 - 두 번째 방", RoomType.MORNING, 9), - room("밤 - 첫 번째 방", RoomType.NIGHT, 22) - ); + public static Room room(String title, RoomType roomType, int certifyTime, String password) { + return Room.builder() + .title(title) + .password(password) + .roomType(roomType) + .certifyTime(certifyTime) + .maxUserCount(8) + .build(); } public static Participant participant(Room room, Long memberId) { @@ -61,6 +63,13 @@ public static Participant participant(Room room, Long memberId) { .build(); } + public static Routine routine(Room room, String content) { + return Routine.builder() + .room(room) + .content(content) + .build(); + } + public static List routines(Room room) { List routines = new ArrayList<>(); From 0d3eac0f1d18efaba837952c64b0eeb26762719e Mon Sep 17 00:00:00 2001 From: ymkim97 Date: Sat, 18 Nov 2023 13:11:48 +0900 Subject: [PATCH 7/8] =?UTF-8?q?test:=20=ED=86=B5=ED=95=A9=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/presentation/RoomControllerTest.java | 326 +++++++++++++++++- 1 file changed, 315 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/moabam/api/presentation/RoomControllerTest.java b/src/test/java/com/moabam/api/presentation/RoomControllerTest.java index f351162d..f5bebe47 100644 --- a/src/test/java/com/moabam/api/presentation/RoomControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/RoomControllerTest.java @@ -1,16 +1,11 @@ package com.moabam.api.presentation; -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 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 java.time.LocalDate; import java.util.ArrayList; @@ -37,6 +32,7 @@ import com.moabam.api.domain.room.DailyRoomCertification; 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.Routine; import com.moabam.api.domain.room.repository.CertificationRepository; import com.moabam.api.domain.room.repository.DailyMemberCertificationRepository; @@ -920,4 +916,312 @@ void get_join_history_success() throws Exception { .andExpect(status().isOk()) .andDo(print()); } + + @DisplayName("아침, 저녁 방 전체 조회 성공 - 첫 번째 조회, 다음 페이지 있음") + @WithMember(id = 1L) + @Test + void search_all_morning_night_rooms_success() throws Exception { + // given + Room room1 = RoomFixture.room("아침 - 첫 번째 방", RoomType.MORNING, 10, "1234"); + Room room2 = RoomFixture.room("아침 - 두 번째 방", RoomType.MORNING, 9); + Room room3 = RoomFixture.room("밤 - 세 번째 방", RoomType.NIGHT, 22); + Room room4 = RoomFixture.room("아침 - 네 번째 방", RoomType.MORNING, 7); + Room room5 = RoomFixture.room("밤 - 다섯 번째 방", RoomType.NIGHT, 23, "5869"); + Room room6 = RoomFixture.room("아침 - 여섯 번째 방", RoomType.MORNING, 8); + Room room7 = RoomFixture.room("밤 - 일곱 번째 방", RoomType.NIGHT, 20); + Room room8 = RoomFixture.room("밤 - 여덟 번째 방", RoomType.NIGHT, 1, "5236"); + Room room9 = RoomFixture.room("아침 - 아홉 번째 방", RoomType.MORNING, 4); + Room room10 = RoomFixture.room("밤 - 열 번째 방", RoomType.NIGHT, 1, "97979"); + Room room11 = RoomFixture.room("밤 - 열하나 번째 방", RoomType.NIGHT, 22); + Room room12 = RoomFixture.room("아침 - 열둘 번째 방", RoomType.MORNING, 10); + Room room13 = RoomFixture.room("밤 - 열셋 번째 방", RoomType.NIGHT, 2); + Room room14 = RoomFixture.room("밤 - 열넷 번째 방", RoomType.NIGHT, 21); + + Routine routine1 = RoomFixture.routine(room1, "방1의 루틴1"); + Routine routine2 = RoomFixture.routine(room1, "방1의 루틴2"); + + Routine routine3 = RoomFixture.routine(room2, "방2의 루틴1"); + Routine routine4 = RoomFixture.routine(room2, "방2의 루틴2"); + + Routine routine5 = RoomFixture.routine(room3, "방3의 루틴1"); + Routine routine6 = RoomFixture.routine(room3, "방3의 루틴2"); + + Routine routine7 = RoomFixture.routine(room4, "방4의 루틴1"); + Routine routine8 = RoomFixture.routine(room4, "방4의 루틴2"); + + Routine routine9 = RoomFixture.routine(room5, "방5의 루틴1"); + Routine routine10 = RoomFixture.routine(room5, "방5의 루틴2"); + + Routine routine11 = RoomFixture.routine(room6, "방6의 루틴1"); + Routine routine12 = RoomFixture.routine(room6, "방6의 루틴2"); + + Routine routine13 = RoomFixture.routine(room7, "방7의 루틴1"); + Routine routine14 = RoomFixture.routine(room7, "방7의 루틴2"); + + Routine routine15 = RoomFixture.routine(room8, "방8의 루틴1"); + Routine routine16 = RoomFixture.routine(room8, "방8의 루틴2"); + + Routine routine17 = RoomFixture.routine(room9, "방9의 루틴1"); + Routine routine18 = RoomFixture.routine(room9, "방9의 루틴2"); + + Routine routine19 = RoomFixture.routine(room10, "방10의 루틴1"); + Routine routine20 = RoomFixture.routine(room10, "방10의 루틴2"); + + Routine routine21 = RoomFixture.routine(room11, "방11의 루틴1"); + Routine routine22 = RoomFixture.routine(room11, "방11의 루틴2"); + + Routine routine23 = RoomFixture.routine(room12, "방12의 루틴1"); + Routine routine24 = RoomFixture.routine(room12, "방12의 루틴2"); + + Routine routine25 = RoomFixture.routine(room13, "방13의 루틴1"); + Routine routine26 = RoomFixture.routine(room13, "방13의 루틴2"); + + Routine routine27 = RoomFixture.routine(room14, "방14의 루틴1"); + Routine routine28 = RoomFixture.routine(room14, "방14의 루틴2"); + + roomRepository.saveAll( + List.of(room1, room2, room3, room4, room5, room6, room7, room8, room9, room10, room11, room12, room13, + room14)); + + routineRepository.saveAll( + List.of(routine1, routine2, routine3, routine4, routine5, routine6, routine7, routine8, routine9, routine10, + routine11, routine12, routine13, routine14, routine15, routine16, routine17, routine18, routine19, + routine20, routine21, routine22, routine23, routine24, routine25, routine26, routine27, routine28)); + + // expected + mockMvc.perform(get("/rooms")) + .andExpect(status().isOk()) + .andDo(print()); + } + + @DisplayName("아침, 저녁 방 전체 조회 성공 - 마지막 조회, 다음 페이지 없음") + @WithMember(id = 1L) + @Test + void search_last_page_all_morning_night_rooms_success() throws Exception { + // given + Room room1 = RoomFixture.room("아침 - 첫 번째 방", RoomType.MORNING, 10, "1234"); + Room room2 = RoomFixture.room("아침 - 두 번째 방", RoomType.MORNING, 9); + Room room3 = RoomFixture.room("밤 - 세 번째 방", RoomType.NIGHT, 22); + Room room4 = RoomFixture.room("아침 - 네 번째 방", RoomType.MORNING, 7); + Room room5 = RoomFixture.room("밤 - 다섯 번째 방", RoomType.NIGHT, 23, "5869"); + Room room6 = RoomFixture.room("아침 - 여섯 번째 방", RoomType.MORNING, 8); + Room room7 = RoomFixture.room("밤 - 일곱 번째 방", RoomType.NIGHT, 20); + Room room8 = RoomFixture.room("밤 - 여덟 번째 방", RoomType.NIGHT, 1, "5236"); + Room room9 = RoomFixture.room("아침 - 아홉 번째 방", RoomType.MORNING, 4); + Room room10 = RoomFixture.room("밤 - 열 번째 방", RoomType.NIGHT, 1, "97979"); + Room room11 = RoomFixture.room("밤 - 열하나 번째 방", RoomType.NIGHT, 22); + Room room12 = RoomFixture.room("아침 - 열둘 번째 방", RoomType.MORNING, 10); + Room room13 = RoomFixture.room("밤 - 열셋 번째 방", RoomType.NIGHT, 2); + Room room14 = RoomFixture.room("밤 - 열넷 번째 방", RoomType.NIGHT, 21); + + Routine routine1 = RoomFixture.routine(room1, "방1의 루틴1"); + Routine routine2 = RoomFixture.routine(room1, "방1의 루틴2"); + + Routine routine3 = RoomFixture.routine(room2, "방2의 루틴1"); + Routine routine4 = RoomFixture.routine(room2, "방2의 루틴2"); + + Routine routine5 = RoomFixture.routine(room3, "방3의 루틴1"); + Routine routine6 = RoomFixture.routine(room3, "방3의 루틴2"); + + Routine routine7 = RoomFixture.routine(room4, "방4의 루틴1"); + Routine routine8 = RoomFixture.routine(room4, "방4의 루틴2"); + + Routine routine9 = RoomFixture.routine(room5, "방5의 루틴1"); + Routine routine10 = RoomFixture.routine(room5, "방5의 루틴2"); + + Routine routine11 = RoomFixture.routine(room6, "방6의 루틴1"); + Routine routine12 = RoomFixture.routine(room6, "방6의 루틴2"); + + Routine routine13 = RoomFixture.routine(room7, "방7의 루틴1"); + Routine routine14 = RoomFixture.routine(room7, "방7의 루틴2"); + + Routine routine15 = RoomFixture.routine(room8, "방8의 루틴1"); + Routine routine16 = RoomFixture.routine(room8, "방8의 루틴2"); + + Routine routine17 = RoomFixture.routine(room9, "방9의 루틴1"); + Routine routine18 = RoomFixture.routine(room9, "방9의 루틴2"); + + Routine routine19 = RoomFixture.routine(room10, "방10의 루틴1"); + Routine routine20 = RoomFixture.routine(room10, "방10의 루틴2"); + + Routine routine21 = RoomFixture.routine(room11, "방11의 루틴1"); + Routine routine22 = RoomFixture.routine(room11, "방11의 루틴2"); + + Routine routine23 = RoomFixture.routine(room12, "방12의 루틴1"); + Routine routine24 = RoomFixture.routine(room12, "방12의 루틴2"); + + Routine routine25 = RoomFixture.routine(room13, "방13의 루틴1"); + Routine routine26 = RoomFixture.routine(room13, "방13의 루틴2"); + + Routine routine27 = RoomFixture.routine(room14, "방14의 루틴1"); + Routine routine28 = RoomFixture.routine(room14, "방14의 루틴2"); + + roomRepository.saveAll( + List.of(room1, room2, room3, room4, room5, room6, room7, room8, room9, room10, room11, room12, room13, + room14)); + + routineRepository.saveAll( + List.of(routine1, routine2, routine3, routine4, routine5, routine6, routine7, routine8, routine9, routine10, + routine11, routine12, routine13, routine14, routine15, routine16, routine17, routine18, routine19, + routine20, routine21, routine22, routine23, routine24, routine25, routine26, routine27, routine28)); + + // expected + mockMvc.perform(get("/rooms?roomId=5")) + .andExpect(status().isOk()) + .andDo(print()); + } + + @DisplayName("아침 방 전체 조회 성공 - 첫 번째 조회, 다음 페이지 없음") + @WithMember(id = 1L) + @Test + void search_last_page_all_morning_rooms_success() throws Exception { + // given + Room room1 = RoomFixture.room("아침 - 첫 번째 방", RoomType.MORNING, 10, "1234"); + Room room2 = RoomFixture.room("아침 - 두 번째 방", RoomType.MORNING, 9); + Room room3 = RoomFixture.room("밤 - 세 번째 방", RoomType.NIGHT, 22); + Room room4 = RoomFixture.room("아침 - 네 번째 방", RoomType.MORNING, 7); + Room room5 = RoomFixture.room("밤 - 다섯 번째 방", RoomType.NIGHT, 23, "5869"); + Room room6 = RoomFixture.room("아침 - 여섯 번째 방", RoomType.MORNING, 8); + Room room7 = RoomFixture.room("밤 - 일곱 번째 방", RoomType.NIGHT, 20); + Room room8 = RoomFixture.room("밤 - 여덟 번째 방", RoomType.NIGHT, 1, "5236"); + Room room9 = RoomFixture.room("아침 - 아홉 번째 방", RoomType.MORNING, 4); + Room room10 = RoomFixture.room("밤 - 열 번째 방", RoomType.NIGHT, 1, "97979"); + Room room11 = RoomFixture.room("밤 - 열하나 번째 방", RoomType.NIGHT, 22); + Room room12 = RoomFixture.room("아침 - 열둘 번째 방", RoomType.MORNING, 10); + Room room13 = RoomFixture.room("밤 - 열셋 번째 방", RoomType.NIGHT, 2); + Room room14 = RoomFixture.room("밤 - 열넷 번째 방", RoomType.NIGHT, 21); + + Routine routine1 = RoomFixture.routine(room1, "방1의 루틴1"); + Routine routine2 = RoomFixture.routine(room1, "방1의 루틴2"); + + Routine routine3 = RoomFixture.routine(room2, "방2의 루틴1"); + Routine routine4 = RoomFixture.routine(room2, "방2의 루틴2"); + + Routine routine5 = RoomFixture.routine(room3, "방3의 루틴1"); + Routine routine6 = RoomFixture.routine(room3, "방3의 루틴2"); + + Routine routine7 = RoomFixture.routine(room4, "방4의 루틴1"); + Routine routine8 = RoomFixture.routine(room4, "방4의 루틴2"); + + Routine routine9 = RoomFixture.routine(room5, "방5의 루틴1"); + Routine routine10 = RoomFixture.routine(room5, "방5의 루틴2"); + + Routine routine11 = RoomFixture.routine(room6, "방6의 루틴1"); + Routine routine12 = RoomFixture.routine(room6, "방6의 루틴2"); + + Routine routine13 = RoomFixture.routine(room7, "방7의 루틴1"); + Routine routine14 = RoomFixture.routine(room7, "방7의 루틴2"); + + Routine routine15 = RoomFixture.routine(room8, "방8의 루틴1"); + Routine routine16 = RoomFixture.routine(room8, "방8의 루틴2"); + + Routine routine17 = RoomFixture.routine(room9, "방9의 루틴1"); + Routine routine18 = RoomFixture.routine(room9, "방9의 루틴2"); + + Routine routine19 = RoomFixture.routine(room10, "방10의 루틴1"); + Routine routine20 = RoomFixture.routine(room10, "방10의 루틴2"); + + Routine routine21 = RoomFixture.routine(room11, "방11의 루틴1"); + Routine routine22 = RoomFixture.routine(room11, "방11의 루틴2"); + + Routine routine23 = RoomFixture.routine(room12, "방12의 루틴1"); + Routine routine24 = RoomFixture.routine(room12, "방12의 루틴2"); + + Routine routine25 = RoomFixture.routine(room13, "방13의 루틴1"); + Routine routine26 = RoomFixture.routine(room13, "방13의 루틴2"); + + Routine routine27 = RoomFixture.routine(room14, "방14의 루틴1"); + Routine routine28 = RoomFixture.routine(room14, "방14의 루틴2"); + + roomRepository.saveAll( + List.of(room1, room2, room3, room4, room5, room6, room7, room8, room9, room10, room11, room12, room13, + room14)); + + routineRepository.saveAll( + List.of(routine1, routine2, routine3, routine4, routine5, routine6, routine7, routine8, routine9, routine10, + routine11, routine12, routine13, routine14, routine15, routine16, routine17, routine18, routine19, + routine20, routine21, routine22, routine23, routine24, routine25, routine26, routine27, routine28)); + + // expected + mockMvc.perform(get("/rooms?type=MORNING")) + .andExpect(status().isOk()) + .andDo(print()); + } + + @DisplayName("저녁 방 전체 조회 성공 - 첫 번째 조회, 다음 페이지 없음") + @WithMember(id = 1L) + @Test + void search_last_page_all_night_rooms_success() throws Exception { + // given + Room room1 = RoomFixture.room("아침 - 첫 번째 방", RoomType.MORNING, 10, "1234"); + Room room2 = RoomFixture.room("아침 - 두 번째 방", RoomType.MORNING, 9); + Room room3 = RoomFixture.room("밤 - 세 번째 방", RoomType.NIGHT, 22); + Room room4 = RoomFixture.room("아침 - 네 번째 방", RoomType.MORNING, 7); + Room room5 = RoomFixture.room("밤 - 다섯 번째 방", RoomType.NIGHT, 23, "5869"); + Room room6 = RoomFixture.room("아침 - 여섯 번째 방", RoomType.MORNING, 8); + Room room7 = RoomFixture.room("밤 - 일곱 번째 방", RoomType.NIGHT, 20); + Room room8 = RoomFixture.room("밤 - 여덟 번째 방", RoomType.NIGHT, 1, "5236"); + Room room9 = RoomFixture.room("아침 - 아홉 번째 방", RoomType.MORNING, 4); + Room room10 = RoomFixture.room("밤 - 열 번째 방", RoomType.NIGHT, 1, "97979"); + Room room11 = RoomFixture.room("밤 - 열하나 번째 방", RoomType.NIGHT, 22); + Room room12 = RoomFixture.room("아침 - 열둘 번째 방", RoomType.MORNING, 10); + Room room13 = RoomFixture.room("밤 - 열셋 번째 방", RoomType.NIGHT, 2); + Room room14 = RoomFixture.room("밤 - 열넷 번째 방", RoomType.NIGHT, 21); + + Routine routine1 = RoomFixture.routine(room1, "방1의 루틴1"); + Routine routine2 = RoomFixture.routine(room1, "방1의 루틴2"); + + Routine routine3 = RoomFixture.routine(room2, "방2의 루틴1"); + Routine routine4 = RoomFixture.routine(room2, "방2의 루틴2"); + + Routine routine5 = RoomFixture.routine(room3, "방3의 루틴1"); + Routine routine6 = RoomFixture.routine(room3, "방3의 루틴2"); + + Routine routine7 = RoomFixture.routine(room4, "방4의 루틴1"); + Routine routine8 = RoomFixture.routine(room4, "방4의 루틴2"); + + Routine routine9 = RoomFixture.routine(room5, "방5의 루틴1"); + Routine routine10 = RoomFixture.routine(room5, "방5의 루틴2"); + + Routine routine11 = RoomFixture.routine(room6, "방6의 루틴1"); + Routine routine12 = RoomFixture.routine(room6, "방6의 루틴2"); + + Routine routine13 = RoomFixture.routine(room7, "방7의 루틴1"); + Routine routine14 = RoomFixture.routine(room7, "방7의 루틴2"); + + Routine routine15 = RoomFixture.routine(room8, "방8의 루틴1"); + Routine routine16 = RoomFixture.routine(room8, "방8의 루틴2"); + + Routine routine17 = RoomFixture.routine(room9, "방9의 루틴1"); + Routine routine18 = RoomFixture.routine(room9, "방9의 루틴2"); + + Routine routine19 = RoomFixture.routine(room10, "방10의 루틴1"); + Routine routine20 = RoomFixture.routine(room10, "방10의 루틴2"); + + Routine routine21 = RoomFixture.routine(room11, "방11의 루틴1"); + Routine routine22 = RoomFixture.routine(room11, "방11의 루틴2"); + + Routine routine23 = RoomFixture.routine(room12, "방12의 루틴1"); + Routine routine24 = RoomFixture.routine(room12, "방12의 루틴2"); + + Routine routine25 = RoomFixture.routine(room13, "방13의 루틴1"); + Routine routine26 = RoomFixture.routine(room13, "방13의 루틴2"); + + Routine routine27 = RoomFixture.routine(room14, "방14의 루틴1"); + Routine routine28 = RoomFixture.routine(room14, "방14의 루틴2"); + + roomRepository.saveAll( + List.of(room1, room2, room3, room4, room5, room6, room7, room8, room9, room10, room11, room12, room13, + room14)); + + routineRepository.saveAll( + List.of(routine1, routine2, routine3, routine4, routine5, routine6, routine7, routine8, routine9, routine10, + routine11, routine12, routine13, routine14, routine15, routine16, routine17, routine18, routine19, + routine20, routine21, routine22, routine23, routine24, routine25, routine26, routine27, routine28)); + + // expected + mockMvc.perform(get("/rooms?type=NIGHT")) + .andExpect(status().isOk()) + .andDo(print()); + } } From ed08bcafaea62415cdc7b927f128eaa8425dbb71 Mon Sep 17 00:00:00 2001 From: ymkim97 Date: Sat, 18 Nov 2023 13:37:22 +0900 Subject: [PATCH 8/8] =?UTF-8?q?fix:=20=ED=94=BC=EC=97=B0=EC=82=B0=EC=9E=90?= =?UTF-8?q?=20Long=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../moabam/api/domain/room/repository/RoomSearchRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/moabam/api/domain/room/repository/RoomSearchRepository.java b/src/main/java/com/moabam/api/domain/room/repository/RoomSearchRepository.java index 3fc64784..9313115d 100644 --- a/src/main/java/com/moabam/api/domain/room/repository/RoomSearchRepository.java +++ b/src/main/java/com/moabam/api/domain/room/repository/RoomSearchRepository.java @@ -27,7 +27,7 @@ public List findAllWithNoOffset(RoomType roomType, Long roomId) { DynamicQuery.generateEq(roomId, room.id::lt) ) .orderBy(room.id.desc()) - .limit(ROOM_FIXED_SEARCH_SIZE + 1) + .limit(ROOM_FIXED_SEARCH_SIZE + 1L) .fetch(); } }