add patch publisher

This commit is contained in:
Valentin CZERYBA 2023-01-07 22:02:00 +01:00
parent 7f9a149196
commit 5b30166cbf

View File

@ -372,35 +372,30 @@ public class PublisherRessources {
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Transactional @Transactional
@Path("{id}") @Path("{id}")
public Response updateUserAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, public Response updatePublisherAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
UsersEntity users, @PathParam("id") String id) { PublisherEntity publishers, @PathParam("id") String id) {
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
UsersEntity user = UsersEntity.findById(kid); UsersEntity user = UsersEntity.findById(kid);
Response.Status status = getResponseCheck(ctx, userCookie, user); Response.Status status = getResponseCheck(ctx, userCookie, user);
if (status.equals(Response.Status.OK)) { if (status.equals(Response.Status.OK)) {
UsersEntity usersOrig = UsersEntity.findById(UUID.fromString(id)); PublisherEntity publishersOrig = PublisherEntity.findById(UUID.fromString(id));
if (usersOrig == null) { if (publishersOrig == null) {
status = Response.Status.NOT_FOUND; status = Response.Status.NOT_FOUND;
} else { } else {
usersOrig.name = users.name; publishersOrig.description = publishers.description;
usersOrig.firstName = users.firstName; publishersOrig.url = publishers.url;
usersOrig.email = users.email; publishersOrig.type = publishers.type;
usersOrig.birth = LocalDate.of(users.birth.getYear(), users.birth.getMonth(),
users.birth.getDayOfMonth()); publishersOrig.updated_at = LocalDateTime.now();
usersOrig.updated_at = LocalDateTime.now();
if(users.password.length() > 0){ if(publishers.status == 1){
usersOrig.password = Hash publishersOrig.deleted_at = null;
.encryptSHA512(Base64.toBase64String(users.password.getBytes(StandardCharsets.UTF_8))); publishersOrig.status = 1;
} }
usersOrig.roles = users.roles; publishersOrig.persist();
if(users.status == 1){ if (!publishersOrig.isPersistent()) {
usersOrig.deleted_at = null;
usersOrig.status = 1;
}
usersOrig.persist();
if (!usersOrig.isPersistent()) {
status = Response.Status.NOT_MODIFIED; status = Response.Status.NOT_MODIFIED;
} }
} }
@ -421,13 +416,13 @@ public class PublisherRessources {
Response.Status status = getResponseCheck(ctx, userCookie, user); Response.Status status = getResponseCheck(ctx, userCookie, user);
if (status.equals(Response.Status.OK)) { if (status.equals(Response.Status.OK)) {
UsersEntity usersOrig = UsersEntity.findById(UUID.fromString(id)); PublisherEntity publishersOrig = PublisherEntity.findById(UUID.fromString(id));
if (usersOrig == null) { if (publishersOrig == null) {
status = Response.Status.NOT_FOUND; status = Response.Status.NOT_FOUND;
} else { } else {
usersOrig.status = 1; publishersOrig.status = 1;
usersOrig.persist(); publishersOrig.persist();
if (!usersOrig.isPersistent()) { if (!publishersOrig.isPersistent()) {
status = Response.Status.NOT_MODIFIED; status = Response.Status.NOT_MODIFIED;
} }
} }