add search name, firstname end pseudo

This commit is contained in:
Valentin CZERYBA 2022-08-23 23:41:55 +02:00
parent 4e39c5e8e7
commit e18ddd2a23
2 changed files with 23 additions and 4 deletions

View File

@ -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

View File

@ -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<UsersEntity> 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;
}