resources comment work

This commit is contained in:
Valentin CZERYBA 2023-01-09 22:08:44 +01:00
parent 9233c16656
commit fecd1799a2

View File

@ -182,15 +182,15 @@ public class CommentRessources {
UsersEntity user = UsersEntity.findById(kid); UsersEntity user = UsersEntity.findById(kid);
Response.Status status = getResponseCheck(ctx, userCookie, user); Response.Status status = getResponseCheck(ctx, userCookie, user);
if (status.equals(Response.Status.OK)) { if (status.equals(Response.Status.OK)) {
PublisherEntity singlePublisher = PublisherEntity.find("id", UUID.fromString(id)).firstResult(); CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult();
if (singlePublisher == null) { if (singleComment == null) {
status = Response.Status.NOT_FOUND; status = Response.Status.NOT_FOUND;
} else { } else {
singlePublisher.status = -1; singleComment.status = -1;
singlePublisher.updated_at = LocalDateTime.now(); singleComment.updated_at = LocalDateTime.now();
singlePublisher.deleted_at = LocalDateTime.now(); singleComment.deleted_at = LocalDateTime.now();
singlePublisher.persist(); singleComment.persist();
if (!singlePublisher.isPersistent()) { if (!singleComment.isPersistent()) {
status = Response.Status.NOT_MODIFIED; status = Response.Status.NOT_MODIFIED;
} }
} }
@ -208,15 +208,15 @@ public class CommentRessources {
UsersEntity user = UsersEntity.findById(kid); UsersEntity user = UsersEntity.findById(kid);
Response.Status status = getResponseCheck(ctx, userCookie, user); Response.Status status = getResponseCheck(ctx, userCookie, user);
if (status.equals(Response.Status.OK)) { if (status.equals(Response.Status.OK)) {
PublisherEntity singlePublisher = PublisherEntity.find("id", UUID.fromString(id)).firstResult(); CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult();
if (singlePublisher == null) { if (singleComment == null) {
status = Response.Status.NOT_FOUND; status = Response.Status.NOT_FOUND;
} else { } else {
singlePublisher.status = 0; singleComment.status = 0;
singlePublisher.updated_at = LocalDateTime.now(); singleComment.updated_at = LocalDateTime.now();
singlePublisher.deleted_at = LocalDateTime.now(); singleComment.deleted_at = LocalDateTime.now();
singlePublisher.persist(); singleComment.persist();
if (!singlePublisher.isPersistent()) { if (!singleComment.isPersistent()) {
status = Response.Status.NOT_MODIFIED; status = Response.Status.NOT_MODIFIED;
} }
} }
@ -231,29 +231,28 @@ public class CommentRessources {
@Transactional @Transactional
@Path("{id}") @Path("{id}")
public Response updatePublisherAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, 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)); UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
UsersEntity user = UsersEntity.findById(kid); UsersEntity user = UsersEntity.findById(kid);
Response.Status status = getResponseCheck(ctx, userCookie, user); Response.Status status = getResponseCheck(ctx, userCookie, user);
if (status.equals(Response.Status.OK)) { if (status.equals(Response.Status.OK)) {
PublisherEntity publishersOrig = PublisherEntity.findById(UUID.fromString(id)); CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id));
if (publishersOrig == null) { if (commentOrig == null) {
status = Response.Status.NOT_FOUND; status = Response.Status.NOT_FOUND;
} else { } else {
publishersOrig.description = publishers.description; commentOrig.comment = comment.comment;
publishersOrig.url = publishers.url;
publishersOrig.type = publishers.type;
publishersOrig.updated_at = LocalDateTime.now();
if(publishers.status == 1){ commentOrig.updated_at = LocalDateTime.now();
publishersOrig.deleted_at = null;
publishersOrig.status = 1; if(comment.status == 1){
commentOrig.deleted_at = null;
commentOrig.status = 1;
} }
publishersOrig.persist(); commentOrig.persist();
if (!publishersOrig.isPersistent()) { if (!commentOrig.isPersistent()) {
status = Response.Status.NOT_MODIFIED; status = Response.Status.NOT_MODIFIED;
} }
} }
@ -274,13 +273,13 @@ public class CommentRessources {
Response.Status status = getResponseCheck(ctx, userCookie, user); Response.Status status = getResponseCheck(ctx, userCookie, user);
if (status.equals(Response.Status.OK)) { if (status.equals(Response.Status.OK)) {
PublisherEntity publishersOrig = PublisherEntity.findById(UUID.fromString(id)); CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id));
if (publishersOrig == null) { if (commentOrig == null) {
status = Response.Status.NOT_FOUND; status = Response.Status.NOT_FOUND;
} else { } else {
publishersOrig.status = 1; commentOrig.status = 1;
publishersOrig.persist(); commentOrig.persist();
if (!publishersOrig.isPersistent()) { if (!commentOrig.isPersistent()) {
status = Response.Status.NOT_MODIFIED; status = Response.Status.NOT_MODIFIED;
} }
} }