add find email and uuid
This commit is contained in:
parent
a85e6b161e
commit
4e39c5e8e7
@ -8,7 +8,8 @@ import javax.persistence.Column;
|
|||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.NamedQueries;
|
||||||
|
import javax.persistence.NamedQuery;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import com.covas.Classes.Hash;
|
import com.covas.Classes.Hash;
|
||||||
@ -21,6 +22,14 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "users")
|
@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 {
|
public class UsersEntity extends PanacheEntityBase {
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "id")
|
@Column(name = "id")
|
||||||
|
@ -31,6 +31,7 @@ import com.covas.Json.UserExist;
|
|||||||
import com.covas.Json.UserSingle;
|
import com.covas.Json.UserSingle;
|
||||||
|
|
||||||
import io.quarkus.panache.common.Page;
|
import io.quarkus.panache.common.Page;
|
||||||
|
import io.quarkus.panache.common.Parameters;
|
||||||
|
|
||||||
import org.eclipse.microprofile.jwt.Claims;
|
import org.eclipse.microprofile.jwt.Claims;
|
||||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||||
@ -71,7 +72,7 @@ public class UsersRessources {
|
|||||||
/// GET
|
/// GET
|
||||||
@GET
|
@GET
|
||||||
@RolesAllowed("Admin")
|
@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){
|
if(nbPages == null){
|
||||||
nbPages = 20;
|
nbPages = 20;
|
||||||
}
|
}
|
||||||
@ -80,10 +81,37 @@ public class UsersRessources {
|
|||||||
}
|
}
|
||||||
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 statusHttp = getResponseCheck(ctx, userCookie, user);
|
||||||
Response responseHttp = Response.status(status).build();
|
Response responseHttp = Response.status(statusHttp).build();
|
||||||
if (status.equals(Response.Status.OK)) {
|
if (statusHttp.equals(Response.Status.OK)) {
|
||||||
responseHttp = Response.ok(UsersEntity.findAll().page(Page.of(page, nbPages)).list()).build();
|
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;
|
return responseHttp;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user