add condition by roles and status

This commit is contained in:
Valentin CZERYBA 2022-08-25 15:19:57 +02:00
parent 9892959b36
commit 596582231c
2 changed files with 15 additions and 1 deletions

View File

@ -26,6 +26,9 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
@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.byRoles", query = "from UsersEntity u where u.roles = :roles"),
@NamedQuery(name = "Users.byStatus", query = "from UsersEntity u where u.status = :status"),
@NamedQuery(name = "Users.byRolesandStatus", query = "from UsersEntity u where 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"),

View File

@ -89,7 +89,18 @@ public class UsersRessources {
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();
List<UsersEntity> listUsers = UsersEntity.findAll().page(Page.of(page, nbPages)).list();
if((roles != null) && (status == null)){
listUsers = UsersEntity.find("#Users.byRoles", Parameters.with("roles",roles)).page(Page.of(page, nbPages)).list();
}
if((roles == null) && (status != null)){
listUsers = UsersEntity.find("#Users.byStatus", Parameters.with("status",status)).page(Page.of(page, nbPages)).list();
}
if((roles != null) && (status != null)){
listUsers = UsersEntity.find("#Users.byRolesandStatus", Parameters.with("roles",roles).and("status", status)).page(Page.of(page, nbPages)).list();
}
responseHttp = Response.ok(listUsers).build();
if(uuid != null){
UsersEntity userSingle = UsersEntity.findById(UUID.fromString(uuid));
if((roles != null) && (status == null)){