From 7b5772b49f7cda5493667e233e46ea304d4b0261 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 13 Apr 2022 23:08:22 +0200 Subject: [PATCH] ressource put init --- src/main/java/com/covas/TokenRessource.java | 24 +++++++++++++++++++++ src/main/resources/application.properties | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/covas/TokenRessource.java b/src/main/java/com/covas/TokenRessource.java index 833d033..8e7b05d 100644 --- a/src/main/java/com/covas/TokenRessource.java +++ b/src/main/java/com/covas/TokenRessource.java @@ -14,6 +14,7 @@ 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; @@ -26,18 +27,41 @@ import io.smallrye.jwt.auth.principal.JWTParser; import io.smallrye.jwt.auth.principal.ParseException; import io.smallrye.jwt.build.Jwt; +import org.eclipse.microprofile.config.inject.ConfigProperty; import org.eclipse.microprofile.jwt.JsonWebToken; @Path("/token") public class TokenRessource { + @Inject + @ConfigProperty(name = "covas.schema.create", defaultValue = "true") + boolean schemaCreate; @Inject JsonWebToken jwt; @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 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3af2412..8e2db47 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -10,4 +10,6 @@ quarkus.datasource.password = toto quarkus.datasource.jdbc.url = jdbc:postgresql://localhost:5432/toto # drop and create the database at startup (use `update` to only update the schema) -quarkus.hibernate-orm.database.generation = drop-and-create \ No newline at end of file +quarkus.hibernate-orm.database.generation = drop-and-create + +covas.schema.create = true \ No newline at end of file