Skip to content

Commit

Permalink
#1198-update-the-order-checkout-payment-tables
Browse files Browse the repository at this point in the history
  • Loading branch information
nashtech-tuannguyenhuu1 committed Oct 21, 2024
1 parent c09fd0b commit ca85e39
Show file tree
Hide file tree
Showing 16 changed files with 446 additions and 56 deletions.
6 changes: 2 additions & 4 deletions order/src/main/java/com/yas/order/mapper/CheckoutMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
@Component
public interface CheckoutMapper {
@Mapping(target = "id", ignore = true)
@Mapping(target = "checkoutId", ignore = true)
@Mapping(target = "checkout", ignore = true)
CheckoutItem toModel(CheckoutItemPostVm checkoutItemPostVm);

@Mapping(target = "id", ignore = true)
@Mapping(target = "checkoutState", ignore = true)
@Mapping(target = "checkoutItem", source = "checkoutItemPostVms")
Checkout toModel(CheckoutPostVm checkoutPostVm);

@Mapping(target = "checkoutId", source = "checkoutId.id")
CheckoutItemVm toVm(CheckoutItem checkoutItem);

@Mapping(target = "checkoutItemVms", source = "checkoutItem")
@Mapping(target = "checkoutItemVms", ignore = true)
CheckoutVm toVm(Checkout checkout);
}
56 changes: 50 additions & 6 deletions order/src/main/java/com/yas/order/model/Checkout.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.yas.order.model;

import com.yas.order.model.enumeration.CheckoutState;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.Set;
import java.math.BigDecimal;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

@Entity
@Table(name = "checkout")
Expand All @@ -24,15 +24,59 @@
@AllArgsConstructor
@Builder
public class Checkout extends AbstractAuditEntity {

@Id
private String id;

private String email;

private String note;

@Column(name = "promotion_code")
private String couponCode;

@Column(name = "status")
@Enumerated(EnumType.STRING)
private CheckoutState checkoutState;

@OneToMany(mappedBy = "checkoutId", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private Set<CheckoutItem> checkoutItem;
@SuppressWarnings("unused")
private String progress;

@SuppressWarnings("unused")
private Long customerId;

@SuppressWarnings("unused")
private String shipmentMethodId;

@SuppressWarnings("unused")
private String paymentMethodId;

@SuppressWarnings("unused")
private Long shippingAddressId;

@SuppressWarnings("unused")
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "last_error", columnDefinition = "jsonb")
private String lastError;

@SuppressWarnings("unused")
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "attributes", columnDefinition = "jsonb")
private String attributes;

@SuppressWarnings("unused")
private BigDecimal totalAmount;

@SuppressWarnings("unused")
private BigDecimal totalShipmentFee;

@SuppressWarnings("unused")
private BigDecimal totalShipmentTax;

@SuppressWarnings("unused")
private BigDecimal totalTax;

@SuppressWarnings("unused")
private BigDecimal totalDiscountAmount;

}
33 changes: 29 additions & 4 deletions order/src/main/java/com/yas/order/model/CheckoutItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yas.order.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
Expand All @@ -22,19 +23,43 @@
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class CheckoutItem {
public class CheckoutItem extends AbstractAuditEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private Long productId;

@Column(name = "checkout_id")
private String checkoutId;

@Column(name = "name")
private String productName;

private int quantity;

@Column(name = "price")
private BigDecimal productPrice;

@Column(name = "description")
private String note;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "checkout_id", insertable = false, updatable = false)
private Checkout checkout;

private BigDecimal discountAmount;

@Column(name = "tax")
private BigDecimal taxAmount;

private BigDecimal taxPercent;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "checkoutId", referencedColumnName = "id")
private Checkout checkoutId;

@SuppressWarnings("unused")
private BigDecimal shipmentTax;

@SuppressWarnings("unused")
private BigDecimal shipmentFee;

}
52 changes: 52 additions & 0 deletions order/src/main/java/com/yas/order/model/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.yas.order.model.enumeration.OrderStatus;
import com.yas.order.model.enumeration.PaymentStatus;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
Expand All @@ -24,6 +25,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

@Entity
@Table(name = "`order`")
Expand All @@ -33,35 +36,84 @@
@AllArgsConstructor
@Builder
public class Order extends AbstractAuditEntity {

@OneToMany(mappedBy = "orderId", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
Set<OrderItem> orderItems;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String email;

@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "shipping_address_id", referencedColumnName = "id")
private OrderAddress shippingAddressId;

@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "billing_address_id", referencedColumnName = "id")
private OrderAddress billingAddressId;

private String note;

@Column(name = "total_tax")
private float tax;

@Column(name = "total_discount_amount")
private float discount;

private int numberItem;

@Column(name = "promotion_code")
private String couponCode;

@Column(name = "total_amount")
private BigDecimal totalPrice;

@Column(name = "total_shipment_fee")
private BigDecimal deliveryFee;
@Enumerated(EnumType.STRING)

@Column(name = "status")
private OrderStatus orderStatus;

@Column(name = "shipment_method_id")
@Enumerated(EnumType.STRING)
private DeliveryMethod deliveryMethod;

@Column(name = "shipment_status")
@Enumerated(EnumType.STRING)
private DeliveryStatus deliveryStatus;

@Enumerated(EnumType.STRING)
private PaymentStatus paymentStatus;

private Long paymentId;

private String checkoutId;

private String rejectReason;

@SuppressWarnings("unused")
private String paymentMethodId;

@SuppressWarnings("unused")
private String progress;

@SuppressWarnings("unused")
private Long customerId;

@SuppressWarnings("unused")
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "last_error", columnDefinition = "jsonb")
private String lastError;

@SuppressWarnings("unused")
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "attributes", columnDefinition = "jsonb")
private String attributes;

@SuppressWarnings("unused")
private BigDecimal totalShipmentTax;

}
31 changes: 30 additions & 1 deletion order/src/main/java/com/yas/order/model/OrderItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yas.order.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
Expand All @@ -14,6 +15,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

@Entity
@Table(name = "order_item")
Expand All @@ -22,19 +25,45 @@
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class OrderItem {
public class OrderItem extends AbstractAuditEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private Long productId;

@Column(name = "name")
private String productName;

private int quantity;

@Column(name = "price")
private BigDecimal productPrice;

@Column(name = "description")
private String note;

private BigDecimal discountAmount;

private BigDecimal taxAmount;

private BigDecimal taxPercent;

@SuppressWarnings("unused")
private BigDecimal shipmentFee;

@SuppressWarnings("unused")
private String status;

@SuppressWarnings("unused")
private BigDecimal shipmentTax;

@SuppressWarnings("unused")
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "processing_state", columnDefinition = "jsonb")
private String processingState;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "orderId", referencedColumnName = "id")
private Order orderId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.yas.order.repository;

import com.yas.order.model.CheckoutItem;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface CheckoutItemRepository extends JpaRepository<CheckoutItem, Long> {

List<CheckoutItem> findAllByCheckoutId(String checkoutId);
}
Loading

0 comments on commit ca85e39

Please sign in to comment.