From 5ae5b7d3b47ef46bfdc015a6b05266060f52949a Mon Sep 17 00:00:00 2001 From: esensar Date: Thu, 23 Mar 2017 00:46:31 +0100 Subject: [PATCH] Add user roles --- .../repository/UserRolesJpaRepository.java | 16 ++++++++ .../repository/UsersJpaRepository.java | 12 ++---- .../ba/steleks/repository/model/User.java | 18 +++++++-- .../ba/steleks/repository/model/UserRole.java | 37 +++++++++++++++++++ 4 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 users/src/main/java/ba/steleks/repository/UserRolesJpaRepository.java create mode 100644 users/src/main/java/ba/steleks/repository/model/UserRole.java diff --git a/users/src/main/java/ba/steleks/repository/UserRolesJpaRepository.java b/users/src/main/java/ba/steleks/repository/UserRolesJpaRepository.java new file mode 100644 index 0000000..24552f7 --- /dev/null +++ b/users/src/main/java/ba/steleks/repository/UserRolesJpaRepository.java @@ -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 { + List findByUsername(@Param("username") String username); +} diff --git a/users/src/main/java/ba/steleks/repository/UsersJpaRepository.java b/users/src/main/java/ba/steleks/repository/UsersJpaRepository.java index 854eb90..0f00297 100644 --- a/users/src/main/java/ba/steleks/repository/UsersJpaRepository.java +++ b/users/src/main/java/ba/steleks/repository/UsersJpaRepository.java @@ -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 { - -public interface UsersJpaRepository extends PagingAndSortingRepository { - - List findByUsername(@Param("username") String username); - User findById(@Param("id") Long id); } diff --git a/users/src/main/java/ba/steleks/repository/model/User.java b/users/src/main/java/ba/steleks/repository/model/User.java index 9b6300f..93f275d 100644 --- a/users/src/main/java/ba/steleks/repository/model/User.java +++ b/users/src/main/java/ba/steleks/repository/model/User.java @@ -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 userRoles; + public long getId() { return id; } @@ -124,4 +126,12 @@ public class User { public void setMembershipTypeId(long membershipTypeId) { this.membershipTypeId = membershipTypeId; } + + public Set getUserRoles() { + return userRoles; + } + + public void setUserRoles(Set userRoles) { + this.userRoles = userRoles; + } } diff --git a/users/src/main/java/ba/steleks/repository/model/UserRole.java b/users/src/main/java/ba/steleks/repository/model/UserRole.java new file mode 100644 index 0000000..4079fb1 --- /dev/null +++ b/users/src/main/java/ba/steleks/repository/model/UserRole.java @@ -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; + } +}