From 3881009353a840170ae85b073475148df7dc1ef1 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 14 Jan 2023 21:14:07 +0100 Subject: [PATCH] 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();