Skip to content

Commit

Permalink
feature:#102 회원이 쿠폰 발급하는 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
joohyun1996 committed May 15, 2024
1 parent da1ebcd commit c17a7a6
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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));
}
}
}
Original file line number Diff line number Diff line change
@@ -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<BaseResponse<Void>> registerBookCoupon();

@PostMapping("/at/bookstore/members/coupons/category")
ResponseEntity<BaseResponse<Void>> registerCategoryCoupon();
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public BaseResponse<T> data(T data) {
return this;
}


public BaseResponse<T> message(String message) {
this.message = message;
return this;
Expand Down
36 changes: 30 additions & 6 deletions src/main/resources/templates/main/page/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,37 @@ <h5 class="modal-title" id="couponModalLabel" >쿠폰을 발급받고 결제창
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<!-- <a href="#couponModal" role="button" class="btn-box" title="bookCoupon" data-bs-content="">도서 쿠폰</a>-->
<button> <!--javascript fetch or ajax to send request to coupon batch or api-->도서 쿠폰 발급받기</button>

<!--<form></form>
<form action="/coupons/book" method="post">
<button id = "bookCouponButton" type="submit">도서 쿠폰 발급받기</button>
</form>
<hr>
<!-- <a href="#couponModal" role="button" class="btn-block" title="categoryCoupon">카테고리 쿠폰</a>-->
<button> <!--javascript fetch or ajax to send request to coupon batch or api-->카테고리 쿠폰 발급받기</button>
<form action="/coupons/category" method="post">
<button id = "categoryCouponButton" type="submit">카테고리 쿠폰 발급받기</button>
</form>-->
<button id="bookCouponButton" type="button"
onclick="issueCoupon('/coupons/book', '도서 쿠폰이 발급되었습니다.', '도서 쿠폰 발급에 실패하였습니다. 다시 시도해 주세요.');">
도서 쿠폰 발급받기
</button>
<button id="categoryCouponButton" type="button"
onclick="issueCoupon('/coupons/category', '카테고리 쿠폰이 발급되었습니다.', '카테고리 쿠폰 발급에 실패하였습니다. 다시 시도해 주세요.');">
카테고리 쿠폰 발급받기
</button>

<script>
function issueCoupon(url, successMessage, errorMessage) {
$.ajax({
url: url,
type: 'POST',
success: function (response) {
$('#couponModal').modal('hide');
},
error: function (error) {
alert(errorMessage);
}
});
}
</script>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
Expand Down Expand Up @@ -247,7 +272,6 @@ <h2>등록된 리뷰가 없습니다.</h2>
indexViewerElement.style.fontSize = '20px';
var descViewerElement = document.querySelector('#descViewer .toastui-editor-contents');
descViewerElement.style.fontSize = '20px';

</script>
</th:block>
</html>

0 comments on commit c17a7a6

Please sign in to comment.