RentalEquipmentJpaEntity.java
package com.github.jenkaby.bikerental.rental.infrastructure.persistence.entity;
import jakarta.persistence.*;
import lombok.*;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
@Entity
@Table(name = "rental_equipments")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ToString()
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class RentalEquipmentJpaEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ToString.Exclude
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "rental_id", nullable = false)
private RentalJpaEntity rental;
@Column(name = "equipment_id")
private Long equipmentId;
@EqualsAndHashCode.Include
@Column(name = "equipment_uid", length = 100)
private String equipmentUid;
@Column(nullable = false, length = 20)
private String status;
@Column(name = "started_at")
private LocalDateTime startedAt;
@Column(name = "expected_return_at")
private LocalDateTime expectedReturnAt;
@Column(name = "actual_return_at")
private LocalDateTime actualReturnAt;
@Column(name = "estimated_cost", precision = 10, scale = 2)
private BigDecimal estimatedCost;
@Column(name = "final_cost", precision = 10, scale = 2)
private BigDecimal finalCost;
@Column(name = "created_at", nullable = false, updatable = false)
private Instant createdAt;
@Column(name = "updated_at", nullable = false, updatable = false)
private Instant updatedAt;
@Column(name = "tariff_id")
private Long tariffId;
@Column(name = "equipment_type_slug", nullable = false, length = 100)
private String equipmentTypeSlug;
@PrePersist
protected void onCreate() {
if (createdAt == null) {
createdAt = Instant.now();
}
}
@PreUpdate
protected void onUpdate() {
updatedAt = Instant.now();
}
}