POST publisher

This commit is contained in:
Valentin CZERYBA 2023-01-08 12:14:02 +01:00
parent a71d6562ca
commit 44dc820a30

View File

@ -170,45 +170,27 @@ public class PublisherRessources {
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Transactional
public Response createUser(UsersEntity users) {
Response.Status status = Response.Status.OK;
UsersEntity usersPseudo = UsersEntity.findByPseudo(users.pseudo);
UsersEntity usersEmail = UsersEntity.findByEmail(users.email);
Boolean createUserBool = true;
Boolean pseudoExist = false;
Boolean emailExist = false;
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 = 2;
usersNew.persist();
if (usersNew.isPersistent()) {
public Response createPublisher(@Context SecurityContext ctx, @CookieParam("user") String userCookie, PublisherEntity publishers) {
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
UsersEntity user = UsersEntity.findById(kid);
Response.Status status = getResponseCheck(ctx, userCookie, user);
PublisherEntity newPublisher = new PublisherEntity();
if (status.equals(Response.Status.OK)) {
newPublisher.description = publishers.description;
newPublisher.type = publishers.type;
newPublisher.url = publishers.url;
newPublisher.users = user;
newPublisher.created_at = LocalDateTime.now();
newPublisher.updated_at = LocalDateTime.now();
newPublisher.persist();
if (newPublisher.isPersistent()) {
status = Response.Status.CREATED;
} else {
status = Response.Status.NO_CONTENT;
}
}
return Response.status(status).entity(new UserExist(emailExist, pseudoExist)).build();
return Response.status(status).entity(newPublisher).build();
}
@ -382,5 +364,4 @@ public class PublisherRessources {
}
return Response.status(status).build();
}
}