From fb48935bbb4027c08c780d54ee27a9a6e56fb0b6 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 8 Jan 2023 12:23:51 +0100 Subject: [PATCH] replace POST to PUT --- .../covas/Resources/PublisherRessources.java | 61 ++----------------- 1 file changed, 4 insertions(+), 57 deletions(-) diff --git a/src/main/java/com/covas/Resources/PublisherRessources.java b/src/main/java/com/covas/Resources/PublisherRessources.java index cd0397c..4b694d2 100644 --- a/src/main/java/com/covas/Resources/PublisherRessources.java +++ b/src/main/java/com/covas/Resources/PublisherRessources.java @@ -166,9 +166,10 @@ public class PublisherRessources { return responseHttp; } - // POST - @POST + // PUT + @PUT @Consumes(MediaType.APPLICATION_JSON) + @RolesAllowed({"Admin", "User"}) @Transactional public Response createPublisher(@Context SecurityContext ctx, @CookieParam("user") String userCookie, PublisherEntity publishers) { @@ -194,61 +195,7 @@ public class PublisherRessources { } - // PUT - @PUT - @RolesAllowed("Admin") - @Consumes(MediaType.APPLICATION_JSON) - @Transactional - public Response addUser(@Context SecurityContext ctx, @CookieParam("user") String userCookie, - UsersEntity users) { - UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); - UsersEntity user = UsersEntity.findById(kid); - Response.Status status = getResponseCheck(ctx, userCookie, user); - Boolean pseudoExist = false; - Boolean emailExist = false; - - if (status.equals(Response.Status.OK)) { - - UsersEntity usersPseudo = UsersEntity.findByPseudo(users.pseudo); - UsersEntity usersEmail = UsersEntity.findByEmail(users.email); - Boolean createUserBool = true; - - if (usersPseudo != null) { - createUserBool = false; - status = Response.Status.UNAUTHORIZED; - pseudoExist = true; - } - if(usersEmail != null){ - createUserBool = false; - status = Response.Status.UNAUTHORIZED; - emailExist = true; - } - if(createUserBool) { - UsersEntity usersNew = new UsersEntity(); - usersNew.name = users.name; - usersNew.pseudo = users.pseudo; - usersNew.firstName = users.firstName; - usersNew.email = users.email; - usersNew.birth = LocalDate.of(users.birth.getYear(), users.birth.getMonth(), - users.birth.getDayOfMonth()); - usersNew.created_at = LocalDateTime.now(); - usersNew.updated_at = LocalDateTime.now(); - usersNew.password = Hash - .encryptSHA512(Base64.toBase64String(users.password.getBytes(StandardCharsets.UTF_8))); - usersNew.roles = users.roles; - usersNew.status = 1; - usersNew.persist(); - if (usersNew.isPersistent()) { - status = Response.Status.CREATED; - } else { - status = Response.Status.NO_CONTENT; - } - } - } - return Response.status(status).entity(new UserExist(emailExist, pseudoExist)).build(); - } - - // Delete + // DELETE @DELETE @Path("{id}") @RolesAllowed({"Admin", "User"})