get publishers 75%
This commit is contained in:
parent
dc0428f7b5
commit
3485fbb646
@ -13,6 +13,8 @@ import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.CascadeType;
|
||||
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
@ -25,6 +27,9 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
|
||||
|
||||
@Entity
|
||||
@Table(name = "publisher")
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "Publishers.bySearch", query = "from PublisherEntity u where u.description like :description"),
|
||||
})
|
||||
public class PublisherEntity extends PanacheEntityBase implements Serializable {
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@ -47,6 +52,9 @@ public class PublisherEntity extends PanacheEntityBase implements Serializable {
|
||||
@ColumnDefault("null")
|
||||
public LocalDateTime deleted_at;
|
||||
|
||||
@ColumnDefault("1")
|
||||
public Short status;
|
||||
|
||||
@ManyToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "users_id", referencedColumnName = "id")
|
||||
public UsersEntity users;
|
||||
|
21
src/main/java/com/covas/Json/PublisherSingle.java
Normal file
21
src/main/java/com/covas/Json/PublisherSingle.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.covas.Json;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
public class PublisherSingle {
|
||||
|
||||
public final String pseudo;
|
||||
public final String text;
|
||||
public final Short status;
|
||||
public final String url;
|
||||
|
||||
public PublisherSingle(String pseudo, String text, Short status, String url){
|
||||
this.pseudo = pseudo;
|
||||
this.text = text;
|
||||
this.status = status;
|
||||
this.url = url;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -27,7 +27,9 @@ import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import com.covas.Classes.Hash;
|
||||
import com.covas.Entity.PublisherEntity;
|
||||
import com.covas.Entity.UsersEntity;
|
||||
import com.covas.Json.PublisherSingle;
|
||||
import com.covas.Json.UserExist;
|
||||
import com.covas.Json.UserSingle;
|
||||
|
||||
@ -75,8 +77,8 @@ public class PublisherRessources {
|
||||
@RolesAllowed("Admin")
|
||||
public Response getUsers(@CookieParam("user") String userCookie, @Context SecurityContext ctx,
|
||||
@QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages,
|
||||
@QueryParam("status") Short status, @QueryParam("roles") String roles,
|
||||
@QueryParam("email") String email, @QueryParam("search") String search,
|
||||
@QueryParam("status") Short status,
|
||||
@QueryParam("search") String search,
|
||||
@QueryParam("uuid") String uuid) {
|
||||
if(nbPages == null){
|
||||
nbPages = 20;
|
||||
@ -89,57 +91,19 @@ public class PublisherRessources {
|
||||
Response.Status statusHttp = getResponseCheck(ctx, userCookie, user);
|
||||
Response responseHttp = Response.status(statusHttp).build();
|
||||
if (statusHttp.equals(Response.Status.OK)) {
|
||||
List<UsersEntity> listUsers = UsersEntity.findAll().page(Page.of(page, nbPages)).list();
|
||||
List<PublisherEntity> listPublishers = PublisherEntity.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();
|
||||
|
||||
responseHttp = Response.ok(listPublishers).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();
|
||||
PublisherEntity publisherSingle = PublisherEntity.findById(UUID.fromString(uuid));
|
||||
responseHttp = Response.ok(publisherSingle).build();
|
||||
}
|
||||
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", email).and("roles",roles)).firstResult();
|
||||
}
|
||||
if((roles == null) && (status != null)){
|
||||
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", email).and("status",status).and("roles", roles)).firstResult();
|
||||
}
|
||||
responseHttp = Response.ok(userSingle).build();
|
||||
}
|
||||
if(search != null){
|
||||
List<UsersEntity> usersList = UsersEntity.find("#Users.bySearch", Parameters.with("search", search)).page(Page.of(page, nbPages)).list();
|
||||
if((roles != null) && (status == null)){
|
||||
usersList = UsersEntity.find("#Users.bySearchandRoles", Parameters.with("search", search).and("roles",roles)).page(Page.of(page, nbPages)).list();
|
||||
}
|
||||
if((roles == null) && (status != null)){
|
||||
usersList = UsersEntity.find("#Users.bySearchandStatus", Parameters.with("search", search).and("status",status)).page(Page.of(page, nbPages)).list();
|
||||
}
|
||||
if((roles != null) && (status != null)){
|
||||
usersList = UsersEntity.find("#Users.bySearchandRolesandStatus", Parameters.with("search", search).and("status",status).and("roles", roles)).page(Page.of(page, nbPages)).list();
|
||||
}
|
||||
responseHttp = Response.ok(usersList).build();
|
||||
List<PublisherEntity> publishersList = PublisherEntity.find("#Publisher.bySearch", Parameters.with("description", search)).page(Page.of(page, nbPages)).list();
|
||||
|
||||
responseHttp = Response.ok(publishersList).build();
|
||||
|
||||
}
|
||||
}
|
||||
@ -155,7 +119,7 @@ public class PublisherRessources {
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
Response responseHttp = Response.status(status).build();
|
||||
if (status.equals(Response.Status.OK)){
|
||||
responseHttp = Response.ok(UsersEntity.count()).build();
|
||||
responseHttp = Response.ok(PublisherEntity.count()).build();
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
@ -171,10 +135,10 @@ public class PublisherRessources {
|
||||
Response responseHttp = Response.status(status).build();
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
UUID uid = UUID.fromString(id);
|
||||
UsersEntity users = UsersEntity.findById(uid);
|
||||
PublisherEntity publishers = PublisherEntity.findById(uid);
|
||||
responseHttp = Response.status(Response.Status.NOT_FOUND).build();
|
||||
if (users != null) {
|
||||
responseHttp = Response.ok(users).build();
|
||||
if (publishers != null) {
|
||||
responseHttp = Response.ok(publishers).build();
|
||||
}
|
||||
|
||||
}
|
||||
@ -198,8 +162,8 @@ public class PublisherRessources {
|
||||
}
|
||||
Response responseHttp = Response.status(status).build();
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
responseHttp = Response.status(status).entity(new UserSingle(user.name, user.pseudo, user.firstName, user.description))
|
||||
.build();
|
||||
// responseHttp = Response.status(status).entity(new PublisherSingle(user.name, user.pseudo, user.firstName, user.description))
|
||||
//.build();
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user