Skip to content

Commit

Permalink
Merge branch 'master' into create-rental-entity
Browse files Browse the repository at this point in the history
  • Loading branch information
TetianaDenchyk authored Nov 20, 2023
2 parents 5c09c23 + f15876b commit 97eeb0f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
47 changes: 46 additions & 1 deletion src/main/java/com/champions/carsharingservice/model/Car.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,64 @@
package com.champions.carsharingservice.model;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

@Entity
@Getter
@Setter
@EqualsAndHashCode(exclude = {"rentals"})
@ToString(exclude = {"rentals"})
@SQLDelete(sql = "UPDATE cars SET is_deleted = true WHERE id = ?")
@Where(clause = "is_deleted=false")
@Table(name = "cars")
public class Car {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToMany
@Column(nullable = false)
private String model;

@Column(nullable = false)
private String brand;

@Enumerated(EnumType.STRING)
@Column(nullable = false, unique = true)
private CarType type;

@Column(nullable = false)
private Integer inventory;

@Column(nullable = false, name = "daily_fee")
private BigDecimal dailyFee;

@OneToMany(mappedBy = "car", orphanRemoval = true, cascade = CascadeType.REMOVE)
private Set<Rental> rentals = new HashSet<>();

@Column(nullable = false, name = "is_deleted")
private boolean isDeleted = false;

public enum CarType {
SEDAN,
SUV,
HATCHBACK,
UNIVERSAL
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ public class Rental {
@JoinColumn(name = "user_id", nullable = false)
private User user;

@Column(name = "rental_date", nullable = false)
private LocalDateTime rentalDateTime;


@Column(name = "return_date", nullable = false)
private LocalDateTime returnDateTime;

@Column(name = "actual_return_date", nullable = false)
private LocalDateTime actualReturnDateTime;

@OneToMany(mappedBy = "rental",
Expand Down

0 comments on commit 97eeb0f

Please sign in to comment.