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 0000000..6a0375b --- /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 0000000..d4c760a --- /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 c9280e9..78405a8 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 b60621e..64545d0 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 b63e4fd..b7ffde5 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 71ed68a..e3e0ad6 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 ea33368..9b0460c 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 01c3470..e1549fd 100644 --- a/src/main/resources/templates/main/page/coupon.html +++ b/src/main/resources/templates/main/page/coupon.html @@ -8,13 +8,23 @@

보유 쿠폰 조회

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