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 0000000..54beada --- /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 0000000..2d29cb5 --- /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 0000000..28e7c61 --- /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 0000000..60ae65c --- /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 7a01ce3..b53311e 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 2d0049a..e818388 100644 --- a/src/main/resources/templates/main/page/detail.html +++ b/src/main/resources/templates/main/page/detail.html @@ -129,12 +129,37 @@