-
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.
- Loading branch information
1 parent
ffaa383
commit 8d51559
Showing
9 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
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,23 @@ | ||
package com.project.carsharingapp.model; | ||
|
||
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.Table; | ||
import lombok.Data; | ||
|
||
@Entity | ||
@Data | ||
@Table(name = "roles") | ||
public class Role { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@Column(name = "name", nullable = false, unique = true) | ||
@Enumerated(EnumType.STRING) | ||
private RoleName roleName; | ||
} |
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,6 @@ | ||
package com.project.carsharingapp.model; | ||
|
||
public enum RoleName { | ||
MANAGER, | ||
CUSTOMER | ||
} |
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 @@ | ||
package com.project.carsharingapp.model; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.JoinTable; | ||
import jakarta.persistence.ManyToMany; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.ToString; | ||
import org.hibernate.annotations.SQLDelete; | ||
import org.hibernate.annotations.Where; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@Entity | ||
@Data | ||
@SQLDelete(sql = "UPDATE users SET is_deleted = true WHERE id =?") | ||
@Where(clause = "is_deleted=false") | ||
@Table(name = "users") | ||
public class User { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@Column(nullable = false, unique = true) | ||
private String email; | ||
@Column(nullable = false) | ||
private String firstName; | ||
@Column(nullable = false) | ||
private String lastName; | ||
@Column(nullable = false) | ||
private String password; | ||
private String phone; | ||
@Column(nullable = false) | ||
@ManyToMany | ||
@JoinTable(name = "user_roles", | ||
joinColumns = @JoinColumn(name = "user_id"), | ||
inverseJoinColumns = @JoinColumn(name = "role_id")) | ||
@ToString.Exclude | ||
@EqualsAndHashCode.Exclude | ||
private Set<Role> roles = new HashSet<>(); | ||
@Column(name = "is_deleted",nullable = false) | ||
private boolean isDeleted = false; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/project/carsharingapp/repository/RoleRepository.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.project.carsharingapp.repository; | ||
|
||
import com.project.carsharingapp.model.Role; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface RoleRepository extends JpaRepository<Role, Long> { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/project/carsharingapp/repository/UserRepository.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.project.carsharingapp.repository; | ||
|
||
import com.project.carsharingapp.model.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserRepository extends JpaRepository<User, Long> { | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/resources/db.changelog/changes/create-roles-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,21 @@ | ||
databaseChangeLog: | ||
- changeSet: | ||
id: create-roles-table | ||
author: osa | ||
changes: | ||
- createTable: | ||
tableName: roles | ||
columns: | ||
- column: | ||
name: id | ||
type: bigint | ||
autoIncrement: true | ||
constraints: | ||
primaryKey: true | ||
nullable: false | ||
- column: | ||
name: name | ||
type: varchar(255) | ||
constraints: | ||
unique: true | ||
nullable: false |
24 changes: 24 additions & 0 deletions
24
src/main/resources/db.changelog/changes/create-user-roles-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,24 @@ | ||
databaseChangeLog: | ||
- changeSet: | ||
id: create-user-role-table | ||
author: osa | ||
changes: | ||
- createTable: | ||
tableName: user_roles | ||
columns: | ||
- column: | ||
name: user_id | ||
type: bigint | ||
constraints: | ||
primaryKey: true | ||
nullable: false | ||
references: users(id) | ||
foreignKeyName: fk_user_roles_user_id | ||
- column: | ||
name: role_id | ||
type: bigint | ||
constraints: | ||
primaryKey: true | ||
nullable: false | ||
references: roles(id) | ||
foreignKeyName: fk_user_roles_role_id |
47 changes: 47 additions & 0 deletions
47
src/main/resources/db.changelog/changes/create-users-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,47 @@ | ||
databaseChangeLog: | ||
- changeSet: | ||
id: create-users-table | ||
author: osa | ||
changes: | ||
- createTable: | ||
tableName: users | ||
columns: | ||
- column: | ||
name: id | ||
type: bigint | ||
autoIncrement: true | ||
constraints: | ||
primaryKey: true | ||
nullable: false | ||
- column: | ||
name: email | ||
type: varchar(255) | ||
constraints: | ||
nullable: false | ||
unique: true | ||
- column: | ||
name: first_name | ||
type: varchar(255) | ||
constraints: | ||
nullable: false | ||
- column: | ||
name: last_name | ||
type: varchar(255) | ||
constraints: | ||
nullable: false | ||
- column: | ||
name: password | ||
type: varchar(255) | ||
constraints: | ||
nullable: false | ||
- column: | ||
name: phone | ||
type: varchar(255) | ||
constraints: | ||
nullable: false | ||
- 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
databaseChangeLog: | ||
- include: | ||
file: db.changelog/changes/create-roles-table.yaml | ||
- include: | ||
file: db.changelog/changes/create-users-table.yaml | ||
- include: | ||
file: db.changelog/changes/create-user-roles-table.yaml |