From c01fff14db0762e433fd8eab3937d390a166a68e Mon Sep 17 00:00:00 2001 From: hydrationn Date: Thu, 16 May 2024 00:28:08 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20#89=20=ED=9A=8C=EC=9B=90=20=EC=8B=9D?= =?UTF-8?q?=EB=B3=84=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adaptor/UserPointDetailAdaptor.java | 36 +++++++++++++++++++ .../client/UserPointDetailApiClient.java | 5 +-- .../controller/UserPointDetailController.java | 18 +++------- .../service/UserPointDetailService.java | 19 ++++++++++ 4 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/t3t/frontserver/pointdetail/adaptor/UserPointDetailAdaptor.java create mode 100644 src/main/java/com/t3t/frontserver/pointdetail/service/UserPointDetailService.java diff --git a/src/main/java/com/t3t/frontserver/pointdetail/adaptor/UserPointDetailAdaptor.java b/src/main/java/com/t3t/frontserver/pointdetail/adaptor/UserPointDetailAdaptor.java new file mode 100644 index 0000000..a344cc7 --- /dev/null +++ b/src/main/java/com/t3t/frontserver/pointdetail/adaptor/UserPointDetailAdaptor.java @@ -0,0 +1,36 @@ +package com.t3t.frontserver.pointdetail.adaptor; + +import com.t3t.frontserver.auth.util.SecurityContextUtils; +import com.t3t.frontserver.common.exception.ApiDataFetchException; +import com.t3t.frontserver.model.response.BaseResponse; +import com.t3t.frontserver.pointdetail.client.UserPointDetailApiClient; +import com.t3t.frontserver.pointdetail.model.response.PointDetailResponse; +import feign.FeignException; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Objects; + +@Slf4j +@Component +@RequiredArgsConstructor +public class UserPointDetailAdaptor { + private final UserPointDetailApiClient userPointDetailApiClient; + + public List getPointDetailByPointDetailType(Long memberId, String pointDetailType) { + try { + ResponseEntity>> response = userPointDetailApiClient.getPointDetailByPointDetailType(memberId, pointDetailType); + if (response.getStatusCode() == HttpStatus.OK) { + return Objects.requireNonNull(response.getBody()).getData(); + } + return null; + } catch (FeignException e) { + log.error(e.getMessage()); + throw new ApiDataFetchException(); + } + } +} diff --git a/src/main/java/com/t3t/frontserver/pointdetail/client/UserPointDetailApiClient.java b/src/main/java/com/t3t/frontserver/pointdetail/client/UserPointDetailApiClient.java index 5e6195d..8ce50f9 100644 --- a/src/main/java/com/t3t/frontserver/pointdetail/client/UserPointDetailApiClient.java +++ b/src/main/java/com/t3t/frontserver/pointdetail/client/UserPointDetailApiClient.java @@ -20,6 +20,7 @@ public interface UserPointDetailApiClient { * @param pointDetailType 조회할 포인트 타입(사용/적립) * @author hydrationn(박수화) */ - @GetMapping("/t3t/bookstore/mypage/point-details") - public ResponseEntity>> getPointDetailByPointDetailType(@RequestParam(name = "pointDetailType", required = false) String pointDetailType); + @GetMapping("/t3t/bookstore/member/{memberId}/point-details") + ResponseEntity>> getPointDetailByPointDetailType(@PathVariable("memberId") Long memberId, + @RequestParam(name = "pointDetailType", required = false) String pointDetailType); } \ No newline at end of file diff --git a/src/main/java/com/t3t/frontserver/pointdetail/controller/UserPointDetailController.java b/src/main/java/com/t3t/frontserver/pointdetail/controller/UserPointDetailController.java index 3b7e19e..bf2d71a 100644 --- a/src/main/java/com/t3t/frontserver/pointdetail/controller/UserPointDetailController.java +++ b/src/main/java/com/t3t/frontserver/pointdetail/controller/UserPointDetailController.java @@ -4,6 +4,7 @@ import com.t3t.frontserver.model.response.BaseResponse; import com.t3t.frontserver.pointdetail.client.UserPointDetailApiClient; import com.t3t.frontserver.pointdetail.model.response.PointDetailResponse; +import com.t3t.frontserver.pointdetail.service.UserPointDetailService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; @@ -18,7 +19,7 @@ @Controller @RequiredArgsConstructor public class UserPointDetailController { - private final UserPointDetailApiClient userPointDetailApiClient; + private final UserPointDetailService userPointDetailService; /** * 회원 포인트 사용/적립 내역 페이지 뷰 반환 @@ -33,20 +34,9 @@ public String pointDetailView(Model model, @Valid @RequestParam(value = "pointDe return "redirect:/login"; } - ResponseEntity>> response = userPointDetailApiClient.getPointDetailByPointDetailType(pointDetailType); // 모든 내역을 가져오는 API 호출 + Long memberId = SecurityContextUtils.getMemberId(); - List pointDetails; - - if (pointDetailType == null) { - // parameter가 null인 경우 모든 내역 반환 - pointDetails = Objects.requireNonNull(response.getBody()).getData(); - } else { - // pointDetailType(used, saved)에 해당하는 내역만 반환 - pointDetails = Objects.requireNonNull(response.getBody()).getData() - .stream() - .filter(pointDetail -> pointDetail.getPointDetailType().equals(pointDetailType)) - .collect(Collectors.toList()); - } + List pointDetails = userPointDetailService.getPointDetailByPointDetailType(memberId, pointDetailType); // 모든 내역을 가져오는 API 호출 model.addAttribute("pointDetails", pointDetails); diff --git a/src/main/java/com/t3t/frontserver/pointdetail/service/UserPointDetailService.java b/src/main/java/com/t3t/frontserver/pointdetail/service/UserPointDetailService.java new file mode 100644 index 0000000..af180cd --- /dev/null +++ b/src/main/java/com/t3t/frontserver/pointdetail/service/UserPointDetailService.java @@ -0,0 +1,19 @@ +package com.t3t.frontserver.pointdetail.service; + +import com.t3t.frontserver.auth.util.SecurityContextUtils; +import com.t3t.frontserver.pointdetail.adaptor.UserPointDetailAdaptor; +import com.t3t.frontserver.pointdetail.model.response.PointDetailResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class UserPointDetailService { + private final UserPointDetailAdaptor userPointDetailAdaptor; + + public List getPointDetailByPointDetailType(Long memberId, String pointDetailType) { + return userPointDetailAdaptor.getPointDetailByPointDetailType(memberId, pointDetailType); + } +}