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(); }