message resources wip

This commit is contained in:
Valentin CZERYBA 2023-01-29 21:20:27 +01:00
parent 90ba63afd5
commit 0dba06a39b
2 changed files with 15 additions and 14 deletions

View File

@ -90,7 +90,7 @@ public class CommentRessources {
responseHttp = Response.ok(listComments).build(); responseHttp = Response.ok(listComments).build();
if(uuid != null){ if(uuid != null){
CommentEntity commentSingle= PublisherEntity.findById(UUID.fromString(uuid)); CommentEntity commentSingle = CommentEntity.findById(UUID.fromString(uuid));
responseHttp = Response.ok(commentSingle).build(); responseHttp = Response.ok(commentSingle).build();
} }

View File

@ -24,6 +24,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import com.covas.Entity.CommentEntity; import com.covas.Entity.CommentEntity;
import com.covas.Entity.MessageEntity;
import com.covas.Entity.PublisherEntity; import com.covas.Entity.PublisherEntity;
import com.covas.Entity.UsersEntity; 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; import org.postgresql.shaded.com.ongres.scram.common.bouncycastle.base64.Base64;
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("mewsage") @Path("message")
public class MessageRessources { public class MessageRessources {
private static final Logger LOGGER = Logger.getLogger(UsersRessources.class); private static final Logger LOGGER = Logger.getLogger(UsersRessources.class);
@Inject @Inject
@ -69,7 +70,7 @@ public class MessageRessources {
/// GET /// GET
@GET @GET
@RolesAllowed("Admin") @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("page") Integer page, @QueryParam("nbPages") Integer nbPages,
@QueryParam("status") Short status, @QueryParam("status") Short status,
@QueryParam("search") String search, @QueryParam("search") String search,
@ -85,19 +86,19 @@ public class MessageRessources {
Response.Status statusHttp = getResponseCheck(ctx, userCookie, user); Response.Status statusHttp = getResponseCheck(ctx, userCookie, user);
Response responseHttp = Response.status(statusHttp).build(); Response responseHttp = Response.status(statusHttp).build();
if (statusHttp.equals(Response.Status.OK)) { if (statusHttp.equals(Response.Status.OK)) {
List<CommentEntity> listComments = CommentEntity.findAll().page(Page.of(page, nbPages)).list(); List<MessageEntity> listMessages = MessageEntity.findAll().page(Page.of(page, nbPages)).list();
responseHttp = Response.ok(listComments).build(); responseHttp = Response.ok(listMessages).build();
if(uuid != null){ if(uuid != null){
CommentEntity commentSingle= PublisherEntity.findById(UUID.fromString(uuid)); MessageEntity messageEntity= MessageEntity.findById(UUID.fromString(uuid));
responseHttp = Response.ok(commentSingle).build(); responseHttp = Response.ok(messageEntity).build();
} }
if(search != null){ if(search != null){
List<CommentEntity> commentsList = CommentEntity.find("#Comment.bySearch", Parameters.with("comment", search)).page(Page.of(page, nbPages)).list(); List<MessageEntity> 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.Status status = getResponseCheck(ctx, userCookie, user);
Response responseHttp = Response.status(status).build(); Response responseHttp = Response.status(status).build();
if (status.equals(Response.Status.OK)){ if (status.equals(Response.Status.OK)){
responseHttp = Response.ok(CommentEntity.count()).build(); responseHttp = Response.ok(MessageEntity.count()).build();
} }
return responseHttp; return responseHttp;
} }
@ -121,7 +122,7 @@ public class MessageRessources {
@GET @GET
@RolesAllowed("Admin") @RolesAllowed("Admin")
@Path("{id}") @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) { @Context SecurityContext ctx) {
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);
@ -129,10 +130,10 @@ public class MessageRessources {
Response responseHttp = Response.status(status).build(); Response responseHttp = Response.status(status).build();
if (status.equals(Response.Status.OK)) { if (status.equals(Response.Status.OK)) {
UUID uid = UUID.fromString(id); UUID uid = UUID.fromString(id);
CommentEntity comment = CommentEntity.findById(uid); MessageEntity message = MessageEntity.findById(uid);
responseHttp = Response.status(Response.Status.NOT_FOUND).build(); responseHttp = Response.status(Response.Status.NOT_FOUND).build();
if (comment != null) { if (message != null) {
responseHttp = Response.ok(comment).build(); responseHttp = Response.ok(message).build();
} }
} }