Skip to content

Commit

Permalink
Added exclude constraint for EqualsAndHashcode and ToString annotatio…
Browse files Browse the repository at this point in the history
…ns. Added @CreationTimestamp for orderDate in Order entity.
  • Loading branch information
nklimovych committed May 25, 2024
1 parent d453ae6 commit 521d6d6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/main/java/mate/academy/bookstore/model/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;

@Getter
@Setter
@EqualsAndHashCode(of = {"id", "title", "author", "isbn", "categories"})
@EqualsAndHashCode(exclude = {"categories"})
@ToString(exclude = {"categories"})
@Entity
@SQLDelete(sql = "UPDATE books SET is_deleted = true WHERE id=?")
@SQLRestriction(value = "is_deleted=false")
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mate/academy/bookstore/model/CartItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

@Getter
@Setter
@EqualsAndHashCode(of = {"id", "shoppingCart", "book"})
@ToString
@EqualsAndHashCode(exclude = {"shoppingCart", "book"})
@ToString(exclude = {"shoppingCart", "book"})
@Entity
@Table(name = "cart_items")
public class CartItem {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mate/academy/bookstore/model/ShoppingCart.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
@Getter
@Setter
@Entity
@EqualsAndHashCode(of = {"id", "user"})
@ToString
@EqualsAndHashCode(exclude = {"user", "cartItems"})
@ToString(exclude = {"user", "cartItems"})
@NoArgsConstructor
@Table(name = "shopping_carts")
public class ShoppingCart {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/mate/academy/bookstore/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

@Getter
@Setter
@EqualsAndHashCode(of = {"id", "email", "firstName", "lastName", "shippingAddress"})
@EqualsAndHashCode(exclude = {"roles"})
@ToString(exclude = {"roles"})
@Entity
@SQLDelete(sql = "UPDATE users SET is_deleted=true WHERE id=?")
@SQLRestriction(value = "is_deleted=false")
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/mate/academy/bookstore/model/order/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
import lombok.Setter;
import lombok.ToString;
import mate.academy.bookstore.model.User;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.SoftDelete;

@Getter
@Setter
@EqualsAndHashCode(of = {"id", "user", "orderDate", "shippingAddress"})
@ToString
@EqualsAndHashCode(exclude = {"user", "orderItems"})
@ToString(exclude = {"user", "orderItems"})
@SoftDelete
@Entity
@Table(name = "orders")
Expand All @@ -47,7 +48,7 @@ public class Order {
@Column(nullable = false)
private BigDecimal total;

@Column(nullable = false)
@CreationTimestamp
private LocalDateTime orderDate;

@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

@Getter
@Setter
@ToString
@EqualsAndHashCode(of = {"id", "order", "book", "price"})
@ToString(exclude = {"order", "book"})
@EqualsAndHashCode(exclude = {"order", "book"})
@SoftDelete
@Entity
@Table(name = "order_items")
Expand All @@ -38,7 +38,7 @@ public class OrderItem {
private Book book;

@Column(nullable = false)
private int quantity;
private Integer quantity;

@Column(nullable = false)
private BigDecimal price;
Expand Down

0 comments on commit 521d6d6

Please sign in to comment.