Merge pull request 'add function publishers for event and group' (#14) from publication into master

Reviewed-on: #14
This commit is contained in:
v4l3n71n 2023-01-19 21:51:00 +00:00
commit 11c8437eb0
4 changed files with 58 additions and 0 deletions

View File

@ -24,6 +24,8 @@ public class EventEntity extends PanacheMongoEntity {
public Collection<String> interesses; public Collection<String> interesses;
public Collection<String> publication;
public String reservation; public String reservation;
public Confidentialite confidentialite; public Confidentialite confidentialite;

View File

@ -17,6 +17,8 @@ public class GroupEntity extends PanacheMongoEntity {
public Collection<String> membres; public Collection<String> membres;
public Collection<String> publication;
public LocalDateTime created_at; public LocalDateTime created_at;
public LocalDateTime updated_at; public LocalDateTime updated_at;
public LocalDateTime deleted_at; public LocalDateTime deleted_at;

View File

@ -270,4 +270,31 @@ public class EventRessources {
} }
return Response.status(status).build(); 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();
}
} }

View File

@ -164,6 +164,33 @@ public class GroupRessources {
return Response.status(status).entity(newGroup).build(); 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
@DELETE @DELETE