From c17a7a602e7b9813e1c57201475fd38ce6397307 Mon Sep 17 00:00:00 2001 From: joohyun Date: Thu, 16 May 2024 00:47:10 +0900 Subject: [PATCH] =?UTF-8?q?feature:#102=20=ED=9A=8C=EC=9B=90=EC=9D=B4=20?= =?UTF-8?q?=EC=BF=A0=ED=8F=B0=20=EB=B0=9C=EA=B8=89=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coupon/adapter/CouponAdapter.java | 40 +++++++++++++++++++ .../coupon/client/CouponApiClient.java | 17 ++++++++ .../controller/CouponRestController.java | 22 ++++++++++ .../coupon/service/CouponService.java | 19 +++++++++ .../model/response/BaseResponse.java | 1 + .../resources/templates/main/page/detail.html | 36 ++++++++++++++--- 6 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/t3t/frontserver/coupon/adapter/CouponAdapter.java create mode 100644 src/main/java/com/t3t/frontserver/coupon/client/CouponApiClient.java create mode 100644 src/main/java/com/t3t/frontserver/coupon/controller/CouponRestController.java create mode 100644 src/main/java/com/t3t/frontserver/coupon/service/CouponService.java diff --git a/src/main/java/com/t3t/frontserver/coupon/adapter/CouponAdapter.java b/src/main/java/com/t3t/frontserver/coupon/adapter/CouponAdapter.java new file mode 100644 index 00000000..54beada2 --- /dev/null +++ b/src/main/java/com/t3t/frontserver/coupon/adapter/CouponAdapter.java @@ -0,0 +1,40 @@ +package com.t3t.frontserver.coupon.adapter; + +import com.t3t.frontserver.coupon.client.CouponApiClient; +import com.t3t.frontserver.member.exception.CouponApiClientException; +import com.t3t.frontserver.util.FeignClientUtils; +import feign.FeignException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class CouponAdapter { + private final CouponApiClient couponApiClient; + + /** + * 회원이 도서 쿠폰 발급받기 위해 사용하는 api + * @author joohyun1996(이주현) + */ + public String registerBookCouponByMember(){ + try{ + couponApiClient.registerBookCoupon(); + return "쿠폰이 등록되었습니다"; + }catch(FeignException e){ + throw new CouponApiClientException("도서쿠폰 등록에 실패하였습니다 " + FeignClientUtils.getMessageFromFeignException(e)); + } + } + + /** + * 회원이 카테고리 쿠폰 발급받기 위해 사용하는 api + * @author joohyun1996(이주현) + */ + public String registerCategoryCouponByMember(){ + try{ + couponApiClient.registerCategoryCoupon(); + return "쿠폰이 등록되었습니다"; + }catch(FeignException e){ + throw new CouponApiClientException("카테고리쿠폰 등록에 실패하였습니다 " + FeignClientUtils.getMessageFromFeignException(e)); + } + } +} diff --git a/src/main/java/com/t3t/frontserver/coupon/client/CouponApiClient.java b/src/main/java/com/t3t/frontserver/coupon/client/CouponApiClient.java new file mode 100644 index 00000000..2d29cb5c --- /dev/null +++ b/src/main/java/com/t3t/frontserver/coupon/client/CouponApiClient.java @@ -0,0 +1,17 @@ +package com.t3t.frontserver.coupon.client; + +import com.t3t.frontserver.model.response.BaseResponse; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; + + +@FeignClient(name = "couponApiClient", url = "${t3t.feignClient.url}") +public interface CouponApiClient { + + @PostMapping("/at/bookstore/members/coupons/book") + ResponseEntity> registerBookCoupon(); + + @PostMapping("/at/bookstore/members/coupons/category") + ResponseEntity> registerCategoryCoupon(); +} diff --git a/src/main/java/com/t3t/frontserver/coupon/controller/CouponRestController.java b/src/main/java/com/t3t/frontserver/coupon/controller/CouponRestController.java new file mode 100644 index 00000000..28e7c61c --- /dev/null +++ b/src/main/java/com/t3t/frontserver/coupon/controller/CouponRestController.java @@ -0,0 +1,22 @@ +package com.t3t.frontserver.coupon.controller; + +import com.t3t.frontserver.coupon.service.CouponService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class CouponRestController { + private final CouponService couponService; + + @PostMapping("/coupons/book") + public void registerBookCouponByMember(){ + couponService.registerBookCoupon(); + } + + @PostMapping("/coupons/category") + public void registerCategoryCouponByMember(){ + couponService.registerCategoryCoupon(); + } +} diff --git a/src/main/java/com/t3t/frontserver/coupon/service/CouponService.java b/src/main/java/com/t3t/frontserver/coupon/service/CouponService.java new file mode 100644 index 00000000..60ae65c5 --- /dev/null +++ b/src/main/java/com/t3t/frontserver/coupon/service/CouponService.java @@ -0,0 +1,19 @@ +package com.t3t.frontserver.coupon.service; + +import com.t3t.frontserver.coupon.adapter.CouponAdapter; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class CouponService { + private final CouponAdapter couponAdapter; + + public String registerBookCoupon(){ + return couponAdapter.registerBookCouponByMember(); + } + + public String registerCategoryCoupon(){ + return couponAdapter.registerCategoryCouponByMember(); + } +} diff --git a/src/main/java/com/t3t/frontserver/model/response/BaseResponse.java b/src/main/java/com/t3t/frontserver/model/response/BaseResponse.java index 7a01ce35..b53311ea 100644 --- a/src/main/java/com/t3t/frontserver/model/response/BaseResponse.java +++ b/src/main/java/com/t3t/frontserver/model/response/BaseResponse.java @@ -26,6 +26,7 @@ public BaseResponse data(T data) { return this; } + public BaseResponse message(String message) { this.message = message; return this; diff --git a/src/main/resources/templates/main/page/detail.html b/src/main/resources/templates/main/page/detail.html index 2d0049ae..e8183886 100644 --- a/src/main/resources/templates/main/page/detail.html +++ b/src/main/resources/templates/main/page/detail.html @@ -129,12 +129,37 @@