From 0dba06a39b21f6bb05cf49cc1a9c7434afc1e58e Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 29 Jan 2023 21:20:27 +0100 Subject: [PATCH] message resources wip --- .../covas/Resources/CommentRessources.java | 2 +- .../covas/Resources/MessageRessources.java | 27 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/covas/Resources/CommentRessources.java b/src/main/java/com/covas/Resources/CommentRessources.java index e9f43f5..de778ba 100644 --- a/src/main/java/com/covas/Resources/CommentRessources.java +++ b/src/main/java/com/covas/Resources/CommentRessources.java @@ -90,7 +90,7 @@ public class CommentRessources { responseHttp = Response.ok(listComments).build(); if(uuid != null){ - CommentEntity commentSingle= PublisherEntity.findById(UUID.fromString(uuid)); + CommentEntity commentSingle = CommentEntity.findById(UUID.fromString(uuid)); responseHttp = Response.ok(commentSingle).build(); } diff --git a/src/main/java/com/covas/Resources/MessageRessources.java b/src/main/java/com/covas/Resources/MessageRessources.java index f48ecd3..3e48686 100644 --- a/src/main/java/com/covas/Resources/MessageRessources.java +++ b/src/main/java/com/covas/Resources/MessageRessources.java @@ -24,6 +24,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import com.covas.Entity.CommentEntity; +import com.covas.Entity.MessageEntity; import com.covas.Entity.PublisherEntity; import com.covas.Entity.UsersEntity; @@ -36,7 +37,7 @@ import org.jboss.logging.Logger; import org.postgresql.shaded.com.ongres.scram.common.bouncycastle.base64.Base64; @Produces(MediaType.APPLICATION_JSON) -@Path("mewsage") +@Path("message") public class MessageRessources { private static final Logger LOGGER = Logger.getLogger(UsersRessources.class); @Inject @@ -69,7 +70,7 @@ public class MessageRessources { /// GET @GET @RolesAllowed("Admin") - public Response getComments(@CookieParam("user") String userCookie, @Context SecurityContext ctx, + public Response getMessages(@CookieParam("user") String userCookie, @Context SecurityContext ctx, @QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages, @QueryParam("status") Short status, @QueryParam("search") String search, @@ -85,19 +86,19 @@ public class MessageRessources { Response.Status statusHttp = getResponseCheck(ctx, userCookie, user); Response responseHttp = Response.status(statusHttp).build(); if (statusHttp.equals(Response.Status.OK)) { - List listComments = CommentEntity.findAll().page(Page.of(page, nbPages)).list(); + List listMessages = MessageEntity.findAll().page(Page.of(page, nbPages)).list(); - responseHttp = Response.ok(listComments).build(); + responseHttp = Response.ok(listMessages).build(); if(uuid != null){ - CommentEntity commentSingle= PublisherEntity.findById(UUID.fromString(uuid)); - responseHttp = Response.ok(commentSingle).build(); + MessageEntity messageEntity= MessageEntity.findById(UUID.fromString(uuid)); + responseHttp = Response.ok(messageEntity).build(); } if(search != null){ - List commentsList = CommentEntity.find("#Comment.bySearch", Parameters.with("comment", search)).page(Page.of(page, nbPages)).list(); + List messagesList = MessageEntity.find("#Message.bySearch", Parameters.with("content", search)).page(Page.of(page, nbPages)).list(); - responseHttp = Response.ok(commentsList).build(); + responseHttp = Response.ok(messagesList).build(); } } @@ -113,7 +114,7 @@ public class MessageRessources { Response.Status status = getResponseCheck(ctx, userCookie, user); Response responseHttp = Response.status(status).build(); if (status.equals(Response.Status.OK)){ - responseHttp = Response.ok(CommentEntity.count()).build(); + responseHttp = Response.ok(MessageEntity.count()).build(); } return responseHttp; } @@ -121,7 +122,7 @@ public class MessageRessources { @GET @RolesAllowed("Admin") @Path("{id}") - public Response getSingleComment(@PathParam("id") String id, @CookieParam("user") String userCookie, + public Response getSingleMessage(@PathParam("id") String id, @CookieParam("user") String userCookie, @Context SecurityContext ctx) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); @@ -129,10 +130,10 @@ public class MessageRessources { Response responseHttp = Response.status(status).build(); if (status.equals(Response.Status.OK)) { UUID uid = UUID.fromString(id); - CommentEntity comment = CommentEntity.findById(uid); + MessageEntity message = MessageEntity.findById(uid); responseHttp = Response.status(Response.Status.NOT_FOUND).build(); - if (comment != null) { - responseHttp = Response.ok(comment).build(); + if (message != null) { + responseHttp = Response.ok(message).build(); } }