replace POST to PUT

This commit is contained in:
Valentin CZERYBA 2023-01-08 12:23:51 +01:00
parent 44dc820a30
commit fb48935bbb

View File

@ -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"})