From fecd1799a2f24a41873d681080e6d9b98456934a Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 9 Jan 2023 22:08:44 +0100 Subject: [PATCH] resources comment work --- .../covas/Resources/CommentRessources.java | 61 +++++++++---------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/covas/Resources/CommentRessources.java b/src/main/java/com/covas/Resources/CommentRessources.java index 76f729f..b988191 100644 --- a/src/main/java/com/covas/Resources/CommentRessources.java +++ b/src/main/java/com/covas/Resources/CommentRessources.java @@ -182,15 +182,15 @@ public class CommentRessources { UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user); if (status.equals(Response.Status.OK)) { - PublisherEntity singlePublisher = PublisherEntity.find("id", UUID.fromString(id)).firstResult(); - if (singlePublisher == null) { + CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult(); + if (singleComment == null) { status = Response.Status.NOT_FOUND; } else { - singlePublisher.status = -1; - singlePublisher.updated_at = LocalDateTime.now(); - singlePublisher.deleted_at = LocalDateTime.now(); - singlePublisher.persist(); - if (!singlePublisher.isPersistent()) { + singleComment.status = -1; + singleComment.updated_at = LocalDateTime.now(); + singleComment.deleted_at = LocalDateTime.now(); + singleComment.persist(); + if (!singleComment.isPersistent()) { status = Response.Status.NOT_MODIFIED; } } @@ -208,15 +208,15 @@ public class CommentRessources { UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user); if (status.equals(Response.Status.OK)) { - PublisherEntity singlePublisher = PublisherEntity.find("id", UUID.fromString(id)).firstResult(); - if (singlePublisher == null) { + CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult(); + if (singleComment == null) { status = Response.Status.NOT_FOUND; } else { - singlePublisher.status = 0; - singlePublisher.updated_at = LocalDateTime.now(); - singlePublisher.deleted_at = LocalDateTime.now(); - singlePublisher.persist(); - if (!singlePublisher.isPersistent()) { + singleComment.status = 0; + singleComment.updated_at = LocalDateTime.now(); + singleComment.deleted_at = LocalDateTime.now(); + singleComment.persist(); + if (!singleComment.isPersistent()) { status = Response.Status.NOT_MODIFIED; } } @@ -231,29 +231,28 @@ public class CommentRessources { @Transactional @Path("{id}") public Response updatePublisherAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, - PublisherEntity publishers, @PathParam("id") String id) { + 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)) { - PublisherEntity publishersOrig = PublisherEntity.findById(UUID.fromString(id)); - if (publishersOrig == null) { + CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id)); + if (commentOrig == null) { status = Response.Status.NOT_FOUND; } else { - publishersOrig.description = publishers.description; - publishersOrig.url = publishers.url; - publishersOrig.type = publishers.type; + commentOrig.comment = comment.comment; - publishersOrig.updated_at = LocalDateTime.now(); - if(publishers.status == 1){ - publishersOrig.deleted_at = null; - publishersOrig.status = 1; + commentOrig.updated_at = LocalDateTime.now(); + + if(comment.status == 1){ + commentOrig.deleted_at = null; + commentOrig.status = 1; } - publishersOrig.persist(); - if (!publishersOrig.isPersistent()) { + commentOrig.persist(); + if (!commentOrig.isPersistent()) { status = Response.Status.NOT_MODIFIED; } } @@ -274,13 +273,13 @@ public class CommentRessources { Response.Status status = getResponseCheck(ctx, userCookie, user); if (status.equals(Response.Status.OK)) { - PublisherEntity publishersOrig = PublisherEntity.findById(UUID.fromString(id)); - if (publishersOrig == null) { + CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id)); + if (commentOrig == null) { status = Response.Status.NOT_FOUND; } else { - publishersOrig.status = 1; - publishersOrig.persist(); - if (!publishersOrig.isPersistent()) { + commentOrig.status = 1; + commentOrig.persist(); + if (!commentOrig.isPersistent()) { status = Response.Status.NOT_MODIFIED; } }