get and put

This commit is contained in:
Valentin CZERYBA 2023-01-12 22:43:48 +01:00
parent 0803c18abb
commit 92f1eb8217

View File

@ -33,8 +33,8 @@ import com.covas.Entity.UsersEntity;
import com.covas.Json.Organisateurs; import com.covas.Json.Organisateurs;
import io.quarkus.panache.common.Page; import io.quarkus.panache.common.Page;
import io.quarkus.panache.common.Parameters;
import org.bson.types.ObjectId;
import org.eclipse.microprofile.jwt.Claims; import org.eclipse.microprofile.jwt.Claims;
import org.eclipse.microprofile.jwt.JsonWebToken; import org.eclipse.microprofile.jwt.JsonWebToken;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -91,20 +91,18 @@ public class EventRessources {
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<EventEntity> listEvents = EventEntity.findAll().page(Page.of(page, nbPages)).list();
responseHttp = Response.ok(listComments).build(); responseHttp = Response.ok(listEvents).build();
if(uuid != null){ if(uuid != null){
CommentEntity commentSingle= PublisherEntity.findById(UUID.fromString(uuid)); EventEntity eventSingle= EventEntity.findById(new ObjectId(uuid));
responseHttp = Response.ok(commentSingle).build(); responseHttp = Response.ok(eventSingle).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<EventEntity> eventsList = EventEntity.find("name", search).page(Page.of(page, nbPages)).list();
responseHttp = Response.ok(eventsList).build();
responseHttp = Response.ok(commentsList).build();
} }
} }
return responseHttp; return responseHttp;
@ -119,7 +117,7 @@ public class EventRessources {
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(EventEntity.count()).build();
} }
return responseHttp; return responseHttp;
} }
@ -134,11 +132,10 @@ public class EventRessources {
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)) {
UUID uid = UUID.fromString(id); EventEntity event = EventEntity.findById(new ObjectId(id));
CommentEntity comment = CommentEntity.findById(uid);
responseHttp = Response.status(Response.Status.NOT_FOUND).build(); responseHttp = Response.status(Response.Status.NOT_FOUND).build();
if (comment != null) { if (event != null) {
responseHttp = Response.ok(comment).build(); responseHttp = Response.ok(event).build();
} }
} }
@ -152,27 +149,23 @@ public class EventRessources {
@RolesAllowed({"Admin", "User"}) @RolesAllowed({"Admin", "User"})
@Path("{id}") @Path("{id}")
@Transactional @Transactional
public Response createComment(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, CommentEntity comment) { public Response createComment(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, EventEntity event) {
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);
CommentEntity newComment = new CommentEntity(); EventEntity newEvent = new EventEntity();
PublisherEntity publishers = PublisherEntity.findById(UUID.fromString(id));
if (status.equals(Response.Status.OK)) { if (status.equals(Response.Status.OK)) {
newComment.comment = comment.comment; newEvent.name = event.name;
newComment.users = user; newEvent.address = event.address;
newComment.publishers = publishers; newEvent.organisateurs = event.organisateurs;
newComment.created_at = LocalDateTime.now(); newEvent.created_at = LocalDateTime.now();
newComment.updated_at = LocalDateTime.now(); newEvent.updated_at = LocalDateTime.now();
newComment.persist(); newEvent.persist();
if (newComment.isPersistent()) { status = Response.Status.CREATED;
status = Response.Status.CREATED;
} else {
status = Response.Status.NO_CONTENT;
}
} }
return Response.status(status).entity(newComment).build(); return Response.status(status).entity(newEvent).build();
} }