From 00a48758386515418c9b64d47b070d8b24191c3b Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 19 Jan 2023 22:49:57 +0100 Subject: [PATCH] add function publishers for event and group --- .../java/com/covas/Entity/EventEntity.java | 2 ++ .../java/com/covas/Entity/GroupEntity.java | 2 ++ .../com/covas/Resources/EventRessources.java | 27 +++++++++++++++++++ .../com/covas/Resources/GroupRessources.java | 27 +++++++++++++++++++ 4 files changed, 58 insertions(+) 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 -- 2.47.1