-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f40c451
commit ed860f3
Showing
5 changed files
with
88 additions
and
9 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/main/java/com/t3t/bookstoreapi/coupon/adapter/CouponAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.t3t.bookstoreapi.coupon.adapter; | ||
|
||
import com.t3t.bookstoreapi.coupon.client.CouponApiClient; | ||
import com.t3t.bookstoreapi.coupon.exception.CouponApiClientException; | ||
import com.t3t.bookstoreapi.coupon.model.response.CouponResponse; | ||
import com.t3t.bookstoreapi.model.response.BaseResponse; | ||
import feign.FeignException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Optional; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class CouponAdapter { | ||
private final CouponApiClient couponApiClient; | ||
|
||
public CouponResponse getGeneralCoupon(){ | ||
try{ | ||
return Optional.ofNullable(couponApiClient.getGeneralCoupon().getBody()) | ||
.map(BaseResponse::getData) | ||
.orElseThrow(CouponApiClientException::new); | ||
}catch (FeignException e){ | ||
throw new CouponApiClientException(); | ||
} | ||
} | ||
|
||
public CouponResponse getBookCoupon(){ | ||
try{ | ||
return Optional.ofNullable(couponApiClient.getBookCoupon().getBody()) | ||
.map(BaseResponse::getData) | ||
.orElseThrow(CouponApiClientException::new); | ||
}catch (FeignException e){ | ||
throw new CouponApiClientException(); | ||
} | ||
} | ||
|
||
public CouponResponse getCategoryCOupon(){ | ||
try{ | ||
return Optional.ofNullable(couponApiClient.getCategoryCoupon().getBody()) | ||
.map(BaseResponse::getData) | ||
.orElseThrow(CouponApiClientException::new); | ||
}catch (FeignException e){ | ||
throw new CouponApiClientException(); | ||
} | ||
} | ||
} |
19 changes: 10 additions & 9 deletions
19
src/main/java/com/t3t/bookstoreapi/coupon/client/CouponApiClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
package com.t3t.bookstoreapi.coupon.client; | ||
|
||
import com.t3t.bookstoreapi.coupon.model.response.CouponResponse; | ||
import com.t3t.bookstoreapi.model.response.BaseResponse; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
@FeignClient(name = "CouponApiClient", url = "${t3t.feignClient.url}") | ||
public interface CouponApiClient { | ||
/*@GetMapping(value = "/t3t/coupon/categories/coupons") | ||
ResponseEntity<BaseResponse<List<CategoryIdResponse>>> getCategoriesId(); | ||
@GetMapping("/t3t/coupon/coupons/book") | ||
ResponseEntity<BaseResponse<CouponResponse>> getBookCoupon(); | ||
|
||
@GetMapping(value = "/t3t/bookstore/categories/{categoryId}/coupons") | ||
ResponseEntity<BaseResponse<CategoryIdResponse>> getCategoryId(@PathVariable("categoryId") Integer categoryId);*/ | ||
@GetMapping("/t3t/coupon/coupons/category") | ||
ResponseEntity<BaseResponse<CouponResponse>> getCategoryCoupon(); | ||
|
||
//todo 1 ) Gateway에서 쿠폰 등록 | ||
|
||
// todo 2 ) book coupon, category coupon, general coupon FeignClient 이용해 가져오기 | ||
|
||
// todo 3 ) 가져온 것 db에 넣어놓기 | ||
@GetMapping("/t3t/coupon/coupons/general") | ||
ResponseEntity<BaseResponse<CouponResponse>> getGeneralCoupon(); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/t3t/bookstoreapi/coupon/exception/CouponApiClientException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.t3t.bookstoreapi.coupon.exception; | ||
|
||
public class CouponApiClientException extends RuntimeException{ | ||
private static final String DEFAULT_MESSAGES = "쿠폰을 가져오지 못했습니다"; | ||
public CouponApiClientException(String message) { | ||
super(message); | ||
} | ||
public CouponApiClientException(){ | ||
super(DEFAULT_MESSAGES); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/t3t/bookstoreapi/coupon/model/response/CouponResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.t3t.bookstoreapi.coupon.model.response; | ||
|
||
import lombok.*; | ||
|
||
@Builder | ||
@Getter@ToString | ||
@EqualsAndHashCode | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CouponResponse { | ||
private String couponId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters