From c01fff14db0762e433fd8eab3937d390a166a68e Mon Sep 17 00:00:00 2001 From: hydrationn Date: Thu, 16 May 2024 00:28:08 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20#89=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EC=8B=9D=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); + } +} From 735e96bae68b913f6d49c8d475709691053a79c2 Mon Sep 17 00:00:00 2001 From: hydrationn Date: Thu, 16 May 2024 01:42:55 +0900 Subject: [PATCH 2/2] =?UTF-8?q?docs:=20#89=20JavaDoc=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pointdetail/adaptor/UserPointDetailAdaptor.java | 13 ++++++++++++- .../client/UserPointDetailApiClient.java | 1 + .../controller/UserPointDetailController.java | 5 +++-- .../pointdetail/service/UserPointDetailService.java | 13 ++++++++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/t3t/frontserver/pointdetail/adaptor/UserPointDetailAdaptor.java b/src/main/java/com/t3t/frontserver/pointdetail/adaptor/UserPointDetailAdaptor.java index a344cc7..4c582dc 100644 --- a/src/main/java/com/t3t/frontserver/pointdetail/adaptor/UserPointDetailAdaptor.java +++ b/src/main/java/com/t3t/frontserver/pointdetail/adaptor/UserPointDetailAdaptor.java @@ -1,6 +1,5 @@ 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; @@ -15,12 +14,24 @@ import java.util.List; import java.util.Objects; +/** + * 포인트 상세 정보를 가져오는 adaptor class + * 외부 시스템으로부터 사용자의 포인트 상세 내역을 가져오는 역할 + */ @Slf4j @Component @RequiredArgsConstructor public class UserPointDetailAdaptor { private final UserPointDetailApiClient userPointDetailApiClient; + /** + * 사용자 ID와 포인트 상세 유형을 기반으로 포인트 상세 정보 조회 + * @param memberId 회원 ID + * @param pointDetailType 조회할 포인트 타입(사용/적립), null이면 전체 내역 조회 + * @return 조건에 맞는 포인트 상세 내역 리스트를 반환. 조회된 정보가 없거나, 요청 처리 중 오류가 발생한 경우 null 반환. + * @throws ApiDataFetchException 외부 시스템으로부터 데이터를 가져오는 과정에서 오류가 발생한 경우 예외 발생 + * @author hydrationn(박수화) + */ public List getPointDetailByPointDetailType(Long memberId, String pointDetailType) { try { ResponseEntity>> response = userPointDetailApiClient.getPointDetailByPointDetailType(memberId, pointDetailType); 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 8ce50f9..c0920ec 100644 --- a/src/main/java/com/t3t/frontserver/pointdetail/client/UserPointDetailApiClient.java +++ b/src/main/java/com/t3t/frontserver/pointdetail/client/UserPointDetailApiClient.java @@ -17,6 +17,7 @@ public interface UserPointDetailApiClient { /** * 회원의 포인트 타입에 따른 포인트 사용/적립 내역 조회 API 호출 + * @param memberId 회원 ID * @param pointDetailType 조회할 포인트 타입(사용/적립) * @author hydrationn(박수화) */ 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 bf2d71a..4011efe 100644 --- a/src/main/java/com/t3t/frontserver/pointdetail/controller/UserPointDetailController.java +++ b/src/main/java/com/t3t/frontserver/pointdetail/controller/UserPointDetailController.java @@ -22,8 +22,9 @@ public class UserPointDetailController { private final UserPointDetailService userPointDetailService; /** - * 회원 포인트 사용/적립 내역 페이지 뷰 반환 - * @return 포인트 사용/적립 내역 뷰 + * 회원 포인트 전체/사용/적립 내역 페이지 뷰 반환 + * @param pointDetailType 조회할 포인트 타입(사용/적립) + * @return 포인트 전체/사용/적립 내역 뷰 * @author hydrationn(박수화) */ @GetMapping("/mypage/point-details") diff --git a/src/main/java/com/t3t/frontserver/pointdetail/service/UserPointDetailService.java b/src/main/java/com/t3t/frontserver/pointdetail/service/UserPointDetailService.java index af180cd..5dcaf63 100644 --- a/src/main/java/com/t3t/frontserver/pointdetail/service/UserPointDetailService.java +++ b/src/main/java/com/t3t/frontserver/pointdetail/service/UserPointDetailService.java @@ -1,6 +1,5 @@ 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; @@ -8,11 +7,23 @@ import java.util.List; +/** + * 사용자의 포인트 상세 정보를 관리하는 서비스 + * 외부 시스템으로부터 사용자의 포인트 상세 정보를 조회하는 기능 제공 + */ @Service @RequiredArgsConstructor public class UserPointDetailService { private final UserPointDetailAdaptor userPointDetailAdaptor; + /** + * 회원 ID와 포인트 상세 유형을 기반으로 포인트 상세 내역 조회 + * @param memberId 회원 ID + * @param pointDetailType 조회할 포인트 타입(사용/적립) + * @return 해당 조건에 맞는 포인트 상세 정보 리스트를 반환. + * 외부 시스템으로부터 정보를 성공적으로 조회하면 그에 대한 결과를, 그렇지 않으면 null을 반환. + * @author hydrationn(박수화) + */ public List getPointDetailByPointDetailType(Long memberId, String pointDetailType) { return userPointDetailAdaptor.getPointDetailByPointDetailType(memberId, pointDetailType); }