Skip to content

Commit

Permalink
add role to user entity
Browse files Browse the repository at this point in the history
  • Loading branch information
buttasam committed Jun 20, 2017
1 parent f90ff73 commit ae853f8
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 7 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-devtools")
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.42'

// test compile dependencies
testCompile('org.springframework.boot:spring-boot-starter-test')
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/app/persistence/entity/Role.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package app.persistence.entity;

import javax.persistence.*;

/**
* @author Samuel Butta
*/
@Entity
public class Role {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@Column(unique = true)
@Enumerated(EnumType.STRING)
private RoleType role;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public RoleType getRole() {
return role;
}

public void setRole(RoleType role) {
this.role = role;
}
}
13 changes: 13 additions & 0 deletions src/main/java/app/persistence/entity/RoleType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package app.persistence.entity;

/**
* Prehled uzivatelskych roli v cele aplikaci.
*
* @author Samuel Butta
*/
public enum RoleType {

USER,
ADMIN

}
21 changes: 14 additions & 7 deletions src/main/java/app/persistence/entity/User.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package app.persistence.entity;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;

import javax.persistence.*;
import java.util.Set;

Expand All @@ -14,25 +11,28 @@ public class User {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "user_id")
@Column
private Long id;

@Column
private String email;

@Column(name = "password")
@Column
private String password;

@Column
private String firstName;

@Column(name = "last_name")
@Column
private String lastName;

@Column(name = "active")
@Column
private boolean active;


@ManyToMany(cascade = CascadeType.ALL)
private Set<Role> roles;

public Long getId() {
return id;
}
Expand Down Expand Up @@ -81,4 +81,11 @@ public void setActive(boolean active) {
this.active = active;
}

public Set<Role> getRoles() {
return roles;
}

public void setRoles(Set<Role> roles) {
this.roles = roles;
}
}
12 changes: 12 additions & 0 deletions src/main/java/app/persistence/repository/RoleRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package app.persistence.repository;

import app.persistence.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

/**
* @author Samuel Butta
*/
@Repository
public interface RoleRepository extends JpaRepository<Role, Long> {
}

0 comments on commit ae853f8

Please sign in to comment.