Skip to content

Commit

Permalink
Merge pull request #21 from code-review-platform-flow/feat/change-struct
Browse files Browse the repository at this point in the history
feat: db 구조 변경에 의한 수정
  • Loading branch information
abwarten authored Aug 5, 2024
2 parents 622657f + 900497c commit 29aeb91
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 76 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/flow/payment/dto/order/OrdersDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class OrdersDto {

private Long orderId;
private Long userId;
private Long coffeeId;
private UUID tossOrderId;
private UUID customerKey;
private LocalDateTime orderDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@AllArgsConstructor
public class OrdersRequestDto {

private String email;
private Long coffeeId;
private BigDecimal totalAmount;

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@NoArgsConstructor
@AllArgsConstructor
public class OrdersResponseDto {
private Long orderId;
private UUID customerKey;
private String tossOrderId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class PaymentsConfirmRequestDto {

private String paymentKey;

@JsonProperty("orderId")
@JsonProperty("tossOrderId")
private String tossOrderId;

}
4 changes: 2 additions & 2 deletions src/main/java/com/flow/payment/entity/OrdersEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class OrdersEntity extends BaseEntity {
@Column(name = "order_id")
private Long orderId;

@Column(name = "user_id", nullable = false)
private Long userId;
@Column(name = "coffee_id", nullable = false)
private Long coffeeId;

@Column(name = "toss_order_id", nullable = false)
private UUID tossOrderId;
Expand Down
52 changes: 0 additions & 52 deletions src/main/java/com/flow/payment/entity/PaymentLogsEntity.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/com/flow/payment/mapper/OrdersMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
@Mapper(componentModel = "spring", imports = {LocalDateTime.class, UUID.class})
public interface OrdersMapper extends GenericMapper<OrdersDto, OrdersEntity> {

@Mapping(target = "userId", source = "user.userId")
@Mapping(target = "coffeeId", source = "coffeeId")
@Mapping(target = "orderDate", expression = "java(LocalDateTime.now())")
@Mapping(target = "tossOrderId", expression = "java(UUID.randomUUID())")
@Mapping(target = "customerKey", expression = "java(UUID.randomUUID())")
@Mapping(target = "status", constant = "주문서 생성")
OrdersDto toOrdersDto(OrdersRequestDto ordersRequestDto, UsersDto user);
OrdersDto toOrdersDto(OrdersRequestDto ordersRequestDto);

OrdersResponseDto toOrdersResponseDto(OrdersDto savedOrder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ public class OrdersCreateService {
private final OrdersService ordersService;
private final OrdersMapper ordersMapper;


public OrdersResponseDto create(OrdersRequestDto ordersRequestDto) {
// 사용자 정보를 이메일로 찾기
UsersDto user = usersService.findUsersByEmail(ordersRequestDto.getEmail());

// 주문 정보를 생성 및 저장
OrdersDto newOrder = ordersMapper.toOrdersDto(ordersRequestDto, user);
OrdersDto newOrder = ordersMapper.toOrdersDto(ordersRequestDto);
OrdersDto savedOrder = ordersService.save(newOrder);

// 응답 DTO 생성 및 반환
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ spring:
hibernate:
ddl-auto: none # Hibernate DDL (none, validate, update, create-drop)
show-sql: true
properties:
hibernate:
format_sql: true
dialect: org.hibernate.dialect.PostgreSQLDialect
toss:
payments:
widget-secret-key: ${WIDGET_SECRET_KEY}
16 changes: 10 additions & 6 deletions src/test/java/com/flow/payment/order/OrderControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ public class OrderControllerTest extends ResourceSnippetIntegrationTest {
@Test
@DisplayName("주문 생성 성공")
void createOrderSuccess() throws Exception {
OrdersRequestDto request = OrdersRequestDto.builder().email("[email protected]").totalAmount(
BigDecimal.valueOf(1000)).build();
OrdersRequestDto request = OrdersRequestDto.builder()
.coffeeId(1L)
.totalAmount(BigDecimal.valueOf(1000)).build();
OrdersResponseDto response = OrdersResponseDto.builder()
.orderId(1L)
.customerKey(UUID.randomUUID())
.tossOrderId(UUID.randomUUID().toString())
.build();
Expand All @@ -55,10 +57,11 @@ void createOrderSuccess() throws Exception {
.requestSchema(Schema.schema("주문 생성 요청"))
.responseSchema(Schema.schema("주문 생성 응답"))
.requestFields(
fieldWithPath("email").description("이메일"),
fieldWithPath("coffeeId").description("커피챗 ID"),
fieldWithPath("totalAmount").description("총 금액")
)
.responseFields(
fieldWithPath("orderId").description("주문서 번호"),
fieldWithPath("customerKey").description("고객 번호 (UUID)"),
fieldWithPath("tossOrderId").description("토스 주문 번호 (UUID)")
)
Expand All @@ -69,8 +72,9 @@ void createOrderSuccess() throws Exception {
@Test
@DisplayName("주문 생성 실패")
void createOrderFailByEmail() throws Exception {
OrdersRequestDto request = OrdersRequestDto.builder().email("[email protected]").totalAmount(
BigDecimal.valueOf(1000)).build();
OrdersRequestDto request = OrdersRequestDto.builder()
.coffeeId(1L)
.totalAmount(BigDecimal.valueOf(1000)).build();

given(ordersCreateService.create(request)).willThrow(new CustomNotFoundException());

Expand All @@ -90,7 +94,7 @@ void createOrderFailByEmail() throws Exception {
.requestSchema(Schema.schema("주문 생성 요청"))
.responseSchema(Schema.schema("주문 생성 응답"))
.requestFields(
fieldWithPath("email").description("이메일"),
fieldWithPath("coffeeId").description("커피챗 ID"),
fieldWithPath("totalAmount").description("총 금액")
)
.responseFields()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void paymentSuccess() throws Exception {
.requestFields(
fieldWithPath("paymentKey").description("paymentKey"),
fieldWithPath("amount").description("총 금액"),
fieldWithPath("orderId").description("토스 주문 번호 (UUID)")
fieldWithPath("tossOrderId").description("토스 주문 번호 (UUID)")
)
.responseFields()
.build()
Expand Down Expand Up @@ -106,7 +106,7 @@ void paymentFail() throws Exception {
.requestFields(
fieldWithPath("paymentKey").description("paymentKey"),
fieldWithPath("amount").description("총 금액"),
fieldWithPath("orderId").description("토스 주문 번호 (UUID)")
fieldWithPath("tossOrderId").description("토스 주문 번호 (UUID)")
)
.responseFields()
.build()
Expand Down

0 comments on commit 29aeb91

Please sign in to comment.