-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into create-rental-entity
- Loading branch information
Showing
2 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
47 changes: 46 additions & 1 deletion
47
src/main/java/com/champions/carsharingservice/model/Car.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,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 | ||
} | ||
} |
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