diff --git a/src/main/java/com/covas/Entity/EventEntity.java b/src/main/java/com/covas/Entity/EventEntity.java index b028523..bef4dd4 100644 --- a/src/main/java/com/covas/Entity/EventEntity.java +++ b/src/main/java/com/covas/Entity/EventEntity.java @@ -24,6 +24,8 @@ public class EventEntity extends PanacheMongoEntity { public Collection interesses; + public Collection publication; + public String reservation; public Confidentialite confidentialite; diff --git a/src/main/java/com/covas/Entity/GroupEntity.java b/src/main/java/com/covas/Entity/GroupEntity.java index f2a7e5e..7293ebd 100644 --- a/src/main/java/com/covas/Entity/GroupEntity.java +++ b/src/main/java/com/covas/Entity/GroupEntity.java @@ -17,6 +17,8 @@ public class GroupEntity extends PanacheMongoEntity { public Collection membres; + public Collection publication; + public LocalDateTime created_at; public LocalDateTime updated_at; public LocalDateTime deleted_at; diff --git a/src/main/java/com/covas/Resources/EventRessources.java b/src/main/java/com/covas/Resources/EventRessources.java index 38f51b4..09d418b 100644 --- a/src/main/java/com/covas/Resources/EventRessources.java +++ b/src/main/java/com/covas/Resources/EventRessources.java @@ -270,4 +270,31 @@ public class EventRessources { } return Response.status(status).build(); } + + // Patch + + @PATCH + @Consumes(MediaType.APPLICATION_JSON) + @RolesAllowed({"Admin", "User"}) + @Path("{id}") + @Transactional + public Response createPublishers(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, @PathParam("publisher") String publisher) { + + 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)) { + EventEntity singleEvent = EventEntity.find("id", new ObjectId(id)).firstResult(); + status = Response.Status.NOT_FOUND; + if(singleEvent != null){ + status = Response.Status.NOT_MODIFIED; + if(singleEvent.publication.add(publisher)){ + singleEvent.updated_at = LocalDateTime.now(); + singleEvent.persist(); + status = Response.Status.CREATED; + } + } + } + return Response.status(status).build(); + } } diff --git a/src/main/java/com/covas/Resources/GroupRessources.java b/src/main/java/com/covas/Resources/GroupRessources.java index 9b61b86..938a172 100644 --- a/src/main/java/com/covas/Resources/GroupRessources.java +++ b/src/main/java/com/covas/Resources/GroupRessources.java @@ -164,6 +164,33 @@ public class GroupRessources { return Response.status(status).entity(newGroup).build(); } + // Patch + + @PATCH + @Consumes(MediaType.APPLICATION_JSON) + @RolesAllowed({"Admin", "User"}) + @Path("{id}") + @Transactional + public Response createPublishers(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, @PathParam("publisher") String publisher) { + + 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)) { + GroupEntity singleGroup = GroupEntity.find("id", new ObjectId(id)).firstResult(); + status = Response.Status.NOT_FOUND; + if(singleGroup != null){ + status = Response.Status.NOT_MODIFIED; + if(singleGroup.publication.add(publisher)){ + singleGroup.updated_at = LocalDateTime.now(); + singleGroup.persist(); + status = Response.Status.CREATED; + } + } + } + return Response.status(status).build(); + } + // DELETE @DELETE