Add another user and enum for roles
This commit is contained in:
parent
cac880df01
commit
268ee6e277
@ -30,6 +30,9 @@ public class ApplicationLifeCycle {
|
|||||||
LOGGER.info("The application has started");
|
LOGGER.info("The application has started");
|
||||||
if (schemaCreate){
|
if (schemaCreate){
|
||||||
Users users = new Users();
|
Users users = new Users();
|
||||||
|
Users users2 = new Users();
|
||||||
|
|
||||||
|
|
||||||
if(users.findByPseudo("Peter") == null){
|
if(users.findByPseudo("Peter") == null){
|
||||||
users.pseudo = "Peter";
|
users.pseudo = "Peter";
|
||||||
users.email = "peter@email.com";
|
users.email = "peter@email.com";
|
||||||
@ -38,10 +41,25 @@ public class ApplicationLifeCycle {
|
|||||||
users.birth = LocalDate.of(1993, Month.FEBRUARY, 23);
|
users.birth = LocalDate.of(1993, Month.FEBRUARY, 23);
|
||||||
users.status = true;
|
users.status = true;
|
||||||
users.password = "toto";
|
users.password = "toto";
|
||||||
|
users.roles = Roles.User;
|
||||||
users.persist();
|
users.persist();
|
||||||
LOGGER.info("Users test was created");
|
LOGGER.info("Peter test was created");
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("User test wasn't created");
|
LOGGER.info("Peter's user test wasn't created");
|
||||||
|
}
|
||||||
|
if(users2.findByPseudo("Robert") == null){
|
||||||
|
users2.pseudo = "Robert";
|
||||||
|
users2.email = "robert@email.com";
|
||||||
|
users2.name = "Toto";
|
||||||
|
users2.firstName = "Peter";
|
||||||
|
users2.birth = LocalDate.of(1993, Month.FEBRUARY, 23);
|
||||||
|
users2.status = true;
|
||||||
|
users2.password = "toto";
|
||||||
|
users2.roles = Roles.Admin;
|
||||||
|
users2.persist();
|
||||||
|
LOGGER.info("Robert test was created");
|
||||||
|
} else {
|
||||||
|
LOGGER.info("Robert's user test wasn't created");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("DB init wassn't created");
|
LOGGER.info("DB init wassn't created");
|
||||||
|
@ -14,7 +14,6 @@ import javax.transaction.Transactional;
|
|||||||
import javax.ws.rs.CookieParam;
|
import javax.ws.rs.CookieParam;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.InternalServerErrorException;
|
import javax.ws.rs.InternalServerErrorException;
|
||||||
import javax.ws.rs.PUT;
|
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
|
@ -9,6 +9,10 @@ import org.hibernate.annotations.ColumnDefault;
|
|||||||
|
|
||||||
import io.quarkus.hibernate.orm.panache.PanacheEntity;
|
import io.quarkus.hibernate.orm.panache.PanacheEntity;
|
||||||
|
|
||||||
|
enum Roles {
|
||||||
|
User,
|
||||||
|
Admin
|
||||||
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Users extends PanacheEntity {
|
public class Users extends PanacheEntity {
|
||||||
@ -27,6 +31,8 @@ public class Users extends PanacheEntity {
|
|||||||
public Boolean status;
|
public Boolean status;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
public String password;
|
public String password;
|
||||||
|
|
||||||
|
public Roles roles;
|
||||||
|
|
||||||
public static Users findByPseudo(String pseudo){
|
public static Users findByPseudo(String pseudo){
|
||||||
return find("pseudo", pseudo).firstResult();
|
return find("pseudo", pseudo).firstResult();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user