From 3485fbb646ce4cb08c693f7fb58b4f30905d62cc Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 7 Jan 2023 21:36:39 +0100 Subject: [PATCH] get publishers 75% --- .../com/covas/Entity/PublisherEntity.java | 8 ++ .../java/com/covas/Json/PublisherSingle.java | 21 ++++++ .../covas/Resources/PublisherRessources.java | 74 +++++-------------- 3 files changed, 48 insertions(+), 55 deletions(-) create mode 100644 src/main/java/com/covas/Json/PublisherSingle.java diff --git a/src/main/java/com/covas/Entity/PublisherEntity.java b/src/main/java/com/covas/Entity/PublisherEntity.java index 1a877a7..95c3df0 100644 --- a/src/main/java/com/covas/Entity/PublisherEntity.java +++ b/src/main/java/com/covas/Entity/PublisherEntity.java @@ -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; diff --git a/src/main/java/com/covas/Json/PublisherSingle.java b/src/main/java/com/covas/Json/PublisherSingle.java new file mode 100644 index 0000000..339ee46 --- /dev/null +++ b/src/main/java/com/covas/Json/PublisherSingle.java @@ -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; + + } + +} diff --git a/src/main/java/com/covas/Resources/PublisherRessources.java b/src/main/java/com/covas/Resources/PublisherRessources.java index 92ccc07..ab2167a 100644 --- a/src/main/java/com/covas/Resources/PublisherRessources.java +++ b/src/main/java/com/covas/Resources/PublisherRessources.java @@ -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 listUsers = UsersEntity.findAll().page(Page.of(page, nbPages)).list(); + List 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(); - } - 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(); + PublisherEntity publisherSingle = PublisherEntity.findById(UUID.fromString(uuid)); + responseHttp = Response.ok(publisherSingle).build(); } + if(search != null){ - List 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 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; }