From d508f19873cd6d0070dda071dd77a2d300bd53eb Mon Sep 17 00:00:00 2001 From: Hyoseop Song Date: Mon, 30 Sep 2024 17:12:31 +0900 Subject: [PATCH] =?UTF-8?q?:bug:=20fix:=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EB=8A=94=20=ED=98=84=EC=9E=AC=20=EC=BB=A4?= =?UTF-8?q?=EC=84=9C=20=EC=9D=B4=ED=9B=84=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EB=B6=80=ED=84=B0=20=EC=A1=B0=ED=9A=8C=20(#92)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/RollingPaperService.java | 5 ++++- .../persistance/RollingPaperRepository.java | 2 +- .../presentation/RollingPaperController.java | 2 +- .../application/RollingPaperServiceTest.java | 16 +++++----------- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/java/slvtwn/khu/toyouserver/application/RollingPaperService.java b/src/main/java/slvtwn/khu/toyouserver/application/RollingPaperService.java index ab2be80..36e80c4 100644 --- a/src/main/java/slvtwn/khu/toyouserver/application/RollingPaperService.java +++ b/src/main/java/slvtwn/khu/toyouserver/application/RollingPaperService.java @@ -1,5 +1,7 @@ package slvtwn.khu.toyouserver.application; +import static java.lang.Long.MIN_VALUE; + import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; @@ -65,9 +67,10 @@ public RollingPaperResponse findById(Long userId, Long rollingPaperId) { public List findReceivedRollingPapers(Long userId, Long groupId, Long targetId, Integer limit) { + Long currentCursor = targetId != null ? targetId : MIN_VALUE; List memberIds = getMemberIds(userId, groupId); PageRequest pageRequest = PageRequest.ofSize(limit); - return rollingPaperRepository.findAllByMembersAfterCursor(memberIds, targetId, pageRequest).stream() + return rollingPaperRepository.findAllByMembersAfterCursor(memberIds, currentCursor, pageRequest).stream() .map(RollingPaperResponse::from) .toList(); } diff --git a/src/main/java/slvtwn/khu/toyouserver/persistance/RollingPaperRepository.java b/src/main/java/slvtwn/khu/toyouserver/persistance/RollingPaperRepository.java index 84236ea..c08a4dc 100644 --- a/src/main/java/slvtwn/khu/toyouserver/persistance/RollingPaperRepository.java +++ b/src/main/java/slvtwn/khu/toyouserver/persistance/RollingPaperRepository.java @@ -9,7 +9,7 @@ public interface RollingPaperRepository extends JpaRepository { - @Query("SELECT r FROM RollingPaper r WHERE r.member.id IN :memberIds AND r.id < :targetId ORDER BY r.id DESC") + @Query("SELECT r FROM RollingPaper r WHERE r.member.id IN :memberIds AND r.id >= :targetId ORDER BY r.id DESC") List findAllByMembersAfterCursor(@Param("memberIds") List memberIds, @Param("targetId") Long targetId, Pageable pageable); diff --git a/src/main/java/slvtwn/khu/toyouserver/presentation/RollingPaperController.java b/src/main/java/slvtwn/khu/toyouserver/presentation/RollingPaperController.java index e3f7a02..c51f2c4 100644 --- a/src/main/java/slvtwn/khu/toyouserver/presentation/RollingPaperController.java +++ b/src/main/java/slvtwn/khu/toyouserver/presentation/RollingPaperController.java @@ -30,7 +30,7 @@ public ToyouResponse findById(@UserAuthentication Long use @GetMapping("/rollingpapers") public ToyouResponse> findReceivedRollingPapers(@UserAuthentication Long userId, @RequestParam Long groupId, - @RequestParam Long targetId, + @RequestParam(defaultValue = "0") Long targetId, @RequestParam(defaultValue = "10") int limit) { return ToyouResponse.from(rollingPaperService.findReceivedRollingPapers(userId, groupId, targetId, limit)); } diff --git a/src/test/java/slvtwn/khu/toyouserver/application/RollingPaperServiceTest.java b/src/test/java/slvtwn/khu/toyouserver/application/RollingPaperServiceTest.java index 74b6ce0..995f4ea 100644 --- a/src/test/java/slvtwn/khu/toyouserver/application/RollingPaperServiceTest.java +++ b/src/test/java/slvtwn/khu/toyouserver/application/RollingPaperServiceTest.java @@ -2,8 +2,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; @@ -14,13 +12,11 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.transaction.annotation.Transactional; import slvtwn.khu.toyouserver.domain.Group; import slvtwn.khu.toyouserver.domain.Member; import slvtwn.khu.toyouserver.domain.RollingPaper; import slvtwn.khu.toyouserver.domain.User; -import slvtwn.khu.toyouserver.dto.CoverRequest; import slvtwn.khu.toyouserver.dto.RollingPaperRequest; import slvtwn.khu.toyouserver.dto.RollingPaperResponse; @@ -125,7 +121,7 @@ class RollingPaperServiceTest { // when List response = rollingPaperService.findReceivedRollingPapers(user.getId(), group.getId(), - rollingPaper.getId() + 1, 10); + null, 10); // then assertThat(response).usingRecursiveComparison() @@ -155,7 +151,7 @@ class RollingPaperServiceTest { List responseWithoutGroupId = rollingPaperService.findReceivedRollingPapers( user.getId(), null, - anotherRollingPaper.getId() + 1, 10); + 0L, 10); // then assertThat(responseWithoutGroupId).usingRecursiveComparison() @@ -188,7 +184,7 @@ class RollingPaperServiceTest { List responseWithGroupId = rollingPaperService.findReceivedRollingPapers( user.getId(), group1.getId(), - rollingPaper.getId() + 1, 10); + 0L, 10); // then assertThat(responseWithGroupId).usingRecursiveComparison() @@ -217,13 +213,11 @@ class RollingPaperServiceTest { entityManager.persist(rollingPaper2); entityManager.persist(rollingPaper3); - long totalRollingPapersCount = rollingPaper3.getId() + 1; - // when List response = rollingPaperService.findReceivedRollingPapers( user.getId(), group1.getId(), - totalRollingPapersCount, 10); + 0L, 10); // then List expectedResponse = List.of( @@ -257,7 +251,7 @@ class RollingPaperServiceTest { List response = rollingPaperService.findReceivedRollingPapers( user.getId(), group.getId(), - rollingPaper3.getId() + 1, 10); + null, 10); // then List expectedResponse = List.of(