MCPcopy Create free account
hub / github.com/Fernanda-Kipper/orderhub / Order

Class Order

src/main/java/com/kipperdev/orderhub/entity/Order.java:14–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12import java.util.List;
13
14@Entity
15@Table(name = "orders")
16@Data
17@NoArgsConstructor
18@AllArgsConstructor
19public class Order {
20
21 @Id
22 @GeneratedValue(strategy = GenerationType.IDENTITY)
23 private Long id;
24
25 @NotNull(message = "Cliente é obrigatório")
26 @ManyToOne(fetch = FetchType.LAZY)
27 @JoinColumn(name = "customer_id", nullable = false)
28 private Customer customer;
29
30 @Enumerated(EnumType.STRING)
31 @Column(nullable = false)
32 private OrderStatus status;
33
34 @DecimalMin(value = "0.01", message = "Valor total deve ser maior que zero")
35 @Column(name = "total_amount", nullable = false, precision = 10, scale = 2)
36 private BigDecimal totalAmount;
37
38 @Column(name = "payment_method")
39 private String paymentMethod;
40
41 @Column(name = "abacate_transaction_id")
42 private String abacateTransactionId;
43
44 @Column(name = "payment_link")
45 private String paymentLink;
46
47 @Column(name = "created_at", nullable = false)
48 private LocalDateTime createdAt;
49
50 @Column(name = "updated_at")
51 private LocalDateTime updatedAt;
52
53 @Column(name = "paid_at")
54 private LocalDateTime paidAt;
55
56 @OneToMany(mappedBy = "order", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
57 private List<OrderItem> items;
58
59 @PrePersist
60 protected void onCreate() {
61 createdAt = LocalDateTime.now();
62 updatedAt = LocalDateTime.now();
63 if (status == null) {
64 status = OrderStatus.PENDING_PAYMENT;
65 }
66 }
67
68 @PreUpdate
69 protected void onUpdate() {
70 updatedAt = LocalDateTime.now();
71 if (status == OrderStatus.PAID && paidAt == null) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected