From bf6b89e5422ab3f55f387e61bbfdb497ae6fc10e Mon Sep 17 00:00:00 2001 From: joohyun Date: Thu, 16 May 2024 01:58:16 +0900 Subject: [PATCH] =?UTF-8?q?feature:#102=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=9E=90=EC=8B=A0=20=EC=BF=A0=ED=8F=B0=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/CouponDetailFindResponse.java | 19 +++++++++++++++++ .../model/response/CouponDetailResponse.java | 16 ++++++++++++++ .../member/adaptor/MemberAdaptor.java | 21 +++++++++++++++++++ .../member/client/MemberApiClient.java | 8 +++++++ .../member/controller/MemberController.java | 18 ++++++++++++++++ .../member/service/MemberService.java | 10 +++++++++ .../main/fragment/mypageSidebar.html | 8 +++---- .../resources/templates/main/page/coupon.html | 14 +++++++++++-- 8 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/t3t/frontserver/coupon/model/response/CouponDetailFindResponse.java create mode 100644 src/main/java/com/t3t/frontserver/coupon/model/response/CouponDetailResponse.java diff --git a/src/main/java/com/t3t/frontserver/coupon/model/response/CouponDetailFindResponse.java b/src/main/java/com/t3t/frontserver/coupon/model/response/CouponDetailFindResponse.java new file mode 100644 index 00000000..6a0375b9 --- /dev/null +++ b/src/main/java/com/t3t/frontserver/coupon/model/response/CouponDetailFindResponse.java @@ -0,0 +1,19 @@ +package com.t3t.frontserver.coupon.model.response; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.time.LocalDate; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class CouponDetailFindResponse { + public String couponId; + public BigDecimal discountRate; + public BigDecimal discountFee; + public LocalDate couponExpireDate; + public String couponType; +} diff --git a/src/main/java/com/t3t/frontserver/coupon/model/response/CouponDetailResponse.java b/src/main/java/com/t3t/frontserver/coupon/model/response/CouponDetailResponse.java new file mode 100644 index 00000000..d4c760ab --- /dev/null +++ b/src/main/java/com/t3t/frontserver/coupon/model/response/CouponDetailResponse.java @@ -0,0 +1,16 @@ +package com.t3t.frontserver.coupon.model.response; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class CouponDetailResponse { + public String couponId; + public String couponUseType; + public LocalDateTime couponUseDate; +} diff --git a/src/main/java/com/t3t/frontserver/member/adaptor/MemberAdaptor.java b/src/main/java/com/t3t/frontserver/member/adaptor/MemberAdaptor.java index c9280e95..78405a89 100644 --- a/src/main/java/com/t3t/frontserver/member/adaptor/MemberAdaptor.java +++ b/src/main/java/com/t3t/frontserver/member/adaptor/MemberAdaptor.java @@ -1,5 +1,7 @@ package com.t3t.frontserver.member.adaptor; +import com.t3t.frontserver.coupon.model.response.CouponDetailFindResponse; +import com.t3t.frontserver.coupon.model.response.CouponDetailResponse; import com.t3t.frontserver.member.client.MemberApiClient; import com.t3t.frontserver.member.exception.CouponApiClientException; import com.t3t.frontserver.member.exception.MemberApiClientException; @@ -160,4 +162,23 @@ public String registerCouponToMemberByAdmin(String couponType, Long memberId){ } } + public List findAllCouponsByMemberId(){ + try { + return Optional.ofNullable(memberApiClient.findAllCoupon().getBody()) + .map(BaseResponse::getData) + .orElseThrow(CouponApiClientException::new); + } catch (FeignException e) { + throw new CouponApiClientException("쿠폰 목록 조회에 실패하였습니다. " + FeignClientUtils.getMessageFromFeignException(e)); + } + } + + public CouponDetailFindResponse getCouponDetails(String id){ + try { + return Optional.ofNullable(memberApiClient.getCouponDetails(id).getBody()) + .map(BaseResponse::getData) + .orElseThrow(CouponApiClientException::new); + } catch (FeignException e) { + throw new CouponApiClientException("쿠폰 세부사항 조회에 실패하였습니다. " + FeignClientUtils.getMessageFromFeignException(e)); + } + } } diff --git a/src/main/java/com/t3t/frontserver/member/client/MemberApiClient.java b/src/main/java/com/t3t/frontserver/member/client/MemberApiClient.java index b60621e4..64545d0f 100644 --- a/src/main/java/com/t3t/frontserver/member/client/MemberApiClient.java +++ b/src/main/java/com/t3t/frontserver/member/client/MemberApiClient.java @@ -1,5 +1,7 @@ package com.t3t.frontserver.member.client; +import com.t3t.frontserver.coupon.model.response.CouponDetailFindResponse; +import com.t3t.frontserver.coupon.model.response.CouponDetailResponse; import com.t3t.frontserver.member.model.dto.MemberAddressDto; import com.t3t.frontserver.member.model.request.MemberPasswordModifyRequest; import com.t3t.frontserver.member.model.request.MemberRegistrationRequest; @@ -101,4 +103,10 @@ public interface MemberApiClient { @PostMapping("/at/bookstore/members/coupons/{memberId}/{couponType}") BaseResponse registerCouponToMemberByAdmin(@PathVariable("couponType") String couponType, @PathVariable("memberId") Long memberId); + + @GetMapping("/at/bookstore/members/coupons") + ResponseEntity>> findAllCoupon(); + + @GetMapping("/at/coupon/details/{couponId}") + ResponseEntity> getCouponDetails(@PathVariable("couponId") String id); } diff --git a/src/main/java/com/t3t/frontserver/member/controller/MemberController.java b/src/main/java/com/t3t/frontserver/member/controller/MemberController.java index b63e4fdc..b7ffde54 100644 --- a/src/main/java/com/t3t/frontserver/member/controller/MemberController.java +++ b/src/main/java/com/t3t/frontserver/member/controller/MemberController.java @@ -1,6 +1,8 @@ package com.t3t.frontserver.member.controller; import com.t3t.frontserver.auth.util.SecurityContextUtils; +import com.t3t.frontserver.coupon.model.response.CouponDetailFindResponse; +import com.t3t.frontserver.coupon.model.response.CouponDetailResponse; import com.t3t.frontserver.member.model.request.MemberPasswordModifyRequest; import com.t3t.frontserver.member.model.request.MemberRegistrationRequest; import com.t3t.frontserver.member.service.MemberService; @@ -15,6 +17,8 @@ import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; +import java.util.ArrayList; +import java.util.List; @Slf4j @Controller @@ -34,6 +38,20 @@ public String registerView(Model model) { return "main/page/register"; } + @GetMapping("/members/coupons") + public String couponView(Model model){ + List responseList = memberService.findAllCouponsByMemberId(); + List couponDetailFindResponseList = new ArrayList<>(); + for (CouponDetailResponse couponDetailResponse : responseList) { + CouponDetailFindResponse response = memberService.findCouponDetails(couponDetailResponse.getCouponId()); + response.setCouponId(couponDetailResponse.getCouponId()); + + couponDetailFindResponseList.add(response); + } + model.addAttribute("couponList", couponDetailFindResponseList); + return "main/page/coupon"; + } + /** * 회원 가입 요청 처리 * diff --git a/src/main/java/com/t3t/frontserver/member/service/MemberService.java b/src/main/java/com/t3t/frontserver/member/service/MemberService.java index 71ed68a1..e3e0ad61 100644 --- a/src/main/java/com/t3t/frontserver/member/service/MemberService.java +++ b/src/main/java/com/t3t/frontserver/member/service/MemberService.java @@ -1,5 +1,7 @@ package com.t3t.frontserver.member.service; +import com.t3t.frontserver.coupon.model.response.CouponDetailFindResponse; +import com.t3t.frontserver.coupon.model.response.CouponDetailResponse; import com.t3t.frontserver.member.adaptor.MemberAdaptor; import com.t3t.frontserver.member.model.dto.MemberAddressDto; import com.t3t.frontserver.member.model.request.MemberPasswordModifyRequest; @@ -100,4 +102,12 @@ public List findMemberByName(String name){ public String registCouponToMemberByAdmin(String couponType, Long memberId){ return memberAdaptor.registerCouponToMemberByAdmin(couponType, memberId); } + + public List findAllCouponsByMemberId(){ + return memberAdaptor.findAllCouponsByMemberId(); + } + + public CouponDetailFindResponse findCouponDetails(String id){ + return memberAdaptor.getCouponDetails(id); + } } diff --git a/src/main/resources/templates/main/fragment/mypageSidebar.html b/src/main/resources/templates/main/fragment/mypageSidebar.html index ea33368e..9b0460c6 100644 --- a/src/main/resources/templates/main/fragment/mypageSidebar.html +++ b/src/main/resources/templates/main/fragment/mypageSidebar.html @@ -40,14 +40,14 @@

주문 정보

쿠폰 및 포인트 정보

diff --git a/src/main/resources/templates/main/page/coupon.html b/src/main/resources/templates/main/page/coupon.html index 01c3470f..e1549fd3 100644 --- a/src/main/resources/templates/main/page/coupon.html +++ b/src/main/resources/templates/main/page/coupon.html @@ -8,13 +8,23 @@

보유 쿠폰 조회

- + - + + + + + + + + + + +
쿠폰명할인액(율)할인액할인율 유효기간 쿠폰종류