diff --git a/src/main/java/com/covas/Json/MessageByUser.java b/src/main/java/com/covas/Json/MessageByUser.java new file mode 100644 index 0000000..4c02497 --- /dev/null +++ b/src/main/java/com/covas/Json/MessageByUser.java @@ -0,0 +1,22 @@ +package com.covas.Json; + +import java.util.Collection; + +import com.covas.Entity.MessageEntity; + +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +public class MessageByUser { + + public final String pseudo; + public final Collection message; + + public MessageByUser(String pseudo, Collection message){ + this.pseudo = pseudo; + this.message = message; + + + } + +} diff --git a/src/main/java/com/covas/Resources/MessageRessources.java b/src/main/java/com/covas/Resources/MessageRessources.java index 1623190..eddb47c 100644 --- a/src/main/java/com/covas/Resources/MessageRessources.java +++ b/src/main/java/com/covas/Resources/MessageRessources.java @@ -27,6 +27,7 @@ import com.covas.Entity.CommentEntity; import com.covas.Entity.MessageEntity; import com.covas.Entity.PublisherEntity; import com.covas.Entity.UsersEntity; +import com.covas.Json.MessageByUser; import io.quarkus.panache.common.Page; import io.quarkus.panache.common.Parameters; @@ -140,6 +141,31 @@ public class MessageRessources { return responseHttp; } + @GET + @RolesAllowed("User") + @Path("info") + public Response getInfoMessage(@Context SecurityContext ctx, @CookieParam("user") String userCookie) { + 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)) { + if (user == null) { + status = Response.Status.NOT_FOUND; + } + if (!checkUserCookie(userCookie, user)) { + status = Response.Status.FORBIDDEN; + } + } + Response responseHttp = Response.status(status).build(); + + if (status.equals(Response.Status.OK)) { + responseHttp = Response.status(status).entity(new MessageByUser(user.pseudo, user.message)) + .build(); + } + return responseHttp; + } + + // PUT @PUT