add function to disable and delete
This commit is contained in:
parent
c20ca0723c
commit
be11abbd9f
@ -1,7 +1,5 @@
|
|||||||
package com.covas.Json;
|
package com.covas.Json;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||||
|
|
||||||
@RegisterForReflection
|
@RegisterForReflection
|
||||||
|
@ -17,7 +17,6 @@ import javax.ws.rs.core.Response;
|
|||||||
|
|
||||||
import com.covas.Classes.Hash;
|
import com.covas.Classes.Hash;
|
||||||
import com.covas.Entity.UsersEntity;
|
import com.covas.Entity.UsersEntity;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.deser.DurationDeserializer;
|
|
||||||
|
|
||||||
import io.smallrye.jwt.auth.principal.JWTParser;
|
import io.smallrye.jwt.auth.principal.JWTParser;
|
||||||
import io.smallrye.jwt.auth.principal.ParseException;
|
import io.smallrye.jwt.auth.principal.ParseException;
|
||||||
|
@ -224,14 +224,14 @@ public class UsersRessources {
|
|||||||
@DELETE
|
@DELETE
|
||||||
@RolesAllowed("User")
|
@RolesAllowed("User")
|
||||||
@Transactional
|
@Transactional
|
||||||
public Response changeStatus(@Context SecurityContext ctx, @CookieParam("user") String userCookie) {
|
public Response changeStatusToDelete(@Context SecurityContext ctx, @CookieParam("user") String userCookie) {
|
||||||
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)) {
|
||||||
user.status = 0;
|
user.status = -1;
|
||||||
user.updated_at = LocalDateTime.now();
|
user.updated_at = LocalDateTime.now();
|
||||||
user.deleted_at = LocalDateTime.now();
|
user.deleted_at = LocalDateTime.now();
|
||||||
user.persist();
|
user.persist();
|
||||||
@ -246,7 +246,57 @@ public class UsersRessources {
|
|||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("Admin")
|
@RolesAllowed("Admin")
|
||||||
@Transactional
|
@Transactional
|
||||||
public Response changeStatusSingleUser(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
public Response changeStatusSingleUserToDelete(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
||||||
|
@PathParam("id") String id) {
|
||||||
|
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||||
|
UsersEntity user = UsersEntity.findById(kid);
|
||||||
|
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||||
|
if (status.equals(Response.Status.OK)) {
|
||||||
|
UsersEntity singleUser = UsersEntity.find("id", UUID.fromString(id)).firstResult();
|
||||||
|
if (singleUser == null) {
|
||||||
|
status = Response.Status.NOT_FOUND;
|
||||||
|
} else {
|
||||||
|
singleUser.status = -1;
|
||||||
|
singleUser.updated_at = LocalDateTime.now();
|
||||||
|
singleUser.deleted_at = LocalDateTime.now();
|
||||||
|
singleUser.persist();
|
||||||
|
if (!singleUser.isPersistent()) {
|
||||||
|
status = Response.Status.NOT_MODIFIED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Response.status(status).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@DELETE
|
||||||
|
@RolesAllowed("User")
|
||||||
|
@Transactional
|
||||||
|
@Path("disable")
|
||||||
|
public Response changeStatusToDisable(@Context SecurityContext ctx, @CookieParam("user") String userCookie) {
|
||||||
|
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||||
|
UsersEntity user = UsersEntity.findById(kid);
|
||||||
|
|
||||||
|
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||||
|
|
||||||
|
if (status.equals(Response.Status.OK)) {
|
||||||
|
user.status = -1;
|
||||||
|
user.updated_at = LocalDateTime.now();
|
||||||
|
user.deleted_at = LocalDateTime.now();
|
||||||
|
user.persist();
|
||||||
|
if (!user.isPersistent()) {
|
||||||
|
status = Response.Status.NOT_MODIFIED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Response.status(status).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DELETE
|
||||||
|
@Path("/disable/{id}")
|
||||||
|
@RolesAllowed("Admin")
|
||||||
|
@Transactional
|
||||||
|
public Response changeStatusSingleUserToDisable(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
||||||
@PathParam("id") String id) {
|
@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);
|
||||||
@ -307,6 +357,33 @@ public class UsersRessources {
|
|||||||
return Response.status(status).build();
|
return Response.status(status).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@PATCH
|
||||||
|
@RolesAllowed("Admin")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Transactional
|
||||||
|
@Path("enable/{id}")
|
||||||
|
public Response enableUserAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @QueryParam("id") String id) {
|
||||||
|
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||||
|
UsersEntity user = UsersEntity.findById(kid);
|
||||||
|
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||||
|
if (status.equals(Response.Status.OK)) {
|
||||||
|
|
||||||
|
UsersEntity usersOrig = UsersEntity.findById(UUID.fromString(id));
|
||||||
|
if (usersOrig == null) {
|
||||||
|
status = Response.Status.NOT_FOUND;
|
||||||
|
} else {
|
||||||
|
usersOrig.status = 1;
|
||||||
|
usersOrig.persist();
|
||||||
|
if (!usersOrig.isPersistent()) {
|
||||||
|
status = Response.Status.NOT_MODIFIED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Response.status(status).build();
|
||||||
|
}
|
||||||
|
|
||||||
@PATCH
|
@PATCH
|
||||||
@RolesAllowed("User")
|
@RolesAllowed("User")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user