Skip to content

Commit

Permalink
created Order & OrderItem
Browse files Browse the repository at this point in the history
  • Loading branch information
fedorovychh committed Jan 3, 2024
1 parent f54fd36 commit 415c362
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/main/java/com/app/bookstore/model/Order.java
Original file line number Diff line number Diff line change
@@ -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<OrderItem> orderItemSet;
@Column(nullable = false)
private boolean isDeleted = false;

enum Status {
PROCESSING, COMPLETED
}
}
42 changes: 42 additions & 0 deletions src/main/java/com/app/bookstore/model/OrderItem.java
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 415c362

Please sign in to comment.