add coupon cart cartItem entities
This commit is contained in:
155
backend/src/main/java/com/petshop/backend/entity/Cart.java
Normal file
155
backend/src/main/java/com/petshop/backend/entity/Cart.java
Normal file
@@ -0,0 +1,155 @@
|
||||
package com.petshop.backend.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.hibernate.annotations.UpdateTimestamp;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "cart")
|
||||
public class Cart {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long cartId;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "userId", nullable = false)
|
||||
private User user;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "storeId")
|
||||
private StoreLocation store;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "couponId")
|
||||
private Coupon coupon;
|
||||
|
||||
@Column(nullable = false, length = 20)
|
||||
private String cartStatus = "ACTIVE";
|
||||
|
||||
@Column(nullable = false, precision = 10, scale = 2)
|
||||
private BigDecimal subtotalAmount = BigDecimal.ZERO;
|
||||
|
||||
@Column(nullable = false, precision = 10, scale = 2)
|
||||
private BigDecimal discountAmount = BigDecimal.ZERO;
|
||||
|
||||
@Column(nullable = false, precision = 10, scale = 2)
|
||||
private BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
|
||||
@CreationTimestamp
|
||||
@Column(name = "created_at", updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@UpdateTimestamp
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
public Cart() {
|
||||
}
|
||||
|
||||
public Long getCartId() {
|
||||
return cartId;
|
||||
}
|
||||
|
||||
public void setCartId(Long cartId) {
|
||||
this.cartId = cartId;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public StoreLocation getStore() {
|
||||
return store;
|
||||
}
|
||||
|
||||
public void setStore(StoreLocation store) {
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
public Coupon getCoupon() {
|
||||
return coupon;
|
||||
}
|
||||
|
||||
public void setCoupon(Coupon coupon) {
|
||||
this.coupon = coupon;
|
||||
}
|
||||
|
||||
public String getCartStatus() {
|
||||
return cartStatus;
|
||||
}
|
||||
|
||||
public void setCartStatus(String cartStatus) {
|
||||
this.cartStatus = cartStatus;
|
||||
}
|
||||
|
||||
public BigDecimal getSubtotalAmount() {
|
||||
return subtotalAmount;
|
||||
}
|
||||
|
||||
public void setSubtotalAmount(BigDecimal subtotalAmount) {
|
||||
this.subtotalAmount = subtotalAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getDiscountAmount() {
|
||||
return discountAmount;
|
||||
}
|
||||
|
||||
public void setDiscountAmount(BigDecimal discountAmount) {
|
||||
this.discountAmount = discountAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getTotalAmount() {
|
||||
return totalAmount;
|
||||
}
|
||||
|
||||
public void setTotalAmount(BigDecimal totalAmount) {
|
||||
this.totalAmount = totalAmount;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(LocalDateTime createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(LocalDateTime updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Cart cart = (Cart) o;
|
||||
return Objects.equals(cartId, cart.cartId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(cartId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Cart{" +
|
||||
"cartId=" + cartId +
|
||||
", cartStatus='" + cartStatus + '\'' +
|
||||
", totalAmount=" + totalAmount +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
121
backend/src/main/java/com/petshop/backend/entity/CartItem.java
Normal file
121
backend/src/main/java/com/petshop/backend/entity/CartItem.java
Normal file
@@ -0,0 +1,121 @@
|
||||
package com.petshop.backend.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.hibernate.annotations.UpdateTimestamp;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "cart_item")
|
||||
public class CartItem {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long cartItemId;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "cartId", nullable = false)
|
||||
private Cart cart;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "prodId", nullable = false)
|
||||
private Product product;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer quantity;
|
||||
|
||||
@Column(nullable = false, precision = 10, scale = 2)
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
@CreationTimestamp
|
||||
@Column(name = "created_at", updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@UpdateTimestamp
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
public CartItem() {
|
||||
}
|
||||
|
||||
public Long getCartItemId() {
|
||||
return cartItemId;
|
||||
}
|
||||
|
||||
public void setCartItemId(Long cartItemId) {
|
||||
this.cartItemId = cartItemId;
|
||||
}
|
||||
|
||||
public Cart getCart() {
|
||||
return cart;
|
||||
}
|
||||
|
||||
public void setCart(Cart cart) {
|
||||
this.cart = cart;
|
||||
}
|
||||
|
||||
public Product getProduct() {
|
||||
return product;
|
||||
}
|
||||
|
||||
public void setProduct(Product product) {
|
||||
this.product = product;
|
||||
}
|
||||
|
||||
public Integer getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(Integer quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public BigDecimal getUnitPrice() {
|
||||
return unitPrice;
|
||||
}
|
||||
|
||||
public void setUnitPrice(BigDecimal unitPrice) {
|
||||
this.unitPrice = unitPrice;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(LocalDateTime createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(LocalDateTime updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CartItem cartItem = (CartItem) o;
|
||||
return Objects.equals(cartItemId, cartItem.cartItemId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(cartItemId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CartItem{" +
|
||||
"cartItemId=" + cartItemId +
|
||||
", quantity=" + quantity +
|
||||
", unitPrice=" + unitPrice +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
162
backend/src/main/java/com/petshop/backend/entity/Coupon.java
Normal file
162
backend/src/main/java/com/petshop/backend/entity/Coupon.java
Normal file
@@ -0,0 +1,162 @@
|
||||
package com.petshop.backend.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.hibernate.annotations.UpdateTimestamp;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "coupon")
|
||||
public class Coupon {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long couponId;
|
||||
|
||||
@Column(nullable = false, length = 50, unique = true)
|
||||
private String couponCode;
|
||||
|
||||
@Column(nullable = false, length = 20)
|
||||
private String discountType;
|
||||
|
||||
@Column(nullable = false, precision = 10, scale = 2)
|
||||
private BigDecimal discountValue;
|
||||
|
||||
@Column(precision = 10, scale = 2)
|
||||
private BigDecimal minOrderAmount;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Boolean active = true;
|
||||
|
||||
private LocalDateTime startsAt;
|
||||
|
||||
private LocalDateTime endsAt;
|
||||
|
||||
private Integer usageLimit;
|
||||
|
||||
@CreationTimestamp
|
||||
@Column(name = "created_at", updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@UpdateTimestamp
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
public Coupon() {
|
||||
}
|
||||
|
||||
public Long getCouponId() {
|
||||
return couponId;
|
||||
}
|
||||
|
||||
public void setCouponId(Long couponId) {
|
||||
this.couponId = couponId;
|
||||
}
|
||||
|
||||
public String getCouponCode() {
|
||||
return couponCode;
|
||||
}
|
||||
|
||||
public void setCouponCode(String couponCode) {
|
||||
this.couponCode = couponCode;
|
||||
}
|
||||
|
||||
public String getDiscountType() {
|
||||
return discountType;
|
||||
}
|
||||
|
||||
public void setDiscountType(String discountType) {
|
||||
this.discountType = discountType;
|
||||
}
|
||||
|
||||
public BigDecimal getDiscountValue() {
|
||||
return discountValue;
|
||||
}
|
||||
|
||||
public void setDiscountValue(BigDecimal discountValue) {
|
||||
this.discountValue = discountValue;
|
||||
}
|
||||
|
||||
public BigDecimal getMinOrderAmount() {
|
||||
return minOrderAmount;
|
||||
}
|
||||
|
||||
public void setMinOrderAmount(BigDecimal minOrderAmount) {
|
||||
this.minOrderAmount = minOrderAmount;
|
||||
}
|
||||
|
||||
public Boolean getActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive(Boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public LocalDateTime getStartsAt() {
|
||||
return startsAt;
|
||||
}
|
||||
|
||||
public void setStartsAt(LocalDateTime startsAt) {
|
||||
this.startsAt = startsAt;
|
||||
}
|
||||
|
||||
public LocalDateTime getEndsAt() {
|
||||
return endsAt;
|
||||
}
|
||||
|
||||
public void setEndsAt(LocalDateTime endsAt) {
|
||||
this.endsAt = endsAt;
|
||||
}
|
||||
|
||||
public Integer getUsageLimit() {
|
||||
return usageLimit;
|
||||
}
|
||||
|
||||
public void setUsageLimit(Integer usageLimit) {
|
||||
this.usageLimit = usageLimit;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(LocalDateTime createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(LocalDateTime updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Coupon coupon = (Coupon) o;
|
||||
return Objects.equals(couponId, coupon.couponId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(couponId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Coupon{" +
|
||||
"couponId=" + couponId +
|
||||
", couponCode='" + couponCode + '\'' +
|
||||
", discountType='" + discountType + '\'' +
|
||||
", discountValue=" + discountValue +
|
||||
", active=" + active +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.petshop.backend.repository;
|
||||
|
||||
import com.petshop.backend.entity.CartItem;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface CartItemRepository extends JpaRepository<CartItem, Long> {
|
||||
|
||||
List<CartItem> findByCartCartId(Long cartId);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.petshop.backend.repository;
|
||||
|
||||
import com.petshop.backend.entity.Cart;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface CartRepository extends JpaRepository<Cart, Long> {
|
||||
|
||||
List<Cart> findByUserId(Long userId);
|
||||
|
||||
Optional<Cart> findByUserIdAndCartStatus(Long userId, String cartStatus);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.petshop.backend.repository;
|
||||
|
||||
import com.petshop.backend.entity.Coupon;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface CouponRepository extends JpaRepository<Coupon, Long> {
|
||||
|
||||
Optional<Coupon> findByCouponCode(String couponCode);
|
||||
}
|
||||
Reference in New Issue
Block a user