Add another user and enum for roles

This commit is contained in:
Valentin CZERYBA 2022-04-15 20:19:06 +02:00
parent cac880df01
commit 268ee6e277
3 changed files with 26 additions and 3 deletions

View File

@ -30,6 +30,9 @@ public class ApplicationLifeCycle {
LOGGER.info("The application has started");
if (schemaCreate){
Users users = new Users();
Users users2 = new Users();
if(users.findByPseudo("Peter") == null){
users.pseudo = "Peter";
users.email = "peter@email.com";
@ -38,10 +41,25 @@ public class ApplicationLifeCycle {
users.birth = LocalDate.of(1993, Month.FEBRUARY, 23);
users.status = true;
users.password = "toto";
users.roles = Roles.User;
users.persist();
LOGGER.info("Users test was created");
LOGGER.info("Peter test was created");
} 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 {
LOGGER.info("DB init wassn't created");

View File

@ -14,7 +14,6 @@ import javax.transaction.Transactional;
import javax.ws.rs.CookieParam;
import javax.ws.rs.GET;
import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;

View File

@ -9,6 +9,10 @@ import org.hibernate.annotations.ColumnDefault;
import io.quarkus.hibernate.orm.panache.PanacheEntity;
enum Roles {
User,
Admin
}
@Entity
public class Users extends PanacheEntity {
@ -27,6 +31,8 @@ public class Users extends PanacheEntity {
public Boolean status;
@Column(nullable = false)
public String password;
public Roles roles;
public static Users findByPseudo(String pseudo){
return find("pseudo", pseudo).firstResult();