-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reservation entity - update changelog directory structure
- Loading branch information
1 parent
31c5a9c
commit d175611
Showing
3 changed files
with
57 additions
and
69 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
91 changes: 31 additions & 60 deletions
91
src/main/java/com/zufar/onlinestore/reservation/entity/Reservation.java
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 |
---|---|---|
@@ -1,92 +1,63 @@ | ||
package com.zufar.onlinestore.reservation.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.Instant; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
@Entity | ||
@EntityListeners(AuditingEntityListener.class) | ||
@Table(name = "reservation") | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Reservation { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.UUID) | ||
@Column(name = "reservation_id") | ||
private String reservationId; | ||
@Column(name = "product_id", nullable = false) | ||
private String productId; | ||
@Column(name = "reserved_quantity", nullable = false) | ||
private int reservedQuantity; | ||
@CreatedDate | ||
@Column(name = "created_at", nullable = false, updatable = false) | ||
private LocalDateTime createdAt; | ||
@Column(name = "status", nullable = false) | ||
private String status; | ||
|
||
public Reservation() { | ||
} | ||
|
||
public Reservation(String productId, int reservedQuantity, LocalDateTime createdAt, String status) { | ||
this.productId = productId; | ||
this.reservedQuantity = reservedQuantity; | ||
this.createdAt = createdAt; | ||
this.status = status; | ||
} | ||
|
||
public String getReservationId() { | ||
return reservationId; | ||
} | ||
|
||
public void setReservationId(String reservationId) { | ||
this.reservationId = reservationId; | ||
} | ||
|
||
public String getProductId() { | ||
return productId; | ||
} | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
private Integer id; | ||
|
||
public void setProductId(String productId) { | ||
this.productId = productId; | ||
} | ||
@Column(name = "reservation_id", nullable = false) | ||
private UUID reservationId; | ||
|
||
public int getReservedQuantity() { | ||
return reservedQuantity; | ||
} | ||
|
||
public void setReservedQuantity(int reservedQuantity) { | ||
this.reservedQuantity = reservedQuantity; | ||
} | ||
|
||
public LocalDateTime getCreatedAt() { | ||
return createdAt; | ||
} | ||
@Column(name = "product_id", nullable = false) | ||
private UUID productId; | ||
|
||
public void setCreatedAt(LocalDateTime createdAt) { | ||
this.createdAt = createdAt; | ||
} | ||
@Column(name = "reserved_quantity", nullable = false) | ||
private Integer reservedQuantity; | ||
|
||
public String getStatus() { | ||
return status; | ||
} | ||
@CreatedDate | ||
@Column(name = "created_at", nullable = false, updatable = false) | ||
private Instant createdAt; | ||
|
||
public void setStatus(String status) { | ||
this.status = status; | ||
} | ||
@Enumerated(EnumType.STRING) | ||
@Column(name = "status", nullable = false) | ||
private ReservationStatus status; | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Reservation that = (Reservation) o; | ||
return Objects.equals(reservationId, that.reservationId) && Objects.equals(productId, that.productId) && Objects.equals(createdAt, that.createdAt); | ||
return reservationId.equals(that.reservationId) && productId.equals(that.productId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(reservationId, productId, createdAt); | ||
return Objects.hash(reservationId, productId); | ||
} | ||
|
||
public enum ReservationStatus { | ||
CREATED, CONFIRMED, CANCELLED | ||
} | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
src/main/resources/db/changelog/version-1.0/22.07.2023.create-reservation-table.sql
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,11 @@ | ||
CREATE TYPE RESERVATION_STATUS AS ENUM ('CREATED', 'CONFIRMED', 'CANCELLED'); | ||
|
||
CREATE TABLE IF NOT EXISTS reservation | ||
( | ||
id SERIAL PRIMARY KEY, | ||
reservation_id UUID NOT NULL, | ||
product_id UUID NOT NULL, | ||
reserved_quantity INT NOT NULL CHECK (reserved_quantity > 0), | ||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
status RESERVATION_STATUS NOT NULL | ||
); |