add coluln deleted_at and update uri for patch
This commit is contained in:
parent
b48f2bc73a
commit
9ef8bb92ff
@ -49,6 +49,8 @@ public class UsersEntity extends PanacheEntityBase {
|
||||
public LocalDateTime created_at;
|
||||
@Column(nullable = false)
|
||||
public LocalDateTime updated_at;
|
||||
@ColumnDefault("null")
|
||||
public LocalDateTime deleted_at;
|
||||
|
||||
public static UsersEntity findByPseudo(String pseudo){
|
||||
return find("pseudo", pseudo).firstResult();
|
||||
|
@ -158,10 +158,11 @@ public class UsersRessources {
|
||||
|
||||
// PUT
|
||||
@PUT
|
||||
@Path("{pseudo}")
|
||||
@RolesAllowed("Admin")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Transactional
|
||||
public Response addUser(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
||||
public Response addUser(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("pseudo") String pseudo,
|
||||
UsersEntity users) {
|
||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||
UsersEntity user = UsersEntity.findById(kid);
|
||||
@ -169,13 +170,13 @@ public class UsersRessources {
|
||||
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
|
||||
UsersEntity usersOrig = UsersEntity.findByPseudo(users.pseudo);
|
||||
UsersEntity usersOrig = UsersEntity.findByPseudo(pseudo);
|
||||
if (usersOrig != null) {
|
||||
status = Response.Status.UNAUTHORIZED;
|
||||
} else {
|
||||
UsersEntity usersNew = new UsersEntity();
|
||||
usersNew.name = users.name;
|
||||
usersNew.pseudo = users.pseudo;
|
||||
usersNew.pseudo = pseudo;
|
||||
usersNew.firstName = users.firstName;
|
||||
usersNew.email = users.email;
|
||||
usersNew.birth = LocalDate.of(users.birth.getYear(), users.birth.getMonth(),
|
||||
@ -210,6 +211,8 @@ public class UsersRessources {
|
||||
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
user.status = false;
|
||||
user.updated_at = LocalDateTime.now();
|
||||
user.deleted_at = LocalDateTime.now();
|
||||
user.persist();
|
||||
if (!user.isPersistent()) {
|
||||
status = Response.Status.NOT_MODIFIED;
|
||||
@ -233,6 +236,8 @@ public class UsersRessources {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
singleUser.status = false;
|
||||
singleUser.updated_at = LocalDateTime.now();
|
||||
singleUser.deleted_at = LocalDateTime.now();
|
||||
singleUser.persist();
|
||||
if (!singleUser.isPersistent()) {
|
||||
status = Response.Status.NOT_MODIFIED;
|
||||
@ -268,6 +273,10 @@ public class UsersRessources {
|
||||
usersOrig.password = Hash
|
||||
.encryptSHA512(Base64.toBase64String(users.password.getBytes(StandardCharsets.UTF_8)));
|
||||
usersOrig.roles = users.roles;
|
||||
if(users.status){
|
||||
usersOrig.deleted_at = null;
|
||||
usersOrig.status = true;
|
||||
}
|
||||
usersOrig.persist();
|
||||
if (!usersOrig.isPersistent()) {
|
||||
status = Response.Status.NOT_MODIFIED;
|
||||
|
Loading…
x
Reference in New Issue
Block a user