-
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.
Merge pull request #184 from nhnacademy-be5-T3Team/feature/coupon
마이페이지, 관리자페이지, 상세보기 쿠폰 개발
- Loading branch information
Showing
27 changed files
with
468 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/t3t/bookstoreapi/book/model/response/BookCouponResponse.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.book.model.response; | ||
|
||
import lombok.*; | ||
|
||
@Builder@Getter | ||
@EqualsAndHashCode | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class BookCouponResponse { | ||
private long bookId; | ||
} |
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
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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/t3t/bookstoreapi/category/model/response/CategoryIdResponse.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.category.model.response; | ||
|
||
import lombok.*; | ||
|
||
@Builder | ||
@Getter@ToString | ||
@EqualsAndHashCode | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CategoryIdResponse { | ||
private Integer categoryId; | ||
} |
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
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,9 @@ | ||
package com.t3t.bookstoreapi.config; | ||
|
||
import org.springframework.cloud.openfeign.EnableFeignClients; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@EnableFeignClients(basePackages ="com.t3t.bookstoreapi") | ||
public class FeignConfig { | ||
} |
64 changes: 64 additions & 0 deletions
64
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,64 @@ | ||
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.request.CouponIdRequest; | ||
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(); | ||
} | ||
} | ||
|
||
public void deleteBookCouponServer(CouponIdRequest request){ | ||
try{ | ||
couponApiClient.deleteBookCoupon(request); | ||
}catch (FeignException e){ | ||
throw new CouponApiClientException(); | ||
} | ||
} | ||
|
||
public void deleteCategoryCouponServer(CouponIdRequest request){ | ||
try{ | ||
couponApiClient.deleteCategoryCoupon(request); | ||
}catch (FeignException e){ | ||
throw new CouponApiClientException(); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.t3t.bookstoreapi.coupon.client; | ||
|
||
import com.t3t.bookstoreapi.coupon.model.request.CouponIdRequest; | ||
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; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
@FeignClient(name = "CouponApiClient", url = "${t3t.feignClient.url}") | ||
public interface CouponApiClient { | ||
@GetMapping("/t3t/coupon/coupons/book") | ||
ResponseEntity<BaseResponse<CouponResponse>> getBookCoupon(); | ||
|
||
@GetMapping("/t3t/coupon/coupons/category") | ||
ResponseEntity<BaseResponse<CouponResponse>> getCategoryCoupon(); | ||
|
||
@GetMapping("/t3t/coupon/coupons/general") | ||
ResponseEntity<BaseResponse<CouponResponse>> getGeneralCoupon(); | ||
|
||
@PutMapping("/t3t/coupon/coupons/book") | ||
ResponseEntity<BaseResponse<Void>> deleteBookCoupon(@RequestBody CouponIdRequest request); | ||
|
||
@PutMapping("/t3t/coupon/coupons/category") | ||
ResponseEntity<BaseResponse<Void>> deleteCategoryCoupon(@RequestBody CouponIdRequest request); | ||
} |
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); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/t3t/bookstoreapi/coupon/model/request/CouponIdRequest.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,13 @@ | ||
package com.t3t.bookstoreapi.coupon.model.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CouponIdRequest { | ||
private String couponId; | ||
} |
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; | ||
} |
Oops, something went wrong.