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;
|
public LocalDateTime created_at;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
public LocalDateTime updated_at;
|
public LocalDateTime updated_at;
|
||||||
|
@ColumnDefault("null")
|
||||||
|
public LocalDateTime deleted_at;
|
||||||
|
|
||||||
public static UsersEntity findByPseudo(String pseudo){
|
public static UsersEntity findByPseudo(String pseudo){
|
||||||
return find("pseudo", pseudo).firstResult();
|
return find("pseudo", pseudo).firstResult();
|
||||||
|
@ -158,10 +158,11 @@ public class UsersRessources {
|
|||||||
|
|
||||||
// PUT
|
// PUT
|
||||||
@PUT
|
@PUT
|
||||||
|
@Path("{pseudo}")
|
||||||
@RolesAllowed("Admin")
|
@RolesAllowed("Admin")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Transactional
|
@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) {
|
UsersEntity users) {
|
||||||
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);
|
||||||
@ -169,13 +170,13 @@ public class UsersRessources {
|
|||||||
|
|
||||||
if (status.equals(Response.Status.OK)) {
|
if (status.equals(Response.Status.OK)) {
|
||||||
|
|
||||||
UsersEntity usersOrig = UsersEntity.findByPseudo(users.pseudo);
|
UsersEntity usersOrig = UsersEntity.findByPseudo(pseudo);
|
||||||
if (usersOrig != null) {
|
if (usersOrig != null) {
|
||||||
status = Response.Status.UNAUTHORIZED;
|
status = Response.Status.UNAUTHORIZED;
|
||||||
} else {
|
} else {
|
||||||
UsersEntity usersNew = new UsersEntity();
|
UsersEntity usersNew = new UsersEntity();
|
||||||
usersNew.name = users.name;
|
usersNew.name = users.name;
|
||||||
usersNew.pseudo = users.pseudo;
|
usersNew.pseudo = pseudo;
|
||||||
usersNew.firstName = users.firstName;
|
usersNew.firstName = users.firstName;
|
||||||
usersNew.email = users.email;
|
usersNew.email = users.email;
|
||||||
usersNew.birth = LocalDate.of(users.birth.getYear(), users.birth.getMonth(),
|
usersNew.birth = LocalDate.of(users.birth.getYear(), users.birth.getMonth(),
|
||||||
@ -210,6 +211,8 @@ public class UsersRessources {
|
|||||||
|
|
||||||
if (status.equals(Response.Status.OK)) {
|
if (status.equals(Response.Status.OK)) {
|
||||||
user.status = false;
|
user.status = false;
|
||||||
|
user.updated_at = LocalDateTime.now();
|
||||||
|
user.deleted_at = LocalDateTime.now();
|
||||||
user.persist();
|
user.persist();
|
||||||
if (!user.isPersistent()) {
|
if (!user.isPersistent()) {
|
||||||
status = Response.Status.NOT_MODIFIED;
|
status = Response.Status.NOT_MODIFIED;
|
||||||
@ -233,6 +236,8 @@ public class UsersRessources {
|
|||||||
status = Response.Status.NOT_FOUND;
|
status = Response.Status.NOT_FOUND;
|
||||||
} else {
|
} else {
|
||||||
singleUser.status = false;
|
singleUser.status = false;
|
||||||
|
singleUser.updated_at = LocalDateTime.now();
|
||||||
|
singleUser.deleted_at = LocalDateTime.now();
|
||||||
singleUser.persist();
|
singleUser.persist();
|
||||||
if (!singleUser.isPersistent()) {
|
if (!singleUser.isPersistent()) {
|
||||||
status = Response.Status.NOT_MODIFIED;
|
status = Response.Status.NOT_MODIFIED;
|
||||||
@ -268,6 +273,10 @@ public class UsersRessources {
|
|||||||
usersOrig.password = Hash
|
usersOrig.password = Hash
|
||||||
.encryptSHA512(Base64.toBase64String(users.password.getBytes(StandardCharsets.UTF_8)));
|
.encryptSHA512(Base64.toBase64String(users.password.getBytes(StandardCharsets.UTF_8)));
|
||||||
usersOrig.roles = users.roles;
|
usersOrig.roles = users.roles;
|
||||||
|
if(users.status){
|
||||||
|
usersOrig.deleted_at = null;
|
||||||
|
usersOrig.status = true;
|
||||||
|
}
|
||||||
usersOrig.persist();
|
usersOrig.persist();
|
||||||
if (!usersOrig.isPersistent()) {
|
if (!usersOrig.isPersistent()) {
|
||||||
status = Response.Status.NOT_MODIFIED;
|
status = Response.Status.NOT_MODIFIED;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user