-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adjusted rental entity and added an appropriate liquibase file
- Loading branch information
1 parent
ec5eeee
commit 5a6569b
Showing
3 changed files
with
65 additions
and
14 deletions.
There are no files selected for viewing
25 changes: 13 additions & 12 deletions
25
src/main/java/com/project/carsharingapp/model/Rental.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,34 +1,35 @@ | ||
package com.project.carsharingapp.model; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.*; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.hibernate.annotations.SQLDelete; | ||
import org.hibernate.annotations.Where; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@SQLDelete(sql = "UPDATE rentals SET is_deleted = true WHERE id = ?") | ||
@Where(clause = "is_deleted=false") | ||
@Entity | ||
@Table(name = "rentals") | ||
public class Rental { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@Column(name = "rental_date", nullable = false) | ||
private LocalDateTime rentalDate; | ||
@Column(name = "return_date", nullable = false) | ||
private LocalDateTime returnDate; | ||
@Column(name = "actual_return_date") | ||
private LocalDateTime actualReturnDate; | ||
//@OneToOne(fetch = FetchType.LAZY) | ||
//private Car car; | ||
// @ManyToOne(fetch = FetchType.LAZY) | ||
// private User user; | ||
@Column(nullable = false) | ||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "car_id", nullable = false) | ||
private Car car; | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id", nullable = false) | ||
private User user; | ||
@Column(name = "is_deleted",nullable = false) | ||
private boolean isDeleted; | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/resources/db/changelog/changes/create-rentals-table.yaml
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,48 @@ | ||
databaseChangeLog: | ||
- changeSet: | ||
id: create-rentals-table | ||
author: ivan-diatliuk | ||
changes: | ||
- createTable: | ||
tableName: rentals | ||
columns: | ||
- column: | ||
name: id | ||
type: bigint | ||
autoIncrement: true | ||
constraints: | ||
nullable: false | ||
primaryKey: true | ||
- column: | ||
name: rental_date | ||
type: timestamp | ||
constraints: | ||
nullable: false | ||
- column: | ||
name: return_date | ||
type: timestamp | ||
constraints: | ||
nullable: false | ||
- column: | ||
name: actual_return_date | ||
type: timestamp | ||
- column: | ||
name: car_id | ||
type: bigint | ||
constraints: | ||
nullable: false | ||
foreignKeyName: fk_car_id | ||
references: cars(id) | ||
- column: | ||
name: user_id | ||
type: bigint | ||
constraints: | ||
nullable: false | ||
foreignKeyName: fk_user_id | ||
references: users(id) | ||
- column: | ||
name: is_deleted | ||
type: boolean | ||
defaultValueBoolean: false | ||
constraints: | ||
nullable: false |
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