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