diff --git a/src/main/java/com/covas/Entity/UsersEntity.java b/src/main/java/com/covas/Entity/UsersEntity.java index 5b7b585..535f7c2 100644 --- a/src/main/java/com/covas/Entity/UsersEntity.java +++ b/src/main/java/com/covas/Entity/UsersEntity.java @@ -28,7 +28,11 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase; @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") + @NamedQuery(name = "Users.byEmailandRolesandStatus", query = "from UsersEntity u where u.email = :email and u.roles = :roles and u.status = :status"), + @NamedQuery(name = "Users.bySearch", query = "from UsersEntity u where u.pseudo = :search or u.name = :search or u.firstName = :search"), + @NamedQuery(name = "Users.bySearchandRoles", query = "from UsersEntity u where (u.pseudo = :search or u.name = :search or u.firstName = :search) and u.roles = :roles"), + @NamedQuery(name = "Users.bySearchandStatus", query = "from UsersEntity u where (u.pseudo = :search or u.name = :search or u.firstName = :search) and u.status = :status"), + @NamedQuery(name = "Users.bySearchandRolesandStatus", query = "from UsersEntity u where (u.pseudo = :search or u.name = :search or u.firstName = :search) and u.roles = :roles and u.status = :status") }) public class UsersEntity extends PanacheEntityBase { @Id diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index 8f9c904..d016f33 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -3,6 +3,7 @@ package com.covas.Resources; import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.List; import java.util.UUID; import javax.annotation.security.RolesAllowed; @@ -102,16 +103,30 @@ public class UsersRessources { 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(); + userSingle = UsersEntity.find("Users.byEmailandRoles", Parameters.with("email", email).and("roles",roles)).firstResult(); } if((roles == null) && (status != null)){ - userSingle = UsersEntity.find("Users.byEmailandStatus", Parameters.with("email", UUID.fromString(uuid)).and("status",status)).firstResult(); + userSingle = UsersEntity.find("Users.byEmailandStatus", Parameters.with("email", email).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(); + userSingle = UsersEntity.find("Users.byEmailandRolesandStatus", Parameters.with("email", email).and("status",status).and("roles", roles)).firstResult(); } responseHttp = Response.ok(userSingle).build(); } + if(search != null){ + List usersList = UsersEntity.list("Users.bySearch", Parameters.with("search", search)); + if((roles != null) && (status == null)){ + usersList = UsersEntity.find("Users.bySearchandRoles", Parameters.with("search", search).and("roles",roles)).list(); + } + if((roles == null) && (status != null)){ + usersList = UsersEntity.find("Users.bySearchandStatus", Parameters.with("search", search).and("status",status)).firstResult(); + } + if((roles != null) && (status != null)){ + usersList = UsersEntity.find("Users.bySearchandRolesandStatus", Parameters.with("search", search).and("status",status).and("roles", roles)).firstResult(); + } + responseHttp = Response.ok(usersList).build(); + + } } return responseHttp; }