Modifiy table users

This commit is contained in:
Valentin CZERYBA 2022-04-14 22:26:12 +02:00
parent ca2ae584bc
commit cac880df01
2 changed files with 23 additions and 4 deletions

View File

@ -30,10 +30,14 @@ public class ApplicationLifeCycle {
LOGGER.info("The application has started");
if (schemaCreate){
Users users = new Users();
if(users.findByName("Peter") == null){
users.name = "Peter";
if(users.findByPseudo("Peter") == null){
users.pseudo = "Peter";
users.email = "peter@email.com";
users.name = "Toto";
users.firstName = "Peter";
users.birth = LocalDate.of(1993, Month.FEBRUARY, 23);
users.status = true;
users.password = "toto";
users.persist();
LOGGER.info("Users test was created");
} else {

View File

@ -2,19 +2,34 @@ package com.covas;
import java.time.LocalDate;
import javax.persistence.Column;
import javax.persistence.Entity;
import org.hibernate.annotations.ColumnDefault;
import io.quarkus.hibernate.orm.panache.PanacheEntity;
@Entity
public class Users extends PanacheEntity {
@Column(nullable = false, unique = true)
public String pseudo;
@Column(nullable = false, unique = true)
public String email;
@Column(nullable = false)
public String name;
@Column(nullable = false)
public String firstName;
@Column(nullable = false)
public LocalDate birth;
@ColumnDefault("false")
public Boolean status;
@Column(nullable = false)
public String password;
public static Users findByName(String name){
return find("name", name).firstResult();
public static Users findByPseudo(String pseudo){
return find("pseudo", pseudo).firstResult();
}
}