message by user

This commit is contained in:
Valentin CZERYBA 2023-01-30 22:49:04 +01:00
parent 905fc40851
commit a88079f5fa
2 changed files with 48 additions and 0 deletions

View File

@ -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<MessageEntity> message;
public MessageByUser(String pseudo, Collection<MessageEntity> message){
this.pseudo = pseudo;
this.message = message;
}
}

View File

@ -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