diff --git a/src/main/java/com/app/bookstore/model/Order.java b/src/main/java/com/app/bookstore/model/Order.java new file mode 100644 index 0000000..2aa4396 --- /dev/null +++ b/src/main/java/com/app/bookstore/model/Order.java @@ -0,0 +1,55 @@ +package com.app.bookstore.model; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.Set; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; + +@Entity +@Data +@SQLDelete(sql = "UPDATE orders SET is_deleted = true WHERE id=?") +@Where(clause = "is_deleted=false") +@Table(name = "orders") +public class Order { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @ManyToOne + @ToString.Exclude + @EqualsAndHashCode.Exclude + @JoinColumn(name = "user_id", nullable = false) + private User user; + @Enumerated(EnumType.STRING) + private Status status; + @Column(nullable = false) + private BigDecimal total; + @CreationTimestamp + private LocalDateTime orderDate; + private String shippingAddress; + @OneToMany(mappedBy = "order") + @ToString.Exclude + @EqualsAndHashCode.Exclude + private Set orderItemSet; + @Column(nullable = false) + private boolean isDeleted = false; + + enum Status { + PROCESSING, COMPLETED + } +} diff --git a/src/main/java/com/app/bookstore/model/OrderItem.java b/src/main/java/com/app/bookstore/model/OrderItem.java new file mode 100644 index 0000000..135c70b --- /dev/null +++ b/src/main/java/com/app/bookstore/model/OrderItem.java @@ -0,0 +1,42 @@ +package com.app.bookstore.model; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; + +import java.math.BigDecimal; + +@Entity +@Data +@SQLDelete(sql = "UPDATE order_items SET is_deleted = true WHERE id=?") +@Where(clause = "is_deleted=false") +@Table(name = "order_items") +public class OrderItem { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @ManyToOne + @ToString.Exclude + @EqualsAndHashCode.Exclude + @JoinColumn(name = "order_id", nullable = false) + private Order order; + @ManyToOne + @ToString.Exclude + @EqualsAndHashCode.Exclude + @JoinColumn(name = "book_id", nullable = false) + private Book book; + private int quantity; + private BigDecimal price; + @Column(nullable = false) + private boolean isDeleted = false; +}