Skip to content

Commit

Permalink
fix: 주문 응답으로 새로운 매핑 객체 생성 (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
hwibaski authored Jul 26, 2023
1 parent 475975d commit 0ae86f6
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 75 deletions.
62 changes: 26 additions & 36 deletions common/src/main/java/org/example/entity/OrderItem.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
package org.example.entity;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

import io.hypersistence.utils.hibernate.type.json.JsonType;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.example.config.PostgreSQLEnumType;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

import io.hypersistence.utils.hibernate.type.json.JsonType;
import lombok.Getter;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
@Entity
@TypeDef(name = "json", typeClass = JsonType.class)
@TypeDef(name = "psql_enum", typeClass = PostgreSQLEnumType.class)
Expand Down Expand Up @@ -113,13 +103,13 @@ public class OrderItem {
private Coupon coupons;

public OrderItem(Product product, Long orderItemTotalPaymentAmount, Long orderQuantity,
Long orderItemTotalAmount, Long productDiscountAmount, LocalDateTime orderStatusDate,
OrderStatus orderStatus, Long deliveryFee, Long baseShippingFee, Long jejuShippingFee,
Long islandShippingFee, Long originJejuShippingFee, Long originIslandShippingFee,
Long originBaseShippingFee, Long conditionalFreeDeliveryFeeStandardByShop,
boolean isAcceptedConditionalFreeDeliveryFee,
Long originalDeliveryFeeBeforeDeliveryDiscount, Shop shop,
ProductOption userSelectOption) {
Long orderItemTotalAmount, Long productDiscountAmount, LocalDateTime orderStatusDate,
OrderStatus orderStatus, Long deliveryFee, Long baseShippingFee, Long jejuShippingFee,
Long islandShippingFee, Long originJejuShippingFee, Long originIslandShippingFee,
Long originBaseShippingFee, Long conditionalFreeDeliveryFeeStandardByShop,
boolean isAcceptedConditionalFreeDeliveryFee,
Long originalDeliveryFeeBeforeDeliveryDiscount, Shop shop,
ProductOption userSelectOption) {
this.product = product;
this.orderItemTotalPaymentAmount = orderItemTotalPaymentAmount;
this.orderQuantity = orderQuantity;
Expand All @@ -146,14 +136,14 @@ public OrderItem(Product product, Long orderItemTotalPaymentAmount, Long orderQu
public Map<String, Object> getOrderItemOption(ProductOption productOption, long orderQuantity) {
if (productOption != null) {
return Map.of("optionId", productOption.getOptionId(),
"optionName1", productOption.getOptionName1(),
"optionValue1", productOption.getOptionValue1(),
"optionName2", productOption.getOptionName2(),
"optionValue2", productOption.getOptionValue2(),
"optionName3", productOption.getOptionName3(),
"optionValue3", productOption.getOptionValue3(),
"optionPrice", productOption.getOptionPrice(),
"orderQuantity", orderQuantity
"optionName1", productOption.getOptionName1(),
"optionValue1", productOption.getOptionValue1(),
"optionName2", productOption.getOptionName2(),
"optionValue2", productOption.getOptionValue2(),
"optionName3", productOption.getOptionName3(),
"optionValue3", productOption.getOptionValue3(),
"optionPrice", productOption.getOptionPrice(),
"orderQuantity", orderQuantity
);
} else {
return Map.of("orderQuantity", orderQuantity);
Expand Down Expand Up @@ -181,7 +171,7 @@ public void setAcceptedConditionalFreeDeliveryFee(boolean acceptedConditionalFre
}

public void setAcceptedConditionalFreeDeliveryFeeWhenOrder(
boolean acceptedConditionalFreeDeliveryFeeWhenOrder) {
boolean acceptedConditionalFreeDeliveryFeeWhenOrder) {
isAcceptedConditionalFreeDeliveryFeeWhenOrder = acceptedConditionalFreeDeliveryFeeWhenOrder;
}

Expand Down Expand Up @@ -218,6 +208,6 @@ public void setOrderStatusToComplete() {
}

public Long getOptionId() {
return (Long)this.options.get("optionId");
return (Long) this.options.get("optionId");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,17 @@
public class CreateMemberOrderResponseDto {

private boolean ok;
private Order results;
private OrderResponse results;
private boolean isZeroPaidOrder;

public CreateMemberOrderResponseDto(boolean ok, Order results, boolean isZeroPaidOrder) {
public CreateMemberOrderResponseDto(boolean ok, Order order, boolean isZeroPaidOrder) {
this.ok = ok;
this.results = results;
this.results = this.toDto(order);
this.isZeroPaidOrder = isZeroPaidOrder;
}

@Override
public String toString() {
return "CreateMemberOrderOutputDTO{" +
"ok=" + ok +
", results=" + results +
", isZeroPaidOrder=" + isZeroPaidOrder +
'}';
private OrderResponse toDto(Order order) {
return new OrderResponse(order);
}
}

95 changes: 95 additions & 0 deletions web/src/main/java/org/example/dto/OrderResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.example.dto;

import lombok.Getter;
import lombok.Setter;
import org.example.entity.DeliveryType;
import org.example.entity.Order;
import org.example.entity.OrderCustomerType;
import org.example.entity.PaymentMethod;

import java.time.LocalDateTime;

@Getter
@Setter
public class OrderResponse {
private long id;

private String orderName;

private String orderNumber;

private Long totalOriginalPrice;

private Long totalDiscountPrice;

private Long productDiscountPrice;

private Long pointDiscountPrice;

private Long couponDiscountPrice;

private Long deliveryFee;

private PaymentMethod paymentMethod;

private OrderCustomerType orderCustomerType;

private DeliveryType deliveryType;

private String refundBankAccount;

private String refundAccountBankName;

private String refundAccountHolder;

private String deliveryMessage;

private String deliveryPhoneNumber;

private String receiver;

private String streetAddress;

private String detailAddress;

private String zipCode;

private LocalDateTime paymentDate;

private String customerEmail;

private String customerName;

private String customerPhoneNumber;

private String customerPersonalCustomsCode;


public OrderResponse(Order order) {
this.id = order.getId();
this.orderName = order.getOrderName();
this.orderNumber = order.getOrderNumber();
this.totalOriginalPrice = order.getTotalOriginalPrice();
this.totalDiscountPrice = order.getTotalDiscountPrice();
this.productDiscountPrice = order.getProductDiscountPrice();
this.pointDiscountPrice = order.getPointDiscountPrice();
this.couponDiscountPrice = order.getCouponDiscountPrice();
this.deliveryFee = order.getDeliveryFee();
this.paymentMethod = order.getPaymentMethod();
this.orderCustomerType = order.getOrderCustomerType();
this.deliveryType = order.getDeliveryType();
this.refundBankAccount = order.getRefundBankAccount();
this.refundAccountBankName = order.getRefundAccountBankName();
this.refundAccountHolder = order.getRefundAccountHolder();
this.deliveryMessage = order.getDeliveryMessage();
this.deliveryPhoneNumber = order.getDeliveryPhoneNumber();
this.receiver = order.getReceiver();
this.streetAddress = order.getStreetAddress();
this.detailAddress = order.getDetailAddress();
this.paymentDate = order.getPaymentDate();
this.customerEmail = order.getCustomerEmail();
this.customerName = order.getCustomerName();
this.customerPhoneNumber = order.getCustomerPhoneNumber();
this.customerPersonalCustomsCode = order.getCustomerPersonalCustomsCode();
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package org.example.interceptor;

import java.util.Collections;

import org.springframework.context.annotation.Configuration;
import org.springframework.graphql.server.WebGraphQlInterceptor;
import org.springframework.graphql.server.WebGraphQlRequest;
import org.springframework.graphql.server.WebGraphQlResponse;

import reactor.core.publisher.Mono;

import java.util.Collections;

@Configuration
public class RequestHeaderInterceptor implements WebGraphQlInterceptor {
@Override
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
String value = request.getHeaders().getFirst("x-jwt");

if (value == null) {
return chain.next(request);
}

request.configureExecutionInput((executionInput, builder) ->
builder.graphQLContext(Collections.singletonMap("x-jwt", value)).build());
builder.graphQLContext(Collections.singletonMap("x-jwt", value)).build());

return chain.next(request);
}
Expand Down
8 changes: 7 additions & 1 deletion web/src/main/java/org/example/resolver/OrderResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.ContextValue;
import org.springframework.graphql.data.method.annotation.MutationMapping;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.stereotype.Controller;

@Controller
Expand All @@ -27,7 +28,7 @@ public class OrderResolver {
public CreateMemberOrderResponseDto createMemberOrderV3(
@Argument("input") CreateMemberOrderRequestDto requestDto,
@ContextValue(name = "x-jwt") String jwtAccessToken) throws Exception {
if (!this.jwtService.verifyToken(jwtAccessToken)) {
if (jwtAccessToken != null && !this.jwtService.verifyToken(jwtAccessToken)) {
throw new GraphqlException("403 FORBIDDEN");
}

Expand All @@ -45,4 +46,9 @@ public CreateMemberOrderResponseDto createMemberOrderV3(

return new CreateMemberOrderResponseDto(true, newOrder, false);
}

@QueryMapping
public String healthCheck() {
return "hello";
}
}
12 changes: 0 additions & 12 deletions web/src/main/resources/graphql/output.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,3 @@ type CreateOrderV3Output {
results: Order
isZeroPaidOrder: Boolean
}

type MemberOrderOutput {
error: String
ok: Boolean!
results: OrderInfo
}

type ConfirmMemberOrderOutput {
error: String
ok: Boolean!
results: Boolean
}
3 changes: 1 addition & 2 deletions web/src/main/resources/graphql/schema.graphqls
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
type Mutation {
createMemberOrderV3(input: CreateOrderV3Input!): CreateOrderV3Output!
confirmMemberOrder(input: ConfirmMemberOrderInput!): ConfirmMemberOrderOutput!
}

type Query {
order(input: MemberOrderInput!): MemberOrderOutput!
healthCheck: String!
}

scalar DateTime
10 changes: 0 additions & 10 deletions web/src/main/resources/graphql/type.graphqls
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
type OrderInfo {
order: Order
payment: Payment
}

type Order {
id: Int!
createdAt: DateTime!
updatedAt: DateTime!
orderNumber: String!
customer: User
items: [OrderItem!]!
totalOriginalPrice: Int!
totalDiscountPrice: Int!
productDiscountPrice: Int
pointDiscountPrice: Int
couponDiscountPrice: Int
deliveryFee: Int!
user: User
product: [Product!]
shop: Shop
orderItemVat: Int
finalPrice: Int
finalPurchasePrice: Int
Expand Down

0 comments on commit 0ae86f6

Please sign in to comment.