From c0038d472ce835cef4ecbc7cf7488edb501dea5d Mon Sep 17 00:00:00 2001 From: hong seokho Date: Tue, 4 Jun 2024 22:54:13 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20SliceUtil?= =?UTF-8?q?=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../friend/api/query/FriendQueryApi.java | 2 +- .../api/query/FriendQueryApiController.java | 10 +++--- .../FriendInviteQueryRepository.java | 2 +- .../FriendInviteQueryRepositoryImpl.java | 16 +++------- .../service/query/FriendQueryService.java | 4 +-- .../core/global/util/SliceUtil.java | 22 +++++++++++++ .../FriendInviteQueryRepositoryTest.java | 32 +++++++++---------- 7 files changed, 51 insertions(+), 37 deletions(-) create mode 100644 backend/core/src/main/java/site/timecapsulearchive/core/global/util/SliceUtil.java diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/api/query/FriendQueryApi.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/api/query/FriendQueryApi.java index bf4fa86b9..14cd4c0d6 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/api/query/FriendQueryApi.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/api/query/FriendQueryApi.java @@ -79,7 +79,7 @@ ResponseEntity> findFriendsBeforeGroupInvite( description = "ok" ) }) - ResponseEntity> findFriendReceptionInvites( + ResponseEntity> findFriendReceivingInvites( Long memberId, @Parameter(in = ParameterIn.QUERY, description = "페이지 크기", required = true) diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/api/query/FriendQueryApiController.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/api/query/FriendQueryApiController.java index 46077f0c9..f963efba8 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/api/query/FriendQueryApiController.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/api/query/FriendQueryApiController.java @@ -76,23 +76,23 @@ public ResponseEntity> findFriendsBeforeGroupInvit } @GetMapping( - value = "/reception-invites", + value = "/receiving-invites", produces = {"application/json"} ) @Override - public ResponseEntity> findFriendReceptionInvites( + public ResponseEntity> findFriendReceivingInvites( @AuthenticationPrincipal final Long memberId, @RequestParam(defaultValue = "20", value = "size") final int size, @RequestParam(value = "created_at") final ZonedDateTime createdAt ) { - final Slice friendReceptionInvitesSlice = friendQueryService.findFriendReceptionInvitesSlice( + final Slice friendReceivingInvitesSlice = friendQueryService.findFriendReceivingInvitesSlice( memberId, size, createdAt); return ResponseEntity.ok( ApiSpec.success( SuccessCode.SUCCESS, - FriendsSliceResponse.createOf(friendReceptionInvitesSlice.getContent(), - friendReceptionInvitesSlice.hasNext()) + FriendsSliceResponse.createOf(friendReceivingInvitesSlice.getContent(), + friendReceivingInvitesSlice.hasNext()) ) ); } diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/repository/friend_invite/FriendInviteQueryRepository.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/repository/friend_invite/FriendInviteQueryRepository.java index 2b4830a7d..40ba418cc 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/repository/friend_invite/FriendInviteQueryRepository.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/repository/friend_invite/FriendInviteQueryRepository.java @@ -10,7 +10,7 @@ public interface FriendInviteQueryRepository { void bulkSave(final Long ownerId, final List friendIds); - Slice findFriendReceptionInvitesSlice( + Slice findFriendReceivingInvitesSlice( final Long memberId, final int size, final ZonedDateTime createdAt diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/repository/friend_invite/FriendInviteQueryRepositoryImpl.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/repository/friend_invite/FriendInviteQueryRepositoryImpl.java index 2bd2f9261..ae6aeceef 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/repository/friend_invite/FriendInviteQueryRepositoryImpl.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/repository/friend_invite/FriendInviteQueryRepositoryImpl.java @@ -19,6 +19,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; import site.timecapsulearchive.core.domain.friend.data.dto.FriendSummaryDto; +import site.timecapsulearchive.core.global.util.SliceUtil; @Repository @RequiredArgsConstructor @@ -58,7 +59,7 @@ public int getBatchSize() { ); } - public Slice findFriendReceptionInvitesSlice( + public Slice findFriendReceivingInvitesSlice( final Long memberId, final int size, final ZonedDateTime createdAt @@ -79,16 +80,7 @@ public Slice findFriendReceptionInvitesSlice( .limit(size + 1) .fetch(); - return makeSlice(size, friends); - } - - private Slice makeSlice(int size, List dtos) { - final boolean hasNext = dtos.size() > size; - if (hasNext) { - dtos.remove(size); - } - - return new SliceImpl<>(dtos, Pageable.ofSize(size), hasNext); + return SliceUtil.makeSlice(size, friends); } @Override @@ -113,6 +105,6 @@ public Slice findFriendSendingInvitesSlice( .limit(size + 1) .fetch(); - return makeSlice(size, friends); + return SliceUtil.makeSlice(size, friends); } } diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/service/query/FriendQueryService.java b/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/service/query/FriendQueryService.java index 956213f12..2e0ecc5e8 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/service/query/FriendQueryService.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/domain/friend/service/query/FriendQueryService.java @@ -36,12 +36,12 @@ public Slice findFriendsBeforeGroupInviteSlice( return memberFriendRepository.findFriendsBeforeGroupInvite(request); } - public Slice findFriendReceptionInvitesSlice( + public Slice findFriendReceivingInvitesSlice( final Long memberId, final int size, final ZonedDateTime createdAt ) { - return friendInviteRepository.findFriendReceptionInvitesSlice(memberId, size, createdAt); + return friendInviteRepository.findFriendReceivingInvitesSlice(memberId, size, createdAt); } public Slice findFriendSendingInvitesSlice( diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/global/util/SliceUtil.java b/backend/core/src/main/java/site/timecapsulearchive/core/global/util/SliceUtil.java new file mode 100644 index 000000000..be393648a --- /dev/null +++ b/backend/core/src/main/java/site/timecapsulearchive/core/global/util/SliceUtil.java @@ -0,0 +1,22 @@ +package site.timecapsulearchive.core.global.util; + +import java.util.List; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.domain.SliceImpl; + +public final class SliceUtil { + + private SliceUtil() { + + } + + public static Slice makeSlice(final int size, final List dtos) { + final boolean hasNext = dtos.size() > size; + if (hasNext) { + dtos.remove(size); + } + + return new SliceImpl<>(dtos, Pageable.ofSize(size), hasNext); + } +} diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/friend/repository/FriendInviteQueryRepositoryTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/friend/repository/FriendInviteQueryRepositoryTest.java index bba643e30..8233b0761 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/friend/repository/FriendInviteQueryRepositoryTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/friend/repository/FriendInviteQueryRepositoryTest.java @@ -31,10 +31,10 @@ class FriendInviteQueryRepositoryTest extends RepositoryTest { private static final int MAX_COUNT = 40; private static final Long BULK_FRIEND_INVITE_MEMBER_START_ID = 2L; - private static final Long FRIEND_RECEPTION_INVITE_MEMBER_START_ID = + private static final Long FRIEND_RECEIVING_INVITE_MEMBER_START_ID = BULK_FRIEND_INVITE_MEMBER_START_ID + MAX_COUNT; private static final Long FRIEND_SENDING_INVITE_MEMBER_START_ID = - FRIEND_RECEPTION_INVITE_MEMBER_START_ID + MAX_COUNT; + FRIEND_RECEIVING_INVITE_MEMBER_START_ID + MAX_COUNT; private static final Long NOT_FRIEND_INVITE_START_ID = FRIEND_SENDING_INVITE_MEMBER_START_ID + MAX_COUNT; @@ -44,7 +44,7 @@ class FriendInviteQueryRepositoryTest extends RepositoryTest { private Long bulkOwnerId; private Long ownerId; - private Long ownerInviteReceptionStartId; + private Long ownerInviteReceivingStartId; private Long ownerInviteSendingStartId; FriendInviteQueryRepositoryTest(EntityManager entityManager, JdbcTemplate jdbcTemplate, @@ -71,15 +71,15 @@ void setup() { ownerId = owner.getId(); // owner에게 친구 요청만 받은 멤버 데이터 - List receptionInviteToOwnerMembers = MemberFixture.members( - FRIEND_RECEPTION_INVITE_MEMBER_START_ID.intValue(), MAX_COUNT); - for (Member member : receptionInviteToOwnerMembers) { + List receivingInviteToOwnerMembers = MemberFixture.members( + FRIEND_RECEIVING_INVITE_MEMBER_START_ID.intValue(), MAX_COUNT); + for (Member member : receivingInviteToOwnerMembers) { entityManager.persist(member); - FriendInvite receptionInvite = FriendInviteFixture.friendInvite(owner, member); - entityManager.persist(receptionInvite); + FriendInvite receivingInvite = FriendInviteFixture.friendInvite(owner, member); + entityManager.persist(receivingInvite); } - ownerInviteReceptionStartId = receptionInviteToOwnerMembers.get(0).getId(); + ownerInviteReceivingStartId = receivingInviteToOwnerMembers.get(0).getId(); // owner에게 친구 요청만 보낸 멤버 데이터 List sendingInviteToOwnerMembers = MemberFixture.members( @@ -131,8 +131,8 @@ private List getFriendInvites(EntityManager entityManager, Long ow ); assertThat(slice.getContent()).isNotEmpty(); - assertThat(slice.getContent()).allMatch(dto -> dto.id() >= ownerInviteReceptionStartId - && dto.id() < ownerInviteReceptionStartId + MAX_COUNT); + assertThat(slice.getContent()).allMatch(dto -> dto.id() >= ownerInviteReceivingStartId + && dto.id() < ownerInviteReceivingStartId + MAX_COUNT); } @Test @@ -191,7 +191,7 @@ private List getFriendInvites(EntityManager entityManager, Long ow void 사용자가_받은_친구_요청_받은_목록을_조회하면_받은_친구_요청목록이_나온다(int size) { ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC")).plusDays(3); - Slice slice = friendInviteQueryRepository.findFriendReceptionInvitesSlice( + Slice slice = friendInviteQueryRepository.findFriendReceivingInvitesSlice( ownerId, size, now @@ -207,12 +207,12 @@ private List getFriendInvites(EntityManager entityManager, Long ow //given int size = 20; ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC")).plusDays(3); - Slice firstSlice = friendInviteQueryRepository.findFriendReceptionInvitesSlice( + Slice firstSlice = friendInviteQueryRepository.findFriendReceivingInvitesSlice( ownerId, size, now); //when FriendSummaryDto dto = firstSlice.getContent().get(firstSlice.getNumberOfElements() - 1); - Slice nextSlice = friendInviteQueryRepository.findFriendReceptionInvitesSlice( + Slice nextSlice = friendInviteQueryRepository.findFriendReceivingInvitesSlice( ownerId, size, dto.createdAt().plusSeconds(1L)); //then @@ -226,7 +226,7 @@ private List getFriendInvites(EntityManager entityManager, Long ow ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC")).minusDays(5); //when - Slice slice = friendInviteQueryRepository.findFriendReceptionInvitesSlice( + Slice slice = friendInviteQueryRepository.findFriendReceivingInvitesSlice( ownerId, size, now @@ -243,7 +243,7 @@ private List getFriendInvites(EntityManager entityManager, Long ow ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC")).plusDays(5); //when - Slice slice = friendInviteQueryRepository.findFriendReceptionInvitesSlice( + Slice slice = friendInviteQueryRepository.findFriendReceivingInvitesSlice( NOT_FRIEND_INVITE_START_ID, size, now