From 9ec6a21ef46e07d982d7eeae8bb49c07c9d77ae5 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Fri, 26 Jul 2024 11:51:33 +0900 Subject: [PATCH 1/8] =?UTF-8?q?Refactor=20:=20=EC=9C=A0=EC=A0=80=EA=B0=80?= =?UTF-8?q?=20=EC=9A=94=EC=B2=AD=ED=95=9C=20=EC=A0=95=EC=82=B0,=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=EB=B0=9B=EC=9D=80=20=EC=A0=95=EC=82=B0=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=96=BB=EB=8A=94=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=EC=97=90=20=ED=95=B4=EB=8B=B9=20=EC=A0=95=EC=82=B0=EC=9D=98=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C=EC=97=AC=EB=B6=80=EB=8F=84=20=ED=8C=8C?= =?UTF-8?q?=EB=9D=BC=EB=AF=B8=ED=84=B0=EB=A1=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PayController.java | 28 ++++++++++++++++--- .../java/space/space_spring/dao/PayDao.java | 12 ++++---- .../space_spring/service/PayService.java | 8 +++--- .../space_spring/service/PayServiceTest.java | 8 +++--- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/main/java/space/space_spring/controller/PayController.java b/src/main/java/space/space_spring/controller/PayController.java index cd54ce3c..ee97921e 100644 --- a/src/main/java/space/space_spring/controller/PayController.java +++ b/src/main/java/space/space_spring/controller/PayController.java @@ -26,16 +26,21 @@ public class PayController { private final PayService payService; private final UserSpaceUtils userSpaceUtils; + /** + * 정산 홈 view + */ @GetMapping("/space/{spaceId}/pay") public BaseResponse showPayListForUser(@JwtLoginAuth Long userId, @PathVariable Long spaceId) { // TODO 1. 유저가 스페이스에 속하는 지 검증 validateIsUserInSpace(userId, spaceId); - // TODO 2. 유저가 요청한 정산 리스트 get - List payRequestInfoDtoList = payService.getPayRequestInfoForUser(userId, spaceId); + // TODO 2. 유저가 요청한 정산 중 현재 진행중인 정산 리스트 get + // 현재 진행중인 정산 -> isComplete = false + List payRequestInfoDtoList = payService.getPayRequestInfoForUser(userId, spaceId, false); - // TODO 3. 유저가 요청받은 정산 리스트 get - List payReceiveInfoDtoList = payService.getPayReceiveInfoForUser(userId, spaceId); + // TODO 3. 유저가 요청받은 정산 중 현재 진행중인 정산 리스트 get + // 현재 진행중인 정산 -> isComplete = false + List payReceiveInfoDtoList = payService.getPayReceiveInfoForUser(userId, spaceId, false); return new BaseResponse<>(new GetPayViewResponse(payRequestInfoDtoList, payReceiveInfoDtoList)); } @@ -46,4 +51,19 @@ private void validateIsUserInSpace(Long userId, Long spaceId) { userSpaceUtils.isUserInSpace(userId, spaceId); } + /** + * 내가 요청한 정산 view + */ +// @GetMapping("/space/{spaceId}/pay/request") +// public BaseResponse showRequestPayListForUser(@JwtLoginAuth Long userId, @PathVariable Long spaceId) { +// // TODO 1. 유저가 스페이스에 속하는 지 검증 -> 추후에 인터셉터에서 처리하게끔 리펙토링 필요 +// validateIsUserInSpace(userId, spaceId); +// +// // TODO 2. 유저가 요청한 정산 중 현재 진행중인 정산 리스트 get +// +// +// // TODO 3. 유저가 요청한 정산 중 완료한 정산 리스트 get +// +// +// } } diff --git a/src/main/java/space/space_spring/dao/PayDao.java b/src/main/java/space/space_spring/dao/PayDao.java index 5b5b54d2..cf6d1e23 100644 --- a/src/main/java/space/space_spring/dao/PayDao.java +++ b/src/main/java/space/space_spring/dao/PayDao.java @@ -18,14 +18,14 @@ public class PayDao { @PersistenceContext private EntityManager em; - public List findPayRequestListByUser(User user, Space space) { + public List findPayRequestListByUser(User user, Space space, boolean isComplete) { // 유저가 해당 스페이스에서 요청한 정산 목록만을 select - // 아직 정산이 완료되지 않은 payRequest 엔티티만 select - String jpql = "SELECT pr FROM PayRequest pr WHERE pr.payCreateUser = :user AND pr.space = :space AND pr.isComplete = false"; + String jpql = "SELECT pr FROM PayRequest pr WHERE pr.payCreateUser = :user AND pr.space = :space AND pr.isComplete = :isComplete"; return em.createQuery(jpql, PayRequest.class) .setParameter("user", user) .setParameter("space", space) + .setParameter("isComplete", isComplete) .getResultList(); } @@ -39,16 +39,16 @@ public List findPayRequestTargetListByPayRequest(PayRequest pa .getResultList(); } - public List findPayRequestTargetListByUser(User user, Space space) { + public List findPayRequestTargetListByUser(User user, Space space, boolean isComplete) { // 유저가 해당 스페이스에서 요청받은 정산 목록만을 select - // 유저가 요청받은 정산 중 아직 완료되지 않은 payRequestTarget 엔티티만 select String jpql = "SELECT prt FROM PayRequestTarget prt " + "JOIN prt.payRequest pr " + - "WHERE prt.targetUserId = :userId AND pr.space = :space AND pr.isComplete = false"; + "WHERE prt.targetUserId = :userId AND pr.space = :space AND pr.isComplete = :isComplete"; return em.createQuery(jpql, PayRequestTarget.class) .setParameter("userId", user.getUserId()) .setParameter("space", space) + .setParameter("isComplete", isComplete) .getResultList(); } diff --git a/src/main/java/space/space_spring/service/PayService.java b/src/main/java/space/space_spring/service/PayService.java index 448969c7..174ae5b4 100644 --- a/src/main/java/space/space_spring/service/PayService.java +++ b/src/main/java/space/space_spring/service/PayService.java @@ -23,7 +23,7 @@ public class PayService { private final UserUtils userUtils; private final SpaceUtils spaceUtils; - public List getPayRequestInfoForUser(Long userId, Long spaceId) { + public List getPayRequestInfoForUser(Long userId, Long spaceId, boolean isComplete) { // TODO 1. userId에 해당하는 user find User userByUserId = userUtils.findUserByUserId(userId); @@ -31,7 +31,7 @@ public List getPayRequestInfoForUser(Long userId, Long spaceI Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); // TODO 3. 유저가 요청한 정산 중 진행 중인 정산 리스트 select - List payRequestListByUser = payDao.findPayRequestListByUser(userByUserId, spaceBySpaceId); + List payRequestListByUser = payDao.findPayRequestListByUser(userByUserId, spaceBySpaceId, isComplete); // TODO 4. return 타입 구성 // 3-1. 각 payRequest 에 해당하는 모든 payRequestTarget 을 loop로 돌면서 데이터 수집 @@ -62,7 +62,7 @@ public List getPayRequestInfoForUser(Long userId, Long spaceI return payRequestInfoDtoList; } - public List getPayReceiveInfoForUser(Long userId, Long spaceId) { + public List getPayReceiveInfoForUser(Long userId, Long spaceId, boolean isComplete) { // TODO 1. userId에 해당하는 유저 find User userByUserId = userUtils.findUserByUserId(userId); @@ -70,7 +70,7 @@ public List getPayReceiveInfoForUser(Long userId, Long spaceI Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); // TODO 3. 유저가 요청받은 정산 중 진행 중인 정산 리스트 select - List payRequestTargetListByUser = payDao.findPayRequestTargetListByUser(userByUserId, spaceBySpaceId); + List payRequestTargetListByUser = payDao.findPayRequestTargetListByUser(userByUserId, spaceBySpaceId, isComplete); // TODO 4. return 타입 구성 // 3-1. 각 payRequestTarget 에 해당하는 정산 요청자, 정산 요청 금액 을 loop를 돌면서 데이터 수집 diff --git a/src/test/java/space/space_spring/service/PayServiceTest.java b/src/test/java/space/space_spring/service/PayServiceTest.java index 0a8c9f3f..0b3d6054 100644 --- a/src/test/java/space/space_spring/service/PayServiceTest.java +++ b/src/test/java/space/space_spring/service/PayServiceTest.java @@ -72,11 +72,11 @@ class PayServiceTest { //given when(userUtils.findUserByUserId(user2.getUserId())).thenReturn(user2); when(spaceUtils.findSpaceBySpaceId(testSpace.getSpaceId())).thenReturn(testSpace); - when(payDao.findPayRequestListByUser(user2, testSpace)).thenReturn(List.of(testPayRequest)); + when(payDao.findPayRequestListByUser(user2, testSpace, false)).thenReturn(List.of(testPayRequest)); when(payDao.findPayRequestTargetListByPayRequest(testPayRequest)).thenReturn(List.of(testPayRequestTarget)); //when - List payRequestInfoForUser = payService.getPayRequestInfoForUser(user2.getUserId(), testSpace.getSpaceId()); + List payRequestInfoForUser = payService.getPayRequestInfoForUser(user2.getUserId(), testSpace.getSpaceId(), false); //then assertThat(payRequestInfoForUser.size()).isEqualTo(1); @@ -95,10 +95,10 @@ class PayServiceTest { //given when(userUtils.findUserByUserId(user1.getUserId())).thenReturn(user1); when(spaceUtils.findSpaceBySpaceId(testSpace.getSpaceId())).thenReturn(testSpace); - when(payDao.findPayRequestTargetListByUser(user1, testSpace)).thenReturn(List.of(testPayRequestTarget)); + when(payDao.findPayRequestTargetListByUser(user1, testSpace, false)).thenReturn(List.of(testPayRequestTarget)); //when - List payReceiveInfoForUser = payService.getPayReceiveInfoForUser(user1.getUserId(), testSpace.getSpaceId()); + List payReceiveInfoForUser = payService.getPayReceiveInfoForUser(user1.getUserId(), testSpace.getSpaceId(), false); //then assertThat(payReceiveInfoForUser.size()).isEqualTo(1); From 8283a989c6268119f8b1748c18d5e6f3c39cb576 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Fri, 26 Jul 2024 11:57:53 +0900 Subject: [PATCH 2/8] =?UTF-8?q?Feat=20:=20=EB=82=B4=EA=B0=80=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=ED=95=9C=20=EC=A0=95=EC=82=B0=20view=20api=20controll?= =?UTF-8?q?er=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PayController.java | 26 ++++++++++--------- .../dto/pay/GetRequestPayViewResponse.java | 16 ++++++++++++ 2 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 src/main/java/space/space_spring/dto/pay/GetRequestPayViewResponse.java diff --git a/src/main/java/space/space_spring/controller/PayController.java b/src/main/java/space/space_spring/controller/PayController.java index ee97921e..4525e017 100644 --- a/src/main/java/space/space_spring/controller/PayController.java +++ b/src/main/java/space/space_spring/controller/PayController.java @@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RestController; import space.space_spring.argument_resolver.jwtLogin.JwtLoginAuth; import space.space_spring.dto.pay.GetPayViewResponse; +import space.space_spring.dto.pay.GetRequestPayViewResponse; import space.space_spring.dto.pay.PayReceiveInfoDto; import space.space_spring.dto.pay.PayRequestInfoDto; import space.space_spring.entity.UserSpace; @@ -54,16 +55,17 @@ private void validateIsUserInSpace(Long userId, Long spaceId) { /** * 내가 요청한 정산 view */ -// @GetMapping("/space/{spaceId}/pay/request") -// public BaseResponse showRequestPayListForUser(@JwtLoginAuth Long userId, @PathVariable Long spaceId) { -// // TODO 1. 유저가 스페이스에 속하는 지 검증 -> 추후에 인터셉터에서 처리하게끔 리펙토링 필요 -// validateIsUserInSpace(userId, spaceId); -// -// // TODO 2. 유저가 요청한 정산 중 현재 진행중인 정산 리스트 get -// -// -// // TODO 3. 유저가 요청한 정산 중 완료한 정산 리스트 get -// -// -// } + @GetMapping("/space/{spaceId}/pay/request") + public BaseResponse showRequestPayListForUser(@JwtLoginAuth Long userId, @PathVariable Long spaceId) { + // TODO 1. 유저가 스페이스에 속하는 지 검증 -> 추후에 인터셉터에서 처리하게끔 리펙토링 필요 + validateIsUserInSpace(userId, spaceId); + + // TODO 2. 유저가 요청한 정산 중 현재 진행중인 정산 리스트 get + List payRequestInfoDtoListInComplete = payService.getPayRequestInfoForUser(userId, spaceId, false); + + // TODO 3. 유저가 요청한 정산 중 완료한 정산 리스트 get + List payRequestInfoDtoListComplete = payService.getPayRequestInfoForUser(userId, spaceId, true); + + return new BaseResponse<>(new GetRequestPayViewResponse(payRequestInfoDtoListInComplete, payRequestInfoDtoListComplete)); + } } diff --git a/src/main/java/space/space_spring/dto/pay/GetRequestPayViewResponse.java b/src/main/java/space/space_spring/dto/pay/GetRequestPayViewResponse.java new file mode 100644 index 00000000..0ee5860a --- /dev/null +++ b/src/main/java/space/space_spring/dto/pay/GetRequestPayViewResponse.java @@ -0,0 +1,16 @@ +package space.space_spring.dto.pay; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@AllArgsConstructor +public class GetRequestPayViewResponse { + + private List payRequestInfoDtoListInComplete = new ArrayList<>(); + + private List payRequestInfoDtoListComplete = new ArrayList<>(); +} From ef6039735a8de733d17ac32c6232db26dfd3e293 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Fri, 26 Jul 2024 15:14:25 +0900 Subject: [PATCH 3/8] =?UTF-8?q?Test=20:=20=EA=B8=B0=EC=A1=B4=20PayServiceT?= =?UTF-8?q?est=20=EC=97=90=EC=84=9C=EC=9D=98=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=9A=A9=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=84=B8=ED=8C=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space_spring/service/PayService.java | 4 +- .../space_spring/service/PayServiceTest.java | 54 ++++++++++++------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/main/java/space/space_spring/service/PayService.java b/src/main/java/space/space_spring/service/PayService.java index 174ae5b4..b1d09587 100644 --- a/src/main/java/space/space_spring/service/PayService.java +++ b/src/main/java/space/space_spring/service/PayService.java @@ -30,7 +30,7 @@ public List getPayRequestInfoForUser(Long userId, Long spaceI // TODO 2. spaceId에 해당하는 space find Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); - // TODO 3. 유저가 요청한 정산 중 진행 중인 정산 리스트 select + // TODO 3. 유저가 요청한 정산 리스트 select List payRequestListByUser = payDao.findPayRequestListByUser(userByUserId, spaceBySpaceId, isComplete); // TODO 4. return 타입 구성 @@ -69,7 +69,7 @@ public List getPayReceiveInfoForUser(Long userId, Long spaceI // TODO 2. spaceId에 해당하는 space find Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId); - // TODO 3. 유저가 요청받은 정산 중 진행 중인 정산 리스트 select + // TODO 3. 유저가 요청받은 정산 리스트 select List payRequestTargetListByUser = payDao.findPayRequestTargetListByUser(userByUserId, spaceBySpaceId, isComplete); // TODO 4. return 타입 구성 diff --git a/src/test/java/space/space_spring/service/PayServiceTest.java b/src/test/java/space/space_spring/service/PayServiceTest.java index 0b3d6054..941533a4 100644 --- a/src/test/java/space/space_spring/service/PayServiceTest.java +++ b/src/test/java/space/space_spring/service/PayServiceTest.java @@ -41,14 +41,20 @@ class PayServiceTest { private User user1; private User user2; + private User user3; + private User user4; private Space testSpace; private PayRequest testPayRequest; - private PayRequestTarget testPayRequestTarget; + private PayRequestTarget testPayRequestTarget_1; + private PayRequestTarget testPayRequestTarget_2; + private PayRequestTarget testPayRequestTarget_3; @BeforeEach public void 테스트_셋업() { /** - * user2이 같은 스페이스에 속한 user1에게 정산을 요청한 상황 가정 + * user1이 같은 스페이스에 속한 user2, 3, 4 에게 정산을 요청한 상황 가정 + * user 2, 3은 아직 정산 진행 중 + * user 4 는 정산 완료 */ user1 = new User(); user1.saveUser("test1@test.com", "abcDEF123!@", "user1", UserSignupType.LOCAL); @@ -56,24 +62,37 @@ class PayServiceTest { user2 = new User(); user2.saveUser("test2@test.com", "abcDEF123!@", "user2", UserSignupType.LOCAL); + user3 = new User(); + user3.saveUser("test3@test.com", "abcDEF123!@", "user3", UserSignupType.LOCAL); + + user4 = new User(); + user4.saveUser("test4@test.com", "abcDEF123!@", "user4", UserSignupType.LOCAL); + testSpace = new Space(); testSpace.saveSpace("testSpace", "test_profile_img_url"); testPayRequest = new PayRequest(); - testPayRequest.savePayRequest(user2, testSpace, 30000, "우리은행", "111-111-111", false); + testPayRequest.savePayRequest(user1, testSpace, 30000, "우리은행", "111-111-111", false); + + testPayRequestTarget_1 = new PayRequestTarget(); + testPayRequestTarget_1.savePayRequestTarget(testPayRequest, user2.getUserId(), 10000, false); + + testPayRequestTarget_2 = new PayRequestTarget(); + testPayRequestTarget_2.savePayRequestTarget(testPayRequest, user3.getUserId(), 10000, false); + + testPayRequestTarget_3 = new PayRequestTarget(); + testPayRequestTarget_3.savePayRequestTarget(testPayRequest, user4.getUserId(), 10000, true); - testPayRequestTarget = new PayRequestTarget(); - testPayRequestTarget.savePayRequestTarget(testPayRequest, user1.getUserId(), 10000, false); } @Test - @DisplayName("getPayRequestInfoForUser_메서드_테스트") - void 유저가_요청한_정산_중_진행중인_정산리스트_찾는_메서드_테스트() throws Exception { + @DisplayName("user1이_testSpace에서_요청한_정산중_현재진행중인_정산리스트_찾기") + void user1이_testSpace에서_요청한_정산중_현재진행중인_정산리스트_찾기() throws Exception { //given - when(userUtils.findUserByUserId(user2.getUserId())).thenReturn(user2); + when(userUtils.findUserByUserId(user1.getUserId())).thenReturn(user1); when(spaceUtils.findSpaceBySpaceId(testSpace.getSpaceId())).thenReturn(testSpace); - when(payDao.findPayRequestListByUser(user2, testSpace, false)).thenReturn(List.of(testPayRequest)); - when(payDao.findPayRequestTargetListByPayRequest(testPayRequest)).thenReturn(List.of(testPayRequestTarget)); + when(payDao.findPayRequestListByUser(user1, testSpace, false)).thenReturn(List.of(testPayRequest)); + when(payDao.findPayRequestTargetListByPayRequest(testPayRequest)).thenReturn(List.of(testPayRequestTarget_1, testPayRequestTarget_2, testPayRequestTarget_3)); //when List payRequestInfoForUser = payService.getPayRequestInfoForUser(user2.getUserId(), testSpace.getSpaceId(), false); @@ -83,19 +102,19 @@ class PayServiceTest { for (PayRequestInfoDto payRequestInfoDto : payRequestInfoForUser) { assertThat(payRequestInfoDto.getTotalAmount()).isEqualTo(30000); - assertThat(payRequestInfoDto.getReceiveAmount()).isEqualTo(0); - assertThat(payRequestInfoDto.getTotalTargetNum()).isEqualTo(1); - assertThat(payRequestInfoDto.getReceiveTargetNum()).isEqualTo(0); + assertThat(payRequestInfoDto.getReceiveAmount()).isEqualTo(10000); + assertThat(payRequestInfoDto.getTotalTargetNum()).isEqualTo(3); + assertThat(payRequestInfoDto.getReceiveTargetNum()).isEqualTo(1); } } @Test @DisplayName("Test name") - void 유저가_요청받은_정산_중_진행중인_정산리스트_찾는_메서드_테스트() throws Exception { + void user2가_testSpace에서_요청받은_정산중_현재진행중인_정산리스트_찾기() throws Exception { //given - when(userUtils.findUserByUserId(user1.getUserId())).thenReturn(user1); + when(userUtils.findUserByUserId(user2.getUserId())).thenReturn(user2); when(spaceUtils.findSpaceBySpaceId(testSpace.getSpaceId())).thenReturn(testSpace); - when(payDao.findPayRequestTargetListByUser(user1, testSpace, false)).thenReturn(List.of(testPayRequestTarget)); + when(payDao.findPayRequestTargetListByUser(user2, testSpace, false)).thenReturn(List.of(testPayRequestTarget_1)); //when List payReceiveInfoForUser = payService.getPayReceiveInfoForUser(user1.getUserId(), testSpace.getSpaceId(), false); @@ -103,12 +122,11 @@ class PayServiceTest { //then assertThat(payReceiveInfoForUser.size()).isEqualTo(1); for (PayReceiveInfoDto payReceiveInfoDto : payReceiveInfoForUser) { - assertThat(payReceiveInfoDto.getPayCreatorName()).isEqualTo(user2.getUserName()); + assertThat(payReceiveInfoDto.getPayCreatorName()).isEqualTo(user1.getUserName()); assertThat(payReceiveInfoDto.getRequestAmount()).isEqualTo(10000); } } - } \ No newline at end of file From f32064c711ffed240ae4fe6edcc959bc8ebea793 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Fri, 26 Jul 2024 15:31:21 +0900 Subject: [PATCH 4/8] =?UTF-8?q?Test=20:=20=EC=9C=A0=EC=A0=80=EA=B0=80=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=ED=95=9C=20=EC=A0=95=EC=82=B0=20=EC=A4=91=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C=EB=90=9C=20=EC=A0=95=EC=82=B0=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PayController.java | 4 +-- .../space_spring/service/PayServiceTest.java | 32 ++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/space/space_spring/controller/PayController.java b/src/main/java/space/space_spring/controller/PayController.java index 4525e017..a6459128 100644 --- a/src/main/java/space/space_spring/controller/PayController.java +++ b/src/main/java/space/space_spring/controller/PayController.java @@ -60,10 +60,10 @@ public BaseResponse showRequestPayListForUser(@JwtLog // TODO 1. 유저가 스페이스에 속하는 지 검증 -> 추후에 인터셉터에서 처리하게끔 리펙토링 필요 validateIsUserInSpace(userId, spaceId); - // TODO 2. 유저가 요청한 정산 중 현재 진행중인 정산 리스트 get + // TODO 2. 유저가 요청한 정산 중 현재 진행중인 정산 리스트 get -> 아직 완료되지 않은 정산 : isComplete = false List payRequestInfoDtoListInComplete = payService.getPayRequestInfoForUser(userId, spaceId, false); - // TODO 3. 유저가 요청한 정산 중 완료한 정산 리스트 get + // TODO 3. 유저가 요청한 정산 중 완료한 정산 리스트 get -> 완료된 정산 : isComplete = true List payRequestInfoDtoListComplete = payService.getPayRequestInfoForUser(userId, spaceId, true); return new BaseResponse<>(new GetRequestPayViewResponse(payRequestInfoDtoListInComplete, payRequestInfoDtoListComplete)); diff --git a/src/test/java/space/space_spring/service/PayServiceTest.java b/src/test/java/space/space_spring/service/PayServiceTest.java index 941533a4..bac2a6af 100644 --- a/src/test/java/space/space_spring/service/PayServiceTest.java +++ b/src/test/java/space/space_spring/service/PayServiceTest.java @@ -109,7 +109,7 @@ class PayServiceTest { } @Test - @DisplayName("Test name") + @DisplayName("user2가_testSpace에서_요청받은_정산중_현재진행중인_정산리스트_찾기") void user2가_testSpace에서_요청받은_정산중_현재진행중인_정산리스트_찾기() throws Exception { //given when(userUtils.findUserByUserId(user2.getUserId())).thenReturn(user2); @@ -127,6 +127,36 @@ class PayServiceTest { } } + @Test + @DisplayName("user2가_testSpace에서_요청한_정산중_완료된_정산리스트_찾기") + void user2가_TestSpace에서_요청한_정산중_완료된_정산리스트_찾기() throws Exception { + //given + /** + * user2 가 testSpace에서 user1에게 정산을 요청 & 이 정산은 완료된 상황을 가정 + */ + PayRequest testPayRequest = new PayRequest(); + testPayRequest.savePayRequest(user2, testSpace, 10000, "우리은행", "111-111-111", true); + PayRequestTarget testPayRequestTarget = new PayRequestTarget(); + testPayRequestTarget.savePayRequestTarget(testPayRequest, user1.getUserId(), 10000, true); + + when(userUtils.findUserByUserId(user2.getUserId())).thenReturn(user2); + when(spaceUtils.findSpaceBySpaceId(testSpace.getSpaceId())).thenReturn(testSpace); + when(payDao.findPayRequestListByUser(user2, testSpace, true)).thenReturn(List.of(testPayRequest)); + when(payDao.findPayRequestTargetListByPayRequest(testPayRequest)).thenReturn(List.of(testPayRequestTarget)); + + //when + List payRequestInfoForUser = payService.getPayRequestInfoForUser(user2.getUserId(), testSpace.getSpaceId(), true); + + //then + assertThat(payRequestInfoForUser.size()).isEqualTo(1); + + for (PayRequestInfoDto payRequestInfoDto : payRequestInfoForUser) { + assertThat(payRequestInfoDto.getTotalAmount()).isEqualTo(10000); + assertThat(payRequestInfoDto.getReceiveAmount()).isEqualTo(10000); + assertThat(payRequestInfoDto.getTotalTargetNum()).isEqualTo(1); + assertThat(payRequestInfoDto.getReceiveTargetNum()).isEqualTo(1); + } + } } \ No newline at end of file From 1698ef16437f8fbc88437c2129d7699e6dc1405a Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Sat, 27 Jul 2024 12:24:09 +0900 Subject: [PATCH 5/8] =?UTF-8?q?refactor=20:=20=EC=8A=A4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=83=9D=EC=84=B1=EC=8B=9C=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20request=20dto=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space/space_spring/dto/space/PostSpaceCreateRequest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/space/space_spring/dto/space/PostSpaceCreateRequest.java b/src/main/java/space/space_spring/dto/space/PostSpaceCreateRequest.java index e92eafa7..488144b2 100644 --- a/src/main/java/space/space_spring/dto/space/PostSpaceCreateRequest.java +++ b/src/main/java/space/space_spring/dto/space/PostSpaceCreateRequest.java @@ -5,6 +5,7 @@ import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.validator.constraints.Length; +import org.springframework.web.multipart.MultipartFile; @Getter @Setter @@ -16,5 +17,5 @@ public class PostSpaceCreateRequest { private String spaceName; @NotBlank(message = "스페이스 프로필 이미지는 공백일 수 없습니다.") - private String spaceProfileImg; // 스페이스 프로필 이미지 (썸네일) + private MultipartFile spaceProfileImg; // 스페이스 프로필 이미지 (썸네일) } From 1233b181c97dc6aefa455692f42974619e15b676 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Sat, 27 Jul 2024 12:45:00 +0900 Subject: [PATCH 6/8] =?UTF-8?q?refactor=20:=20=EC=8A=A4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=83=9D=EC=84=B1=EC=8B=9C=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=EB=A5=BC=20s3=EC=97=90=20=EC=A0=80=EC=9E=A5=ED=95=B4?= =?UTF-8?q?=EC=84=9C=20=EC=96=BB=EC=9D=80=20url=EC=9D=84=20Space=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=EC=97=90=20=ED=95=A0=EB=8B=B9?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=B0=A9=EC=8B=9D=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space_spring/controller/SpaceController.java | 12 ++++++++++-- src/main/java/space/space_spring/dao/SpaceDao.java | 4 ++-- .../space/space_spring/service/SpaceService.java | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/space/space_spring/controller/SpaceController.java b/src/main/java/space/space_spring/controller/SpaceController.java index fd3d707a..f7f35f57 100644 --- a/src/main/java/space/space_spring/controller/SpaceController.java +++ b/src/main/java/space/space_spring/controller/SpaceController.java @@ -12,9 +12,11 @@ import space.space_spring.entity.UserSpace; import space.space_spring.exception.SpaceException; import space.space_spring.response.BaseResponse; +import space.space_spring.service.S3Uploader; import space.space_spring.service.SpaceService; import space.space_spring.util.userSpace.UserSpaceUtils; +import java.io.IOException; import java.util.Optional; import static space.space_spring.response.status.BaseExceptionResponseStatus.INVALID_SPACE_CREATE; @@ -28,14 +30,20 @@ public class SpaceController { private final SpaceService spaceService; private final UserSpaceUtils userSpaceUtils; + private final S3Uploader s3Uploader; + private final String spaceImgDirName = "spaceImg"; @PostMapping("/create") - public BaseResponse createSpace(@JwtLoginAuth Long userId, @Validated @RequestBody PostSpaceCreateRequest postSpaceCreateRequest, BindingResult bindingResult) { + public BaseResponse createSpace(@JwtLoginAuth Long userId, @Validated @ModelAttribute PostSpaceCreateRequest postSpaceCreateRequest, BindingResult bindingResult) throws IOException { if (bindingResult.hasErrors()) { throw new SpaceException(INVALID_SPACE_CREATE, getErrorMessage(bindingResult)); } - return new BaseResponse<>(spaceService.createSpace(userId, postSpaceCreateRequest)); + // TODO 1. 스페이스 썸네일을 s3에 upload + String spaceImgUrl = s3Uploader.upload(postSpaceCreateRequest.getSpaceProfileImg(), spaceImgDirName); + + // TODO 2. s3에 저장하고 받은 이미지 url 정보와 spaceName 정보로 space create 작업 수행 + return new BaseResponse<>(spaceService.createSpace(userId, postSpaceCreateRequest.getSpaceName(), spaceImgUrl)); } /** diff --git a/src/main/java/space/space_spring/dao/SpaceDao.java b/src/main/java/space/space_spring/dao/SpaceDao.java index adb4c5da..604b23a4 100644 --- a/src/main/java/space/space_spring/dao/SpaceDao.java +++ b/src/main/java/space/space_spring/dao/SpaceDao.java @@ -16,9 +16,9 @@ public class SpaceDao { @PersistenceContext private EntityManager em; - public Space saveSpace(PostSpaceCreateRequest postSpaceCreateRequest) { + public Space saveSpace(String spaceName, String spaceImgUrl) { Space space = new Space(); - space.saveSpace(postSpaceCreateRequest.getSpaceName(), postSpaceCreateRequest.getSpaceProfileImg()); + space.saveSpace(spaceName, spaceImgUrl); em.persist(space); return space; diff --git a/src/main/java/space/space_spring/service/SpaceService.java b/src/main/java/space/space_spring/service/SpaceService.java index c4e9f7a5..2c3dfb79 100644 --- a/src/main/java/space/space_spring/service/SpaceService.java +++ b/src/main/java/space/space_spring/service/SpaceService.java @@ -21,10 +21,10 @@ public class SpaceService { private final UserSpaceDao userSpaceDao; @Transactional - public PostSpaceCreateResponse createSpace(Long userId, PostSpaceCreateRequest postSpaceCreateRequest) { + public PostSpaceCreateResponse createSpace(Long userId, String spaceName, String spaceImgUrl) { // TODO 1. 스페이스 생성 정보 db insert - Space saveSpace = spaceDao.saveSpace(postSpaceCreateRequest); + Space saveSpace = spaceDao.saveSpace(spaceName, spaceImgUrl); // TODO 2. 유저_스페이스 매핑 정보 db insert User manager = userDao.findUserByUserId(userId); From ba284cbea1115aa38bf66d4f71af45dbb582c030 Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Sat, 27 Jul 2024 12:50:18 +0900 Subject: [PATCH 7/8] =?UTF-8?q?refactor=20:=20=EC=8A=A4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20url=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=ED=99=95=EC=9D=B8=EC=9D=84=20=EC=9C=84=ED=95=B4=20?= =?UTF-8?q?return=20dto=EC=97=90=20spaceImgUrl=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space/space_spring/dto/space/PostSpaceCreateResponse.java | 1 + src/main/java/space/space_spring/service/SpaceService.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/space/space_spring/dto/space/PostSpaceCreateResponse.java b/src/main/java/space/space_spring/dto/space/PostSpaceCreateResponse.java index 26479f54..bc0c2031 100644 --- a/src/main/java/space/space_spring/dto/space/PostSpaceCreateResponse.java +++ b/src/main/java/space/space_spring/dto/space/PostSpaceCreateResponse.java @@ -8,4 +8,5 @@ public class PostSpaceCreateResponse { private Long spaceId; + private String spaceImgUrl; // 사진 url이 잘 생성됐는지 확인하는 용도 } diff --git a/src/main/java/space/space_spring/service/SpaceService.java b/src/main/java/space/space_spring/service/SpaceService.java index 2c3dfb79..a5f941c9 100644 --- a/src/main/java/space/space_spring/service/SpaceService.java +++ b/src/main/java/space/space_spring/service/SpaceService.java @@ -30,6 +30,6 @@ public PostSpaceCreateResponse createSpace(Long userId, String spaceName, String User manager = userDao.findUserByUserId(userId); UserSpace userSpace = userSpaceDao.createUserSpace(manager, saveSpace); - return new PostSpaceCreateResponse(saveSpace.getSpaceId()); + return new PostSpaceCreateResponse(saveSpace.getSpaceId(), spaceImgUrl); } } From 4e9dd6f579285781e77c4c087d8153bcf0fff99a Mon Sep 17 00:00:00 2001 From: seongjunnoh Date: Sat, 27 Jul 2024 16:02:36 +0900 Subject: [PATCH 8/8] =?UTF-8?q?feat=20:=20=EC=8A=A4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=83=9D=EC=84=B1=EC=8B=9C=20request=20dto?= =?UTF-8?q?=EC=9D=98=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=EC=97=90=20=EB=8C=80=ED=95=9C=20validation=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/space/PostSpaceCreateRequest.java | 3 ++- .../space_spring/validator/ValidFile.java | 18 ++++++++++++++++++ .../validator/ValidFileValidator.java | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/main/java/space/space_spring/validator/ValidFile.java create mode 100644 src/main/java/space/space_spring/validator/ValidFileValidator.java diff --git a/src/main/java/space/space_spring/dto/space/PostSpaceCreateRequest.java b/src/main/java/space/space_spring/dto/space/PostSpaceCreateRequest.java index 488144b2..f92e5774 100644 --- a/src/main/java/space/space_spring/dto/space/PostSpaceCreateRequest.java +++ b/src/main/java/space/space_spring/dto/space/PostSpaceCreateRequest.java @@ -6,6 +6,7 @@ import lombok.Setter; import org.hibernate.validator.constraints.Length; import org.springframework.web.multipart.MultipartFile; +import space.space_spring.validator.ValidFile; @Getter @Setter @@ -16,6 +17,6 @@ public class PostSpaceCreateRequest { @NotBlank(message = "스페이스 이름은 공백일 수 없습니다.") private String spaceName; - @NotBlank(message = "스페이스 프로필 이미지는 공백일 수 없습니다.") + @ValidFile(message = "스페이스 프로필 이미지는 공백일 수 없습니다.") private MultipartFile spaceProfileImg; // 스페이스 프로필 이미지 (썸네일) } diff --git a/src/main/java/space/space_spring/validator/ValidFile.java b/src/main/java/space/space_spring/validator/ValidFile.java new file mode 100644 index 00000000..6981573c --- /dev/null +++ b/src/main/java/space/space_spring/validator/ValidFile.java @@ -0,0 +1,18 @@ +package space.space_spring.validator; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = ValidFileValidator.class) +public @interface ValidFile { + String message() default "유효하지 않은 파일입니다."; + Class[] groups() default {}; + Class[] payload() default {}; +} diff --git a/src/main/java/space/space_spring/validator/ValidFileValidator.java b/src/main/java/space/space_spring/validator/ValidFileValidator.java new file mode 100644 index 00000000..73f814b9 --- /dev/null +++ b/src/main/java/space/space_spring/validator/ValidFileValidator.java @@ -0,0 +1,14 @@ +package space.space_spring.validator; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; +import org.springframework.web.multipart.MultipartFile; + +public class ValidFileValidator implements ConstraintValidator { + + // multipartFile이 null 이 아니거나 비어있지 않으면 검증로직 통과 + @Override + public boolean isValid(MultipartFile multipartFile, ConstraintValidatorContext constraintValidatorContext) { + return multipartFile != null && !multipartFile.isEmpty(); + } +}