get publishers 75%

This commit is contained in:
Valentin CZERYBA 2023-01-07 21:36:39 +01:00
parent dc0428f7b5
commit 3485fbb646
3 changed files with 48 additions and 55 deletions

View File

@ -13,6 +13,8 @@ import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.ColumnDefault;
@ -25,6 +27,9 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
@Entity @Entity
@Table(name = "publisher") @Table(name = "publisher")
@NamedQueries({
@NamedQuery(name = "Publishers.bySearch", query = "from PublisherEntity u where u.description like :description"),
})
public class PublisherEntity extends PanacheEntityBase implements Serializable { public class PublisherEntity extends PanacheEntityBase implements Serializable {
@Id @Id
@Column(name = "id") @Column(name = "id")
@ -47,6 +52,9 @@ public class PublisherEntity extends PanacheEntityBase implements Serializable {
@ColumnDefault("null") @ColumnDefault("null")
public LocalDateTime deleted_at; public LocalDateTime deleted_at;
@ColumnDefault("1")
public Short status;
@ManyToOne(cascade = CascadeType.ALL) @ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "users_id", referencedColumnName = "id") @JoinColumn(name = "users_id", referencedColumnName = "id")
public UsersEntity users; public UsersEntity users;

View 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;
}
}

View File

@ -27,7 +27,9 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import com.covas.Classes.Hash; import com.covas.Classes.Hash;
import com.covas.Entity.PublisherEntity;
import com.covas.Entity.UsersEntity; import com.covas.Entity.UsersEntity;
import com.covas.Json.PublisherSingle;
import com.covas.Json.UserExist; import com.covas.Json.UserExist;
import com.covas.Json.UserSingle; import com.covas.Json.UserSingle;
@ -75,8 +77,8 @@ public class PublisherRessources {
@RolesAllowed("Admin") @RolesAllowed("Admin")
public Response getUsers(@CookieParam("user") String userCookie, @Context SecurityContext ctx, public Response getUsers(@CookieParam("user") String userCookie, @Context SecurityContext ctx,
@QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages, @QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages,
@QueryParam("status") Short status, @QueryParam("roles") String roles, @QueryParam("status") Short status,
@QueryParam("email") String email, @QueryParam("search") String search, @QueryParam("search") String search,
@QueryParam("uuid") String uuid) { @QueryParam("uuid") String uuid) {
if(nbPages == null){ if(nbPages == null){
nbPages = 20; nbPages = 20;
@ -89,57 +91,19 @@ public class PublisherRessources {
Response.Status statusHttp = getResponseCheck(ctx, userCookie, user); Response.Status statusHttp = getResponseCheck(ctx, userCookie, user);
Response responseHttp = Response.status(statusHttp).build(); Response responseHttp = Response.status(statusHttp).build();
if (statusHttp.equals(Response.Status.OK)) { 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(); responseHttp = Response.ok(listPublishers).build();
}
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){ if(uuid != null){
UsersEntity userSingle = UsersEntity.findById(UUID.fromString(uuid)); PublisherEntity publisherSingle = PublisherEntity.findById(UUID.fromString(uuid));
if((roles != null) && (status == null)){ responseHttp = Response.ok(publisherSingle).build();
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", 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){ if(search != null){
List<UsersEntity> usersList = UsersEntity.find("#Users.bySearch", Parameters.with("search", search)).page(Page.of(page, nbPages)).list(); List<PublisherEntity> publishersList = PublisherEntity.find("#Publisher.bySearch", Parameters.with("description", 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(); responseHttp = Response.ok(publishersList).build();
}
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();
} }
} }
@ -155,7 +119,7 @@ public class PublisherRessources {
Response.Status status = getResponseCheck(ctx, userCookie, user); Response.Status status = getResponseCheck(ctx, userCookie, user);
Response responseHttp = Response.status(status).build(); Response responseHttp = Response.status(status).build();
if (status.equals(Response.Status.OK)){ if (status.equals(Response.Status.OK)){
responseHttp = Response.ok(UsersEntity.count()).build(); responseHttp = Response.ok(PublisherEntity.count()).build();
} }
return responseHttp; return responseHttp;
} }
@ -171,10 +135,10 @@ public class PublisherRessources {
Response responseHttp = Response.status(status).build(); Response responseHttp = Response.status(status).build();
if (status.equals(Response.Status.OK)) { if (status.equals(Response.Status.OK)) {
UUID uid = UUID.fromString(id); UUID uid = UUID.fromString(id);
UsersEntity users = UsersEntity.findById(uid); PublisherEntity publishers = PublisherEntity.findById(uid);
responseHttp = Response.status(Response.Status.NOT_FOUND).build(); responseHttp = Response.status(Response.Status.NOT_FOUND).build();
if (users != null) { if (publishers != null) {
responseHttp = Response.ok(users).build(); responseHttp = Response.ok(publishers).build();
} }
} }
@ -198,8 +162,8 @@ public class PublisherRessources {
} }
Response responseHttp = Response.status(status).build(); Response responseHttp = Response.status(status).build();
if (status.equals(Response.Status.OK)) { if (status.equals(Response.Status.OK)) {
responseHttp = Response.status(status).entity(new UserSingle(user.name, user.pseudo, user.firstName, user.description)) // responseHttp = Response.status(status).entity(new PublisherSingle(user.name, user.pseudo, user.firstName, user.description))
.build(); //.build();
} }
return responseHttp; return responseHttp;
} }