POST publisher
This commit is contained in:
parent
a71d6562ca
commit
44dc820a30
@ -170,45 +170,27 @@ public class PublisherRessources {
|
|||||||
@POST
|
@POST
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Transactional
|
@Transactional
|
||||||
public Response createUser(UsersEntity users) {
|
public Response createPublisher(@Context SecurityContext ctx, @CookieParam("user") String userCookie, PublisherEntity publishers) {
|
||||||
Response.Status status = Response.Status.OK;
|
|
||||||
UsersEntity usersPseudo = UsersEntity.findByPseudo(users.pseudo);
|
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||||
UsersEntity usersEmail = UsersEntity.findByEmail(users.email);
|
UsersEntity user = UsersEntity.findById(kid);
|
||||||
Boolean createUserBool = true;
|
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||||
Boolean pseudoExist = false;
|
PublisherEntity newPublisher = new PublisherEntity();
|
||||||
Boolean emailExist = false;
|
if (status.equals(Response.Status.OK)) {
|
||||||
if (usersPseudo != null) {
|
newPublisher.description = publishers.description;
|
||||||
createUserBool = false;
|
newPublisher.type = publishers.type;
|
||||||
status = Response.Status.UNAUTHORIZED;
|
newPublisher.url = publishers.url;
|
||||||
pseudoExist = true;
|
newPublisher.users = user;
|
||||||
}
|
newPublisher.created_at = LocalDateTime.now();
|
||||||
if(usersEmail != null){
|
newPublisher.updated_at = LocalDateTime.now();
|
||||||
createUserBool = false;
|
newPublisher.persist();
|
||||||
status = Response.Status.UNAUTHORIZED;
|
if (newPublisher.isPersistent()) {
|
||||||
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()) {
|
|
||||||
status = Response.Status.CREATED;
|
status = Response.Status.CREATED;
|
||||||
} else {
|
} else {
|
||||||
status = Response.Status.NO_CONTENT;
|
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();
|
return Response.status(status).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user