-
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 #113 from feature/order 결제, 주문 및 장바구니
- Loading branch information
Showing
38 changed files
with
2,054 additions
and
231 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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/t3t/frontserver/book/exception/BookApiClientException.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.frontserver.book.exception; | ||
|
||
/** | ||
* BookApiClient 로 도서 관련 API 호출 실패시 발생하는 예외 | ||
* | ||
* @author woody35545(구건모) | ||
*/ | ||
public class BookApiClientException extends RuntimeException { | ||
public BookApiClientException(String message) { | ||
super(message); | ||
} | ||
} |
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,48 @@ | ||
package com.t3t.frontserver.config; | ||
|
||
import com.t3t.frontserver.property.RedisProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
|
||
@Configuration | ||
@EnableRedisRepositories | ||
public class RedisConfig { | ||
|
||
/** | ||
* RedisConnectionFactory 빈 설정 | ||
* | ||
* @author woody35545(구건모) | ||
*/ | ||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory(RedisProperties redisProperties) { | ||
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); | ||
redisStandaloneConfiguration.setHostName(redisProperties.getRedisServerIpAddress()); | ||
redisStandaloneConfiguration.setPort(Integer.parseInt(redisProperties.getRedisServerPort())); | ||
redisStandaloneConfiguration.setPassword(redisProperties.getRedisServerPassword()); | ||
redisStandaloneConfiguration.setDatabase(redisProperties.getRedisDatabase()); | ||
System.out.println("redisProperties.getRedisServerIpAddress() = " + redisProperties.getRedisServerIpAddress()); | ||
return new LettuceConnectionFactory(redisStandaloneConfiguration); | ||
} | ||
|
||
/** | ||
* RedisTemplate 빈 설정 | ||
* | ||
* @author woody35545(구건모) | ||
*/ | ||
@Bean | ||
public RedisTemplate<String, String> redisTemplate(RedisProperties redisProperties) { | ||
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>(); | ||
redisTemplate.setConnectionFactory(redisConnectionFactory(redisProperties)); | ||
redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
redisTemplate.setValueSerializer(new StringRedisSerializer()); | ||
return redisTemplate; | ||
} | ||
|
||
} |
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
69 changes: 69 additions & 0 deletions
69
src/main/java/com/t3t/frontserver/order/adaptor/OrderAdaptor.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,69 @@ | ||
package com.t3t.frontserver.order.adaptor; | ||
|
||
import com.t3t.frontserver.model.response.BaseResponse; | ||
import com.t3t.frontserver.model.response.PageResponse; | ||
import com.t3t.frontserver.order.client.OrderApiClient; | ||
import com.t3t.frontserver.order.exception.OrderApiClientException; | ||
import com.t3t.frontserver.order.model.request.MemberOrderPreparationRequest; | ||
import com.t3t.frontserver.order.model.request.OrderConfirmRequest; | ||
import com.t3t.frontserver.order.model.response.MemberOrderPreparationResponse; | ||
import com.t3t.frontserver.order.model.response.OrderInfoResponse; | ||
import com.t3t.frontserver.util.FeignClientUtils; | ||
import feign.FeignException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Optional; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class OrderAdaptor { | ||
private final OrderApiClient orderApiClient; | ||
|
||
/** | ||
* 회원 주문 생성 | ||
* 결제 대기 상태의 주문을 생성한다. | ||
* | ||
* @author woody35545(구건모) | ||
*/ | ||
public MemberOrderPreparationResponse createMemberOrder(MemberOrderPreparationRequest request) { | ||
try { | ||
return Optional.ofNullable(orderApiClient.createMemberOrder(request).getBody()) | ||
.map(BaseResponse::getData) | ||
.orElseThrow(RuntimeException::new); | ||
} catch (FeignException e) { | ||
throw new OrderApiClientException("주문 생성에 실패하였습니다. " + FeignClientUtils.getMessageFromFeignException(e)); | ||
} | ||
} | ||
|
||
/** | ||
* 주문에 대한 결제 검증 및 주문 승인 | ||
* | ||
* @author woody35545(구건모) | ||
*/ | ||
public void confirmOrder(OrderConfirmRequest request) { | ||
try { | ||
orderApiClient.confirmOrder(request); | ||
} catch (FeignException e) { | ||
throw new OrderApiClientException("주문에 대한 결제 검증에 실패하였습니다. " + FeignClientUtils.getMessageFromFeignException(e)); | ||
} | ||
} | ||
|
||
/** | ||
* 특정 회원의 모든 주문 관련 정보를 페이징을 통해 조회 | ||
* | ||
* @author woody35545(구건모) | ||
*/ | ||
public PageResponse<OrderInfoResponse> getMemberOrderInfoListByMemberId(Long memberId, Pageable pageable) { | ||
try { | ||
return Optional.ofNullable(orderApiClient.getMemberOrderInfoListByMemberId(memberId, pageable).getBody()) | ||
.map(BaseResponse::getData) | ||
.orElseThrow(RuntimeException::new); | ||
} catch (FeignException e) { | ||
throw new OrderApiClientException("주문 정보 조회에 실패하였습니다. " + FeignClientUtils.getMessageFromFeignException(e)); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/t3t/frontserver/order/client/OrderApiClient.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,44 @@ | ||
package com.t3t.frontserver.order.client; | ||
|
||
import com.t3t.frontserver.model.response.BaseResponse; | ||
import com.t3t.frontserver.model.response.PageResponse; | ||
import com.t3t.frontserver.order.model.request.MemberOrderPreparationRequest; | ||
import com.t3t.frontserver.order.model.request.OrderConfirmRequest; | ||
import com.t3t.frontserver.order.model.response.MemberOrderPreparationResponse; | ||
import com.t3t.frontserver.order.model.response.OrderInfoResponse; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@FeignClient(name = "OrderApiClient", url = "${t3t.feignClient.url}") | ||
public interface OrderApiClient { | ||
|
||
/** | ||
* 회원 주문 생성 API<br> | ||
* 결제 대기 상태의 주문을 생성한다. | ||
* | ||
* @author woody35545(구건모) | ||
*/ | ||
@PostMapping(value = "/t3t/bookstore/orders/member") | ||
ResponseEntity<BaseResponse<MemberOrderPreparationResponse>> createMemberOrder(@RequestBody MemberOrderPreparationRequest memberOrderPreparationRequest); | ||
|
||
|
||
/** | ||
* 주문에 대한 결제 검증 및 주문 승인 API | ||
* | ||
* @author woody35545(구건모) | ||
*/ | ||
@PostMapping("/t3t/bookstore/orders/confirm") | ||
ResponseEntity<BaseResponse<Void>> confirmOrder(@RequestBody OrderConfirmRequest orderConfirmRequest); | ||
|
||
/** | ||
* 특정 회원의 모든 주문 관련 정보를 페이징을 통해 조회 | ||
* | ||
* @author woody35545(구건모) | ||
*/ | ||
@GetMapping("/t3t/bookstore/members/{memberId}/orders") | ||
ResponseEntity<BaseResponse<PageResponse<OrderInfoResponse>>> getMemberOrderInfoListByMemberId(@PathVariable("memberId") Long memberId, Pageable pageable); | ||
} |
Oops, something went wrong.