diff --git a/src/main/java/com/covas/Entity/UsersEntity.java b/src/main/java/com/covas/Entity/UsersEntity.java index 11d5f6d..5b7b585 100644 --- a/src/main/java/com/covas/Entity/UsersEntity.java +++ b/src/main/java/com/covas/Entity/UsersEntity.java @@ -8,7 +8,8 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; - +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; import javax.persistence.Table; import com.covas.Classes.Hash; @@ -21,6 +22,14 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase; @Entity @Table(name = "users") +@NamedQueries({ + @NamedQuery(name = "Users.byUUIDandRoles", query = "from UsersEntity u where u.id = :id and u.roles = :roles"), + @NamedQuery(name = "Users.byUUIDandStatus", query = "from UsersEntity u where u.id = :id and u.status = :status"), + @NamedQuery(name = "Users.byUUIDandRolesandStatus", query = "from UsersEntity u where u.id = :id and u.roles = :roles and u.status = :status"), + @NamedQuery(name = "Users.byEmailandRoles", query = "from UsersEntity u where u.email = :email and u.roles = :roles"), + @NamedQuery(name = "Users.byEmailandStatus", query = "from UsersEntity u where u.email = :email and u.status = :status"), + @NamedQuery(name = "Users.byEmailandRolesandStatus", query = "from UsersEntity u where u.email = :email and u.roles = :roles and u.status = :status") +}) public class UsersEntity extends PanacheEntityBase { @Id @Column(name = "id") diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index e734e59..8f9c904 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -31,6 +31,7 @@ import com.covas.Json.UserExist; import com.covas.Json.UserSingle; import io.quarkus.panache.common.Page; +import io.quarkus.panache.common.Parameters; import org.eclipse.microprofile.jwt.Claims; import org.eclipse.microprofile.jwt.JsonWebToken; @@ -71,7 +72,7 @@ public class UsersRessources { /// GET @GET @RolesAllowed("Admin") - public Response getUsers(@CookieParam("user") String userCookie, @Context SecurityContext ctx, @QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages) { + public Response getUsers(@CookieParam("user") String userCookie, @Context SecurityContext ctx, @QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages, @QueryParam("status") Integer status, @QueryParam("roles") String roles, @QueryParam("email") String email, @QueryParam("search") String search, @QueryParam("uuid") String uuid) { if(nbPages == null){ nbPages = 20; } @@ -80,10 +81,37 @@ public class UsersRessources { } UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); - Response.Status status = getResponseCheck(ctx, userCookie, user); - Response responseHttp = Response.status(status).build(); - if (status.equals(Response.Status.OK)) { + Response.Status statusHttp = getResponseCheck(ctx, userCookie, user); + Response responseHttp = Response.status(statusHttp).build(); + if (statusHttp.equals(Response.Status.OK)) { responseHttp = Response.ok(UsersEntity.findAll().page(Page.of(page, nbPages)).list()).build(); + if(uuid != null){ + UsersEntity userSingle = UsersEntity.findById(UUID.fromString(uuid)); + if((roles != null) && (status == null)){ + userSingle = UsersEntity.find("Users.byUUIDandRoles", Parameters.with("id", UUID.fromString(uuid)).and("roles",roles)).firstResult(); + } + if((roles == null) && (status != null)){ + userSingle = UsersEntity.find("Users.byUUIDandStatus", Parameters.with("id", UUID.fromString(uuid)).and("status",status)).firstResult(); + } + if((roles != null) && (status != null)){ + userSingle = UsersEntity.find("Users.byUUIDandRolesandStatus", Parameters.with("id", UUID.fromString(uuid)).and("status",status).and("roles", roles)).firstResult(); + } + responseHttp = Response.ok(userSingle).build(); + + } + if(email != null){ + UsersEntity userSingle = UsersEntity.findByEmail(email); + if((roles != null) && (status == null)){ + userSingle = UsersEntity.find("Users.byEmailandRoles", Parameters.with("email", UUID.fromString(uuid)).and("roles",roles)).firstResult(); + } + if((roles == null) && (status != null)){ + userSingle = UsersEntity.find("Users.byEmailandStatus", Parameters.with("email", UUID.fromString(uuid)).and("status",status)).firstResult(); + } + if((roles != null) && (status != null)){ + userSingle = UsersEntity.find("Users.byEmailandRolesandStatus", Parameters.with("email", UUID.fromString(uuid)).and("status",status).and("roles", roles)).firstResult(); + } + responseHttp = Response.ok(userSingle).build(); + } } return responseHttp; }