update resources event

This commit is contained in:
Valentin CZERYBA 2023-01-14 21:14:07 +01:00
parent 92f1eb8217
commit 3881009353

View File

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