-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f54fd36
commit 415c362
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |