Skip to content

Commit

Permalink
Reservation entity - update changelog directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkasuka committed Jul 22, 2023
1 parent 31c5a9c commit d175611
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Past;

import java.time.LocalDateTime;
import java.time.Instant;


public record ReservationDto(
int reservationId,
@NotBlank(message = "Product ID is mandatory")
int productId,
@NotNull(message = "Reserved quantity is mandatory")
int reservedQuantity,
@NotNull(message = "ReservationId is the mandatory attribute")
Integer reservationId,

@NotBlank(message = "ProductId is the mandatory attribute")
String productId,

@NotNull(message = "ReservedQuantity is the mandatory attribute")
Integer reservedQuantity,

@NotNull(message = "CreatedAt is the mandatory attribute")
@Past
LocalDateTime createdAt,
@NotBlank(message = "Status is mandatory")
Instant createdAt,

@NotBlank(message = "Status is the mandatory attribute")
String status
) {
}
}
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
}
}

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
);

0 comments on commit d175611

Please sign in to comment.