ressource put init

This commit is contained in:
Valentin CZERYBA 2022-04-13 23:08:22 +02:00
parent 0b241bd8b5
commit 7b5772b49f
2 changed files with 27 additions and 1 deletions

View File

@ -14,6 +14,7 @@ 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;
@ -26,18 +27,41 @@ import io.smallrye.jwt.auth.principal.JWTParser;
import io.smallrye.jwt.auth.principal.ParseException; import io.smallrye.jwt.auth.principal.ParseException;
import io.smallrye.jwt.build.Jwt; import io.smallrye.jwt.build.Jwt;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.jwt.JsonWebToken; import org.eclipse.microprofile.jwt.JsonWebToken;
@Path("/token") @Path("/token")
public class TokenRessource { public class TokenRessource {
@Inject
@ConfigProperty(name = "covas.schema.create", defaultValue = "true")
boolean schemaCreate;
@Inject @Inject
JsonWebToken jwt; JsonWebToken jwt;
@Inject JWTParser parser; @Inject JWTParser parser;
@PUT
@Path("init")
@Transactional
public Response init(){
if (schemaCreate){
Users users = new Users();
if(users.findByName("Peter") == null){
users.name = "Peter";
users.birth = LocalDate.of(1993, Month.FEBRUARY, 23);
users.status = true;
users.persist();
return Response.status(Response.Status.CREATED).build();
}
}
return Response.status(Response.Status.NOT_MODIFIED).build();
}
@GET @GET

View File

@ -10,4 +10,6 @@ quarkus.datasource.password = toto
quarkus.datasource.jdbc.url = jdbc:postgresql://localhost:5432/toto quarkus.datasource.jdbc.url = jdbc:postgresql://localhost:5432/toto
# drop and create the database at startup (use `update` to only update the schema) # drop and create the database at startup (use `update` to only update the schema)
quarkus.hibernate-orm.database.generation = drop-and-create quarkus.hibernate-orm.database.generation = drop-and-create
covas.schema.create = true