-
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.
Signed-off-by: Mykhailo Marchuk <[email protected]>
- Loading branch information
1 parent
4f8b37e
commit 13674fd
Showing
12 changed files
with
165 additions
and
140 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
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
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,27 +1,52 @@ | ||
package com.booking.app.entity; | ||
|
||
import com.booking.app.enums.EnumRole; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@Entity | ||
@Table(name = "role") | ||
@Table(name = "roles") | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Setter | ||
@Getter | ||
@Builder | ||
public class Role{ | ||
public class Role { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Integer id; | ||
private Short id; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private EnumRole enumRole; | ||
private RoleType type; | ||
|
||
@OneToMany(mappedBy = "role", cascade = CascadeType.ALL) | ||
@ManyToMany(mappedBy = "roles") | ||
private Set<User> users; | ||
|
||
public static Set<Role> createRoles(Role... roles) { | ||
return new HashSet<>(Arrays.asList(roles)); | ||
} | ||
|
||
public Set<SimpleGrantedAuthority> getGrantedAuthorities() { | ||
return Collections.singleton(new SimpleGrantedAuthority("ROLE_" + type.getType())); | ||
} | ||
|
||
@Getter | ||
public enum RoleType { | ||
ADMIN("ADMIN"), | ||
USER("USER"); | ||
|
||
private final String type; | ||
|
||
RoleType(String type) { | ||
this.type = type; | ||
} | ||
|
||
} | ||
|
||
} |
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
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
This file was deleted.
Oops, something went wrong.
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 @@ | ||
package com.booking.app.enums; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public enum TransportType { | ||
BUS, | ||
TRAIN, | ||
AIRPLANE, | ||
FERRY; | ||
|
||
public static Set<TransportType> getTypes(boolean bus, boolean train, boolean airplane, boolean ferry) { | ||
Set<TransportType> types = new HashSet<>(); | ||
if (bus) types.add(TransportType.BUS); | ||
if (train) types.add(TransportType.TRAIN); | ||
if (airplane) types.add(TransportType.AIRPLANE); | ||
if (ferry) types.add(TransportType.FERRY); | ||
return types; | ||
} | ||
|
||
} |
28 changes: 0 additions & 28 deletions
28
src/main/java/com/booking/app/enums/TypeTransportEnum.java
This file was deleted.
Oops, something went wrong.
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
4 changes: 1 addition & 3 deletions
4
src/main/java/com/booking/app/repositories/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 |
---|---|---|
@@ -1,13 +1,11 @@ | ||
package com.booking.app.repositories; | ||
|
||
import com.booking.app.entity.Role; | ||
|
||
import com.booking.app.enums.EnumRole; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface RoleRepository extends JpaRepository<Role, Integer> { | ||
Role findRoleByEnumRole(EnumRole enumRole); | ||
Role findByType(Role.RoleType roleType); | ||
|
||
} |
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
Oops, something went wrong.