From 2e31a812511bd66c02e7a222430e3797343a1010 Mon Sep 17 00:00:00 2001 From: Yura Novak Date: Mon, 20 Nov 2023 15:11:11 +0200 Subject: [PATCH] [model]-new-model-for-payment --- src/main/java/model/Payment.java | 57 ++++++++++++++++++++++++++++++++ src/main/java/model/Rental.java | 13 ++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/main/java/model/Payment.java create mode 100644 src/main/java/model/Rental.java diff --git a/src/main/java/model/Payment.java b/src/main/java/model/Payment.java new file mode 100644 index 0000000..3d7b5bd --- /dev/null +++ b/src/main/java/model/Payment.java @@ -0,0 +1,57 @@ +package model; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; +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 java.math.BigDecimal; +import java.net.URL; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@EqualsAndHashCode(exclude = {"rental"}) +@ToString(exclude = {"rental"}) +@Entity +@Table(name = "payments") +public class Payment { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private PaymentStatus status; + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private PaymentType type; + @Column(nullable = false) + private URL sessionUrl; + @Column(nullable = false) + private String sessionId; + @Column(nullable = false) + private BigDecimal amountToPay; + @ManyToOne(fetch = FetchType.LAZY, optional = false) // ?Lilja + @JoinColumn(name = "rental_id", nullable = false) + private Rental rental; + + private enum PaymentStatus { + PENDING, + PAID, + CANCELED + } + + private enum PaymentType { + PAYMENT, + FINE + } +} diff --git a/src/main/java/model/Rental.java b/src/main/java/model/Rental.java new file mode 100644 index 0000000..151ce2d --- /dev/null +++ b/src/main/java/model/Rental.java @@ -0,0 +1,13 @@ +package model; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class Rental { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; +}