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); 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)) {
CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult(); EventEntity singleEvent = EventEntity.find("id", new ObjectId(id)).firstResult();
if (singleComment == null) { if (singleEvent == null) {
status = Response.Status.NOT_FOUND; status = Response.Status.NOT_FOUND;
} else { } else {
singleComment.status = -1; singleEvent.status = -1;
singleComment.updated_at = LocalDateTime.now(); singleEvent.updated_at = LocalDateTime.now();
singleComment.deleted_at = LocalDateTime.now(); singleEvent.deleted_at = LocalDateTime.now();
singleComment.persist(); singleEvent.persist();
if (!singleComment.isPersistent()) {
status = Response.Status.NOT_MODIFIED;
}
} }
} }
return Response.status(status).build(); return Response.status(status).build();
@ -206,17 +203,14 @@ public class EventRessources {
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)) {
CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult(); EventEntity singleEvent = EventEntity.find("id", new ObjectId(id)).firstResult();
if (singleComment == null) { if (singleEvent == null) {
status = Response.Status.NOT_FOUND; status = Response.Status.NOT_FOUND;
} else { } else {
singleComment.status = 0; singleEvent.status = 0;
singleComment.updated_at = LocalDateTime.now(); singleEvent.updated_at = LocalDateTime.now();
singleComment.deleted_at = LocalDateTime.now(); singleEvent.deleted_at = LocalDateTime.now();
singleComment.persist(); singleEvent.persist();
if (!singleComment.isPersistent()) {
status = Response.Status.NOT_MODIFIED;
}
} }
} }
return Response.status(status).build(); return Response.status(status).build();
@ -229,30 +223,28 @@ public class EventRessources {
@Transactional @Transactional
@Path("{id}") @Path("{id}")
public Response updateCommentAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, 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)); 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)) {
CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id)); EventEntity eventOrig = EventEntity.findById(new ObjectId(id));
if (commentOrig == null) { if (eventOrig == null) {
status = Response.Status.NOT_FOUND; status = Response.Status.NOT_FOUND;
} else { } else {
commentOrig.comment = comment.comment; eventOrig.name = event.name;
commentOrig.updated_at = LocalDateTime.now(); eventOrig.updated_at = LocalDateTime.now();
if(comment.status == 1){ if(event.status == 1){
commentOrig.deleted_at = null; eventOrig.deleted_at = null;
commentOrig.status = 1; eventOrig.status = 1;
}
commentOrig.persist();
if (!commentOrig.isPersistent()) {
status = Response.Status.NOT_MODIFIED;
} }
eventOrig.persist();
} }
} }
return Response.status(status).build(); return Response.status(status).build();
@ -271,15 +263,12 @@ public class EventRessources {
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)) {
CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id)); EventEntity eventOrig = EventEntity.findById(new ObjectId(id));
if (commentOrig == null) { if (eventOrig == null) {
status = Response.Status.NOT_FOUND; status = Response.Status.NOT_FOUND;
} else { } else {
commentOrig.status = 1; eventOrig.status = 1;
commentOrig.persist(); eventOrig.persist();
if (!commentOrig.isPersistent()) {
status = Response.Status.NOT_MODIFIED;
}
} }
} }
return Response.status(status).build(); return Response.status(status).build();