Add user roles

master
esensar 2017-03-23 00:46:31 +01:00
parent 7848c33ad2
commit 5ae5b7d3b4
4 changed files with 70 additions and 13 deletions

View File

@ -0,0 +1,16 @@
package ba.steleks.repository;
/**
* Created by ensar on 22/03/17.
*/
import ba.steleks.repository.model.User;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import java.util.List;
public interface UserRolesJpaRepository extends CrudRepository<User, Long> {
List<User> findByUsername(@Param("username") String username);
}

View File

@ -4,15 +4,9 @@ package ba.steleks.repository;
* Created by ensar on 22/03/17.
*/
import ba.steleks.repository.model.User;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import ba.steleks.repository.model.UserRole;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface UsersJpaRepository extends CrudRepository<UserRole, Long> {
public interface UsersJpaRepository extends PagingAndSortingRepository<User, Long> {
List<User> findByUsername(@Param("username") String username);
User findById(@Param("id") Long id);
}

View File

@ -2,10 +2,8 @@ package ba.steleks.repository.model;/**
* Created by ensar on 22/03/17.
*/
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.*;
import java.util.Set;
import java.util.logging.Logger;
@Entity
@ -29,6 +27,10 @@ public class User {
private long courseId;
private long membershipTypeId;
@ManyToMany
@JoinColumn
private Set<UserRole> userRoles;
public long getId() {
return id;
}
@ -124,4 +126,12 @@ public class User {
public void setMembershipTypeId(long membershipTypeId) {
this.membershipTypeId = membershipTypeId;
}
public Set<UserRole> getUserRoles() {
return userRoles;
}
public void setUserRoles(Set<UserRole> userRoles) {
this.userRoles = userRoles;
}
}

View File

@ -0,0 +1,37 @@
package ba.steleks.repository.model;/**
* Created by ensar on 22/03/17.
*/
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.logging.Logger;
@Entity
public class UserRole {
private static final Logger logger =
Logger.getLogger(UserRole.class.getName());
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String roleName;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
}