From dac58bd99a94fb18a5a5b2823baf74a22f0e9b36 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 9 Jan 2023 22:49:41 +0100 Subject: [PATCH 1/9] add mongdb-client --- pom.xml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 5232c38..41a3184 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,10 @@ io.quarkus quarkus-redis-client + + io.quarkus + quarkus-mongodb-client + io.quarkus quarkus-junit5 @@ -132,7 +136,6 @@ native - native @@ -150,7 +153,6 @@ verify - ${project.build.directory}/${project.build.finalName}-runner org.jboss.logmanager.LogManager @@ -163,7 +165,7 @@ - native + native From 48c535bf487251021d9eb4cf4a90221bb5819b00 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 10 Jan 2023 21:29:09 +0100 Subject: [PATCH 2/9] remove panache --- pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pom.xml b/pom.xml index 41a3184..f40a5b9 100644 --- a/pom.xml +++ b/pom.xml @@ -80,10 +80,6 @@ io.quarkus quarkus-redis-client - - io.quarkus - quarkus-mongodb-client - io.quarkus quarkus-junit5 From d0f69044c44f9584e3a21440a804cff835a2c424 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 10 Jan 2023 21:32:22 +0100 Subject: [PATCH 3/9] replace by mongo panache --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index f40a5b9..3ec3057 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,10 @@ io.quarkus quarkus-redis-client + + io.quarkus + quarkus-mongodb-panache + io.quarkus quarkus-junit5 From 2cb02ca22351c2d997eb5ba2fbcc0aef1eed83a8 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 10 Jan 2023 22:08:23 +0100 Subject: [PATCH 4/9] set parameter for mongo --- src/main/resources/application.properties | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 34a392f..d80f3ea 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -32,4 +32,7 @@ quarkus.http.cors.headers=accept,authorization,content-type,x-requested-with,x-f quarkus.http.cors.access-control-allow-credentials=true #quarkus.native.additional-build-args=-H:IncludeResources=.*\\.pem,.\\*.txt -quarkus.native.additional-build-args=-H:ResourceConfigurationFiles=${RESOURCES:resource-config.json} \ No newline at end of file +quarkus.native.additional-build-args=-H:ResourceConfigurationFiles=${RESOURCES:resource-config.json} + +quarkus.mongodb.connection-string=mongodb://${MONGO_USER:admin}:${MONGO_PASSWORD:mongo}@${MONGO_HOST:mongo}:${MONGO_PORT:27017} +quarkus.mongodb.database = ${MONGO_DATABASE:admin}: \ No newline at end of file From 3c053b94eeb2d4238b083037ca6b403451025863 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 10 Jan 2023 22:14:29 +0100 Subject: [PATCH 5/9] add collection mongo event --- src/main/java/com/covas/Entity/EventEntity.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/main/java/com/covas/Entity/EventEntity.java diff --git a/src/main/java/com/covas/Entity/EventEntity.java b/src/main/java/com/covas/Entity/EventEntity.java new file mode 100644 index 0000000..dbe5f16 --- /dev/null +++ b/src/main/java/com/covas/Entity/EventEntity.java @@ -0,0 +1,13 @@ +package com.covas.Entity; + +import io.quarkus.mongodb.panache.PanacheMongoEntity; +import io.quarkus.mongodb.panache.common.MongoEntity; + +@MongoEntity(collection="event") +public class EventEntity extends PanacheMongoEntity { + + public String name; + + public Short status; + +} From 0803c18abba3cc311e97c3653c7d403ddcd0c659 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 11 Jan 2023 22:02:06 +0100 Subject: [PATCH 6/9] add event resources and test ok --- .../java/com/covas/Entity/EventEntity.java | 18 +- .../java/com/covas/Json/Organisateurs.java | 21 ++ .../covas/Resources/CommentRessources.java | 1 - .../com/covas/Resources/EventRessources.java | 294 ++++++++++++++++++ 4 files changed, 332 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/covas/Json/Organisateurs.java create mode 100644 src/main/java/com/covas/Resources/EventRessources.java diff --git a/src/main/java/com/covas/Entity/EventEntity.java b/src/main/java/com/covas/Entity/EventEntity.java index dbe5f16..b4b931b 100644 --- a/src/main/java/com/covas/Entity/EventEntity.java +++ b/src/main/java/com/covas/Entity/EventEntity.java @@ -1,5 +1,10 @@ package com.covas.Entity; +import java.time.LocalDateTime; +import java.util.Collection; + +import com.covas.Json.Organisateurs; + import io.quarkus.mongodb.panache.PanacheMongoEntity; import io.quarkus.mongodb.panache.common.MongoEntity; @@ -9,5 +14,16 @@ public class EventEntity extends PanacheMongoEntity { public String name; public Short status; - + + public String address; + + public Organisateurs organisateurs; + + public Collection participants; + + public Collection interesses; + + public LocalDateTime created_at; + public LocalDateTime updated_at; + public LocalDateTime deleted_at; } diff --git a/src/main/java/com/covas/Json/Organisateurs.java b/src/main/java/com/covas/Json/Organisateurs.java new file mode 100644 index 0000000..9f78890 --- /dev/null +++ b/src/main/java/com/covas/Json/Organisateurs.java @@ -0,0 +1,21 @@ +package com.covas.Json; + +import java.util.Collection; + +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +public class Organisateurs { + + public Collection users_id; + public Collection groups_id; + + public Organisateurs(){ + + } + + public Organisateurs(Collection users_id, Collection groups_id){ + this.users_id = users_id; + this.groups_id = groups_id; + } +} diff --git a/src/main/java/com/covas/Resources/CommentRessources.java b/src/main/java/com/covas/Resources/CommentRessources.java index c6e608f..e9f43f5 100644 --- a/src/main/java/com/covas/Resources/CommentRessources.java +++ b/src/main/java/com/covas/Resources/CommentRessources.java @@ -26,7 +26,6 @@ import javax.ws.rs.core.Response; import com.covas.Entity.CommentEntity; import com.covas.Entity.PublisherEntity; import com.covas.Entity.UsersEntity; -import com.covas.Json.PublisherByUser; import io.quarkus.panache.common.Page; import io.quarkus.panache.common.Parameters; diff --git a/src/main/java/com/covas/Resources/EventRessources.java b/src/main/java/com/covas/Resources/EventRessources.java new file mode 100644 index 0000000..9717e2b --- /dev/null +++ b/src/main/java/com/covas/Resources/EventRessources.java @@ -0,0 +1,294 @@ +package com.covas.Resources; + +import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; +import java.util.List; +import java.util.UUID; +import java.util.ArrayList; +import java.util.Collection; + + +import javax.annotation.security.RolesAllowed; +import javax.inject.Inject; +import javax.transaction.Transactional; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.Consumes; +import javax.ws.rs.CookieParam; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.PATCH; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import com.covas.Entity.CommentEntity; +import com.covas.Entity.EventEntity; +import com.covas.Entity.PublisherEntity; +import com.covas.Entity.UsersEntity; +import com.covas.Json.Organisateurs; + +import io.quarkus.panache.common.Page; +import io.quarkus.panache.common.Parameters; + +import org.eclipse.microprofile.jwt.Claims; +import org.eclipse.microprofile.jwt.JsonWebToken; +import org.jboss.logging.Logger; +import org.postgresql.shaded.com.ongres.scram.common.bouncycastle.base64.Base64; + +@Produces(MediaType.APPLICATION_JSON) +@Path("event") +public class EventRessources { + private static final Logger LOGGER = Logger.getLogger(UsersRessources.class); + @Inject + JsonWebToken jwt; + + /// Function + private Boolean checkUserCookie(String userCookie, UsersEntity users) { + if ((userCookie == null) || (users == null)) { + return false; + } + String name = new String(Base64.decode(userCookie), StandardCharsets.UTF_8); + if (!name.equals(users.pseudo) && (users.status != 1)) { + return false; + } + return true; + } + + private Response.Status getResponseCheck(SecurityContext ctx, String userCookie, UsersEntity users) { + if (!ctx.getUserPrincipal().getName().equals(jwt.getName())) { + return Response.Status.INTERNAL_SERVER_ERROR; + } + if (!checkUserCookie(userCookie, users)) { + return Response.Status.FORBIDDEN; + } + return Response.Status.OK; + } + + /// Appel HTTP + + + /// GET + @GET + @RolesAllowed("Admin") + public Response getComments(@CookieParam("user") String userCookie, @Context SecurityContext ctx, + @QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages, + @QueryParam("status") Short status, + @QueryParam("search") String search, + @QueryParam("uuid") String uuid) { + if(nbPages == null){ + nbPages = 20; + } + if(page == null){ + page = 0; + } + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status statusHttp = getResponseCheck(ctx, userCookie, user); + Response responseHttp = Response.status(statusHttp).build(); + if (statusHttp.equals(Response.Status.OK)) { + List listComments = CommentEntity.findAll().page(Page.of(page, nbPages)).list(); + + + responseHttp = Response.ok(listComments).build(); + if(uuid != null){ + CommentEntity commentSingle= PublisherEntity.findById(UUID.fromString(uuid)); + responseHttp = Response.ok(commentSingle).build(); + } + + if(search != null){ + List commentsList = CommentEntity.find("#Comment.bySearch", Parameters.with("comment", search)).page(Page.of(page, nbPages)).list(); + + responseHttp = Response.ok(commentsList).build(); + + } + } + return responseHttp; + } + + @GET + @RolesAllowed("Admin") + @Path("count") + public Response getCount(@CookieParam("user") String userCookie, @Context SecurityContext ctx){ + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + Response responseHttp = Response.status(status).build(); + if (status.equals(Response.Status.OK)){ + responseHttp = Response.ok(CommentEntity.count()).build(); + } + return responseHttp; + } + + @GET + @RolesAllowed("Admin") + @Path("{id}") + public Response getSingleComment(@PathParam("id") String id, @CookieParam("user") String userCookie, + @Context SecurityContext ctx) { + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + Response responseHttp = Response.status(status).build(); + if (status.equals(Response.Status.OK)) { + UUID uid = UUID.fromString(id); + CommentEntity comment = CommentEntity.findById(uid); + responseHttp = Response.status(Response.Status.NOT_FOUND).build(); + if (comment != null) { + responseHttp = Response.ok(comment).build(); + } + + } + return responseHttp; + } + + + // PUT + @PUT + @Consumes(MediaType.APPLICATION_JSON) + @RolesAllowed({"Admin", "User"}) + @Path("{id}") + @Transactional + public Response createComment(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, CommentEntity comment) { + + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + CommentEntity newComment = new CommentEntity(); + PublisherEntity publishers = PublisherEntity.findById(UUID.fromString(id)); + if (status.equals(Response.Status.OK)) { + newComment.comment = comment.comment; + newComment.users = user; + newComment.publishers = publishers; + newComment.created_at = LocalDateTime.now(); + newComment.updated_at = LocalDateTime.now(); + newComment.persist(); + if (newComment.isPersistent()) { + status = Response.Status.CREATED; + } else { + status = Response.Status.NO_CONTENT; + } + } + return Response.status(status).entity(newComment).build(); + } + + + // DELETE + @DELETE + @Path("{id}") + @RolesAllowed({"Admin", "User"}) + @Transactional + public Response changeStatusSingleCommentToDelete(@Context SecurityContext ctx, @CookieParam("user") String userCookie, + @PathParam("id") String id) { + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + if (status.equals(Response.Status.OK)) { + CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult(); + if (singleComment == null) { + status = Response.Status.NOT_FOUND; + } else { + singleComment.status = -1; + singleComment.updated_at = LocalDateTime.now(); + singleComment.deleted_at = LocalDateTime.now(); + singleComment.persist(); + if (!singleComment.isPersistent()) { + status = Response.Status.NOT_MODIFIED; + } + } + } + return Response.status(status).build(); + } + + @DELETE + @Path("/disable/{id}") + @RolesAllowed({"Admin", "User"}) + @Transactional + public Response changeStatusSingleCommentToDisable(@Context SecurityContext ctx, @CookieParam("user") String userCookie, + @PathParam("id") String id) { + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + if (status.equals(Response.Status.OK)) { + CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult(); + if (singleComment == null) { + status = Response.Status.NOT_FOUND; + } else { + singleComment.status = 0; + singleComment.updated_at = LocalDateTime.now(); + singleComment.deleted_at = LocalDateTime.now(); + singleComment.persist(); + if (!singleComment.isPersistent()) { + status = Response.Status.NOT_MODIFIED; + } + } + } + return Response.status(status).build(); + } + + // PATCH + @PATCH + @RolesAllowed({"Admin", "User"}) + @Consumes(MediaType.APPLICATION_JSON) + @Transactional + @Path("{id}") + public Response updateCommentAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, + CommentEntity comment, @PathParam("id") String id) { + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + + if (status.equals(Response.Status.OK)) { + + CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id)); + if (commentOrig == null) { + status = Response.Status.NOT_FOUND; + } else { + commentOrig.comment = comment.comment; + + + commentOrig.updated_at = LocalDateTime.now(); + + if(comment.status == 1){ + commentOrig.deleted_at = null; + commentOrig.status = 1; + } + commentOrig.persist(); + if (!commentOrig.isPersistent()) { + status = Response.Status.NOT_MODIFIED; + } + } + } + return Response.status(status).build(); + } + + + + @PATCH + @RolesAllowed({"Admin", "User"}) + @Consumes(MediaType.APPLICATION_JSON) + @Transactional + @Path("enable/{id}") + public Response enableCommentAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id) { + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + if (status.equals(Response.Status.OK)) { + + CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id)); + if (commentOrig == null) { + status = Response.Status.NOT_FOUND; + } else { + commentOrig.status = 1; + commentOrig.persist(); + if (!commentOrig.isPersistent()) { + status = Response.Status.NOT_MODIFIED; + } + } + } + return Response.status(status).build(); + } +} From 92f1eb8217929defce30e6ae0c7dd94b2e5d2bb2 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 12 Jan 2023 22:43:48 +0100 Subject: [PATCH 7/9] get and put --- .../com/covas/Resources/EventRessources.java | 51 ++++++++----------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/covas/Resources/EventRessources.java b/src/main/java/com/covas/Resources/EventRessources.java index 9717e2b..8c7c18e 100644 --- a/src/main/java/com/covas/Resources/EventRessources.java +++ b/src/main/java/com/covas/Resources/EventRessources.java @@ -33,8 +33,8 @@ import com.covas.Entity.UsersEntity; import com.covas.Json.Organisateurs; import io.quarkus.panache.common.Page; -import io.quarkus.panache.common.Parameters; +import org.bson.types.ObjectId; import org.eclipse.microprofile.jwt.Claims; import org.eclipse.microprofile.jwt.JsonWebToken; import org.jboss.logging.Logger; @@ -91,20 +91,18 @@ public class EventRessources { Response.Status statusHttp = getResponseCheck(ctx, userCookie, user); Response responseHttp = Response.status(statusHttp).build(); if (statusHttp.equals(Response.Status.OK)) { - List listComments = CommentEntity.findAll().page(Page.of(page, nbPages)).list(); + List listEvents = EventEntity.findAll().page(Page.of(page, nbPages)).list(); - responseHttp = Response.ok(listComments).build(); + responseHttp = Response.ok(listEvents).build(); if(uuid != null){ - CommentEntity commentSingle= PublisherEntity.findById(UUID.fromString(uuid)); - responseHttp = Response.ok(commentSingle).build(); + EventEntity eventSingle= EventEntity.findById(new ObjectId(uuid)); + responseHttp = Response.ok(eventSingle).build(); } if(search != null){ - List commentsList = CommentEntity.find("#Comment.bySearch", Parameters.with("comment", search)).page(Page.of(page, nbPages)).list(); - - responseHttp = Response.ok(commentsList).build(); - + List eventsList = EventEntity.find("name", search).page(Page.of(page, nbPages)).list(); + responseHttp = Response.ok(eventsList).build(); } } return responseHttp; @@ -119,7 +117,7 @@ public class EventRessources { Response.Status status = getResponseCheck(ctx, userCookie, user); Response responseHttp = Response.status(status).build(); if (status.equals(Response.Status.OK)){ - responseHttp = Response.ok(CommentEntity.count()).build(); + responseHttp = Response.ok(EventEntity.count()).build(); } return responseHttp; } @@ -134,11 +132,10 @@ public class EventRessources { Response.Status status = getResponseCheck(ctx, userCookie, user); Response responseHttp = Response.status(status).build(); if (status.equals(Response.Status.OK)) { - UUID uid = UUID.fromString(id); - CommentEntity comment = CommentEntity.findById(uid); + EventEntity event = EventEntity.findById(new ObjectId(id)); responseHttp = Response.status(Response.Status.NOT_FOUND).build(); - if (comment != null) { - responseHttp = Response.ok(comment).build(); + if (event != null) { + responseHttp = Response.ok(event).build(); } } @@ -152,27 +149,23 @@ public class EventRessources { @RolesAllowed({"Admin", "User"}) @Path("{id}") @Transactional - public Response createComment(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, CommentEntity comment) { + public Response createComment(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, EventEntity event) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user); - CommentEntity newComment = new CommentEntity(); - PublisherEntity publishers = PublisherEntity.findById(UUID.fromString(id)); + EventEntity newEvent = new EventEntity(); if (status.equals(Response.Status.OK)) { - newComment.comment = comment.comment; - newComment.users = user; - newComment.publishers = publishers; - newComment.created_at = LocalDateTime.now(); - newComment.updated_at = LocalDateTime.now(); - newComment.persist(); - if (newComment.isPersistent()) { - status = Response.Status.CREATED; - } else { - status = Response.Status.NO_CONTENT; - } + newEvent.name = event.name; + newEvent.address = event.address; + newEvent.organisateurs = event.organisateurs; + newEvent.created_at = LocalDateTime.now(); + newEvent.updated_at = LocalDateTime.now(); + newEvent.persist(); + status = Response.Status.CREATED; + } - return Response.status(status).entity(newComment).build(); + return Response.status(status).entity(newEvent).build(); } From 3881009353a840170ae85b073475148df7dc1ef1 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 14 Jan 2023 21:14:07 +0100 Subject: [PATCH 8/9] update resources event --- .../com/covas/Resources/EventRessources.java | 63 ++++++++----------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/covas/Resources/EventRessources.java b/src/main/java/com/covas/Resources/EventRessources.java index 8c7c18e..e86f0fe 100644 --- a/src/main/java/com/covas/Resources/EventRessources.java +++ b/src/main/java/com/covas/Resources/EventRessources.java @@ -180,17 +180,14 @@ public class EventRessources { UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user); if (status.equals(Response.Status.OK)) { - CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult(); - if (singleComment == null) { + EventEntity singleEvent = EventEntity.find("id", new ObjectId(id)).firstResult(); + if (singleEvent == null) { status = Response.Status.NOT_FOUND; } else { - singleComment.status = -1; - singleComment.updated_at = LocalDateTime.now(); - singleComment.deleted_at = LocalDateTime.now(); - singleComment.persist(); - if (!singleComment.isPersistent()) { - status = Response.Status.NOT_MODIFIED; - } + singleEvent.status = -1; + singleEvent.updated_at = LocalDateTime.now(); + singleEvent.deleted_at = LocalDateTime.now(); + singleEvent.persist(); } } return Response.status(status).build(); @@ -206,17 +203,14 @@ public class EventRessources { UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user); if (status.equals(Response.Status.OK)) { - CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult(); - if (singleComment == null) { + EventEntity singleEvent = EventEntity.find("id", new ObjectId(id)).firstResult(); + if (singleEvent == null) { status = Response.Status.NOT_FOUND; } else { - singleComment.status = 0; - singleComment.updated_at = LocalDateTime.now(); - singleComment.deleted_at = LocalDateTime.now(); - singleComment.persist(); - if (!singleComment.isPersistent()) { - status = Response.Status.NOT_MODIFIED; - } + singleEvent.status = 0; + singleEvent.updated_at = LocalDateTime.now(); + singleEvent.deleted_at = LocalDateTime.now(); + singleEvent.persist(); } } return Response.status(status).build(); @@ -229,30 +223,28 @@ public class EventRessources { @Transactional @Path("{id}") public Response updateCommentAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, - CommentEntity comment, @PathParam("id") String id) { + EventEntity event, @PathParam("id") String id) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user); if (status.equals(Response.Status.OK)) { - CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id)); - if (commentOrig == null) { + EventEntity eventOrig = EventEntity.findById(new ObjectId(id)); + if (eventOrig == null) { status = Response.Status.NOT_FOUND; } else { - commentOrig.comment = comment.comment; + eventOrig.name = event.name; - commentOrig.updated_at = LocalDateTime.now(); + eventOrig.updated_at = LocalDateTime.now(); - if(comment.status == 1){ - commentOrig.deleted_at = null; - commentOrig.status = 1; - } - commentOrig.persist(); - if (!commentOrig.isPersistent()) { - status = Response.Status.NOT_MODIFIED; + if(event.status == 1){ + eventOrig.deleted_at = null; + eventOrig.status = 1; } + eventOrig.persist(); + } } return Response.status(status).build(); @@ -271,15 +263,12 @@ public class EventRessources { Response.Status status = getResponseCheck(ctx, userCookie, user); if (status.equals(Response.Status.OK)) { - CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id)); - if (commentOrig == null) { + EventEntity eventOrig = EventEntity.findById(new ObjectId(id)); + if (eventOrig == null) { status = Response.Status.NOT_FOUND; } else { - commentOrig.status = 1; - commentOrig.persist(); - if (!commentOrig.isPersistent()) { - status = Response.Status.NOT_MODIFIED; - } + eventOrig.status = 1; + eventOrig.persist(); } } return Response.status(status).build(); From 8aadc04fd57fc31fc81e0c870959aa4fa46c324f Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 14 Jan 2023 21:16:27 +0100 Subject: [PATCH 9/9] change name function --- .../java/com/covas/Resources/EventRessources.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/covas/Resources/EventRessources.java b/src/main/java/com/covas/Resources/EventRessources.java index e86f0fe..b21c8ac 100644 --- a/src/main/java/com/covas/Resources/EventRessources.java +++ b/src/main/java/com/covas/Resources/EventRessources.java @@ -75,7 +75,7 @@ public class EventRessources { /// GET @GET @RolesAllowed("Admin") - public Response getComments(@CookieParam("user") String userCookie, @Context SecurityContext ctx, + public Response getEvents(@CookieParam("user") String userCookie, @Context SecurityContext ctx, @QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages, @QueryParam("status") Short status, @QueryParam("search") String search, @@ -125,7 +125,7 @@ public class EventRessources { @GET @RolesAllowed("Admin") @Path("{id}") - public Response getSingleComment(@PathParam("id") String id, @CookieParam("user") String userCookie, + public Response getSingleEvent(@PathParam("id") String id, @CookieParam("user") String userCookie, @Context SecurityContext ctx) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); @@ -149,7 +149,7 @@ public class EventRessources { @RolesAllowed({"Admin", "User"}) @Path("{id}") @Transactional - public Response createComment(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, EventEntity event) { + public Response createEvent(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, EventEntity event) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); @@ -174,7 +174,7 @@ public class EventRessources { @Path("{id}") @RolesAllowed({"Admin", "User"}) @Transactional - public Response changeStatusSingleCommentToDelete(@Context SecurityContext ctx, @CookieParam("user") String userCookie, + public Response changeStatusSingleEventToDelete(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); @@ -197,7 +197,7 @@ public class EventRessources { @Path("/disable/{id}") @RolesAllowed({"Admin", "User"}) @Transactional - public Response changeStatusSingleCommentToDisable(@Context SecurityContext ctx, @CookieParam("user") String userCookie, + public Response changeStatusSingleEventToDisable(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); @@ -222,7 +222,7 @@ public class EventRessources { @Consumes(MediaType.APPLICATION_JSON) @Transactional @Path("{id}") - public Response updateCommentAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, + public Response updateEvent(@Context SecurityContext ctx, @CookieParam("user") String userCookie, EventEntity event, @PathParam("id") String id) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); @@ -257,7 +257,7 @@ public class EventRessources { @Consumes(MediaType.APPLICATION_JSON) @Transactional @Path("enable/{id}") - public Response enableCommentAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id) { + public Response enableEvent(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user);