From 127ed20959f92126ce17d895e913d9c51f8ea6cc Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 9 Jan 2023 21:24:39 +0100 Subject: [PATCH 1/6] add table comment --- .../java/com/covas/Entity/CommentEntity.java | 65 +++++++++++++++++++ .../com/covas/Entity/PublisherEntity.java | 4 ++ .../java/com/covas/Entity/UsersEntity.java | 3 + src/main/java/com/covas/Enum/Type.java | 2 +- 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/covas/Entity/CommentEntity.java diff --git a/src/main/java/com/covas/Entity/CommentEntity.java b/src/main/java/com/covas/Entity/CommentEntity.java new file mode 100644 index 0000000..0fe5a8e --- /dev/null +++ b/src/main/java/com/covas/Entity/CommentEntity.java @@ -0,0 +1,65 @@ +package com.covas.Entity; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.List; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +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; +import org.hibernate.annotations.GenericGenerator; + +import com.covas.Enum.Type; + +import io.quarkus.hibernate.orm.panache.PanacheEntityBase; + + +@Entity +@Table(name = "comment") +@NamedQueries({ +@NamedQuery(name = "Comment.bySearch", query = "from CommentEntity u where u.comment like :comment"), +}) +public class CommentEntity extends PanacheEntityBase implements Serializable { + @Id + @Column(name = "id") + @GeneratedValue(generator = "UUID") + @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") + public UUID id; + + @Column(columnDefinition="TEXT") + public String comment; + + @Column(nullable = false) + public LocalDateTime created_at; + @Column(nullable = false) + public LocalDateTime updated_at; + @ColumnDefault("null") + public LocalDateTime deleted_at; + + @ColumnDefault("1") + public Short status; + + @ManyToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "users_id", referencedColumnName = "id") + public UsersEntity users; + + @ManyToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "publishers_id", referencedColumnName = "id") + public PublisherEntity publishers; + + public static List findByUsers(String uuid){ + return find("users_id", uuid).list(); + } +} \ No newline at end of file diff --git a/src/main/java/com/covas/Entity/PublisherEntity.java b/src/main/java/com/covas/Entity/PublisherEntity.java index 5310c46..fc5ea32 100644 --- a/src/main/java/com/covas/Entity/PublisherEntity.java +++ b/src/main/java/com/covas/Entity/PublisherEntity.java @@ -60,6 +60,10 @@ public class PublisherEntity extends PanacheEntityBase implements Serializable { @JoinColumn(name = "users_id", referencedColumnName = "id") public UsersEntity users; + @OneToMany(mappedBy = "publishers") + public Collection comment; + + public static List findByUsers(String uuid){ return find("users_id", uuid).list(); } diff --git a/src/main/java/com/covas/Entity/UsersEntity.java b/src/main/java/com/covas/Entity/UsersEntity.java index e8a5a14..bc86693 100644 --- a/src/main/java/com/covas/Entity/UsersEntity.java +++ b/src/main/java/com/covas/Entity/UsersEntity.java @@ -77,6 +77,9 @@ public class UsersEntity extends PanacheEntityBase implements Serializable { @OneToMany(mappedBy = "users") public Collection publisher; + @OneToMany(mappedBy = "users") + public Collection comment; + public static UsersEntity findByPseudo(String pseudo){ return find("pseudo", pseudo).firstResult(); } diff --git a/src/main/java/com/covas/Enum/Type.java b/src/main/java/com/covas/Enum/Type.java index e9d6839..3198aa0 100644 --- a/src/main/java/com/covas/Enum/Type.java +++ b/src/main/java/com/covas/Enum/Type.java @@ -1,6 +1,6 @@ package com.covas.Enum; public enum Type { - VIDEO, PHOTO, TEXT, URL + VIDEO, PHOTO, TEXT, URL, EVENT } From 9233c16656775b90c1b1d5db33d518bbe978effc Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 9 Jan 2023 21:54:37 +0100 Subject: [PATCH 2/6] Add comment resources --- .../java/com/covas/Entity/CommentEntity.java | 3 - .../covas/Resources/CommentRessources.java | 290 ++++++++++++++++++ .../covas/Resources/PublisherRessources.java | 4 - 3 files changed, 290 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/covas/Resources/CommentRessources.java diff --git a/src/main/java/com/covas/Entity/CommentEntity.java b/src/main/java/com/covas/Entity/CommentEntity.java index 0fe5a8e..c93dcab 100644 --- a/src/main/java/com/covas/Entity/CommentEntity.java +++ b/src/main/java/com/covas/Entity/CommentEntity.java @@ -7,8 +7,6 @@ import java.util.UUID; import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; @@ -21,7 +19,6 @@ import javax.persistence.CascadeType; import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.GenericGenerator; -import com.covas.Enum.Type; import io.quarkus.hibernate.orm.panache.PanacheEntityBase; diff --git a/src/main/java/com/covas/Resources/CommentRessources.java b/src/main/java/com/covas/Resources/CommentRessources.java new file mode 100644 index 0000000..76f729f --- /dev/null +++ b/src/main/java/com/covas/Resources/CommentRessources.java @@ -0,0 +1,290 @@ +package com.covas.Resources; + +import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; +import java.util.List; +import java.util.UUID; + +import javax.annotation.security.RolesAllowed; +import javax.inject.Inject; +import javax.transaction.Transactional; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.Consumes; +import javax.ws.rs.CookieParam; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.PATCH; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import com.covas.Entity.CommentEntity; +import com.covas.Entity.PublisherEntity; +import com.covas.Entity.UsersEntity; +import com.covas.Json.PublisherByUser; + +import io.quarkus.panache.common.Page; +import io.quarkus.panache.common.Parameters; + +import org.eclipse.microprofile.jwt.Claims; +import org.eclipse.microprofile.jwt.JsonWebToken; +import org.jboss.logging.Logger; +import org.postgresql.shaded.com.ongres.scram.common.bouncycastle.base64.Base64; + +@Produces(MediaType.APPLICATION_JSON) +@Path("comment") +public class CommentRessources { + private static final Logger LOGGER = Logger.getLogger(UsersRessources.class); + @Inject + JsonWebToken jwt; + + /// Function + private Boolean checkUserCookie(String userCookie, UsersEntity users) { + if ((userCookie == null) || (users == null)) { + return false; + } + String name = new String(Base64.decode(userCookie), StandardCharsets.UTF_8); + if (!name.equals(users.pseudo) && (users.status != 1)) { + return false; + } + return true; + } + + private Response.Status getResponseCheck(SecurityContext ctx, String userCookie, UsersEntity users) { + if (!ctx.getUserPrincipal().getName().equals(jwt.getName())) { + return Response.Status.INTERNAL_SERVER_ERROR; + } + if (!checkUserCookie(userCookie, users)) { + return Response.Status.FORBIDDEN; + } + return Response.Status.OK; + } + + /// Appel HTTP + + /// GET + @GET + @RolesAllowed("Admin") + public Response getPublishers(@CookieParam("user") String userCookie, @Context SecurityContext ctx, + @QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages, + @QueryParam("status") Short status, + @QueryParam("search") String search, + @QueryParam("uuid") String uuid) { + if(nbPages == null){ + nbPages = 20; + } + if(page == null){ + page = 0; + } + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status statusHttp = getResponseCheck(ctx, userCookie, user); + Response responseHttp = Response.status(statusHttp).build(); + if (statusHttp.equals(Response.Status.OK)) { + List listComments = CommentEntity.findAll().page(Page.of(page, nbPages)).list(); + + + responseHttp = Response.ok(listComments).build(); + if(uuid != null){ + CommentEntity commentSingle= PublisherEntity.findById(UUID.fromString(uuid)); + responseHttp = Response.ok(commentSingle).build(); + } + + if(search != null){ + List commentsList = CommentEntity.find("#Comment.bySearch", Parameters.with("comment", search)).page(Page.of(page, nbPages)).list(); + + responseHttp = Response.ok(commentsList).build(); + + } + } + return responseHttp; + } + + @GET + @RolesAllowed("Admin") + @Path("count") + public Response getCount(@CookieParam("user") String userCookie, @Context SecurityContext ctx){ + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + Response responseHttp = Response.status(status).build(); + if (status.equals(Response.Status.OK)){ + responseHttp = Response.ok(CommentEntity.count()).build(); + } + return responseHttp; + } + + @GET + @RolesAllowed("Admin") + @Path("{id}") + public Response getSinglePublisher(@PathParam("id") String id, @CookieParam("user") String userCookie, + @Context SecurityContext ctx) { + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + Response responseHttp = Response.status(status).build(); + if (status.equals(Response.Status.OK)) { + UUID uid = UUID.fromString(id); + CommentEntity comment = CommentEntity.findById(uid); + responseHttp = Response.status(Response.Status.NOT_FOUND).build(); + if (comment != null) { + responseHttp = Response.ok(comment).build(); + } + + } + return responseHttp; + } + + + // PUT + @PUT + @Consumes(MediaType.APPLICATION_JSON) + @RolesAllowed({"Admin", "User"}) + @Path("{id}") + @Transactional + public Response createPublisher(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, CommentEntity comment) { + + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + CommentEntity newComment = new CommentEntity(); + PublisherEntity publishers = PublisherEntity.findById(UUID.fromString(id)); + if (status.equals(Response.Status.OK)) { + newComment.comment = comment.comment; + newComment.users = user; + newComment.publishers = publishers; + newComment.created_at = LocalDateTime.now(); + newComment.updated_at = LocalDateTime.now(); + newComment.persist(); + if (newComment.isPersistent()) { + status = Response.Status.CREATED; + } else { + status = Response.Status.NO_CONTENT; + } + } + return Response.status(status).entity(newComment).build(); + } + + + // DELETE + @DELETE + @Path("{id}") + @RolesAllowed({"Admin", "User"}) + @Transactional + public Response changeStatusSinglePublisherToDelete(@Context SecurityContext ctx, @CookieParam("user") String userCookie, + @PathParam("id") String id) { + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + if (status.equals(Response.Status.OK)) { + PublisherEntity singlePublisher = PublisherEntity.find("id", UUID.fromString(id)).firstResult(); + if (singlePublisher == null) { + status = Response.Status.NOT_FOUND; + } else { + singlePublisher.status = -1; + singlePublisher.updated_at = LocalDateTime.now(); + singlePublisher.deleted_at = LocalDateTime.now(); + singlePublisher.persist(); + if (!singlePublisher.isPersistent()) { + status = Response.Status.NOT_MODIFIED; + } + } + } + return Response.status(status).build(); + } + + @DELETE + @Path("/disable/{id}") + @RolesAllowed({"Admin", "User"}) + @Transactional + public Response changeStatusSinglePublisherToDisable(@Context SecurityContext ctx, @CookieParam("user") String userCookie, + @PathParam("id") String id) { + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + if (status.equals(Response.Status.OK)) { + PublisherEntity singlePublisher = PublisherEntity.find("id", UUID.fromString(id)).firstResult(); + if (singlePublisher == null) { + status = Response.Status.NOT_FOUND; + } else { + singlePublisher.status = 0; + singlePublisher.updated_at = LocalDateTime.now(); + singlePublisher.deleted_at = LocalDateTime.now(); + singlePublisher.persist(); + if (!singlePublisher.isPersistent()) { + status = Response.Status.NOT_MODIFIED; + } + } + } + return Response.status(status).build(); + } + + // PATCH + @PATCH + @RolesAllowed({"Admin", "User"}) + @Consumes(MediaType.APPLICATION_JSON) + @Transactional + @Path("{id}") + public Response updatePublisherAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, + PublisherEntity publishers, @PathParam("id") String id) { + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + + if (status.equals(Response.Status.OK)) { + + PublisherEntity publishersOrig = PublisherEntity.findById(UUID.fromString(id)); + if (publishersOrig == null) { + status = Response.Status.NOT_FOUND; + } else { + publishersOrig.description = publishers.description; + publishersOrig.url = publishers.url; + publishersOrig.type = publishers.type; + + publishersOrig.updated_at = LocalDateTime.now(); + + if(publishers.status == 1){ + publishersOrig.deleted_at = null; + publishersOrig.status = 1; + } + publishersOrig.persist(); + if (!publishersOrig.isPersistent()) { + status = Response.Status.NOT_MODIFIED; + } + } + } + return Response.status(status).build(); + } + + + + @PATCH + @RolesAllowed({"Admin", "User"}) + @Consumes(MediaType.APPLICATION_JSON) + @Transactional + @Path("enable/{id}") + public Response enableUserAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id) { + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + if (status.equals(Response.Status.OK)) { + + PublisherEntity publishersOrig = PublisherEntity.findById(UUID.fromString(id)); + if (publishersOrig == null) { + status = Response.Status.NOT_FOUND; + } else { + publishersOrig.status = 1; + publishersOrig.persist(); + if (!publishersOrig.isPersistent()) { + status = Response.Status.NOT_MODIFIED; + } + } + } + return Response.status(status).build(); + } +} diff --git a/src/main/java/com/covas/Resources/PublisherRessources.java b/src/main/java/com/covas/Resources/PublisherRessources.java index 4b694d2..aa32769 100644 --- a/src/main/java/com/covas/Resources/PublisherRessources.java +++ b/src/main/java/com/covas/Resources/PublisherRessources.java @@ -1,7 +1,6 @@ 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; @@ -15,7 +14,6 @@ import javax.ws.rs.CookieParam; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.PATCH; -import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -25,11 +23,9 @@ import javax.ws.rs.core.Context; 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.PublisherByUser; -import com.covas.Json.UserExist; import io.quarkus.panache.common.Page; import io.quarkus.panache.common.Parameters; From fecd1799a2f24a41873d681080e6d9b98456934a Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 9 Jan 2023 22:08:44 +0100 Subject: [PATCH 3/6] resources comment work --- .../covas/Resources/CommentRessources.java | 61 +++++++++---------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/covas/Resources/CommentRessources.java b/src/main/java/com/covas/Resources/CommentRessources.java index 76f729f..b988191 100644 --- a/src/main/java/com/covas/Resources/CommentRessources.java +++ b/src/main/java/com/covas/Resources/CommentRessources.java @@ -182,15 +182,15 @@ public class CommentRessources { UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user); if (status.equals(Response.Status.OK)) { - PublisherEntity singlePublisher = PublisherEntity.find("id", UUID.fromString(id)).firstResult(); - if (singlePublisher == null) { + CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult(); + if (singleComment == null) { status = Response.Status.NOT_FOUND; } else { - singlePublisher.status = -1; - singlePublisher.updated_at = LocalDateTime.now(); - singlePublisher.deleted_at = LocalDateTime.now(); - singlePublisher.persist(); - if (!singlePublisher.isPersistent()) { + singleComment.status = -1; + singleComment.updated_at = LocalDateTime.now(); + singleComment.deleted_at = LocalDateTime.now(); + singleComment.persist(); + if (!singleComment.isPersistent()) { status = Response.Status.NOT_MODIFIED; } } @@ -208,15 +208,15 @@ public class CommentRessources { UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user); if (status.equals(Response.Status.OK)) { - PublisherEntity singlePublisher = PublisherEntity.find("id", UUID.fromString(id)).firstResult(); - if (singlePublisher == null) { + CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult(); + if (singleComment == null) { status = Response.Status.NOT_FOUND; } else { - singlePublisher.status = 0; - singlePublisher.updated_at = LocalDateTime.now(); - singlePublisher.deleted_at = LocalDateTime.now(); - singlePublisher.persist(); - if (!singlePublisher.isPersistent()) { + singleComment.status = 0; + singleComment.updated_at = LocalDateTime.now(); + singleComment.deleted_at = LocalDateTime.now(); + singleComment.persist(); + if (!singleComment.isPersistent()) { status = Response.Status.NOT_MODIFIED; } } @@ -231,29 +231,28 @@ public class CommentRessources { @Transactional @Path("{id}") public Response updatePublisherAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, - PublisherEntity publishers, @PathParam("id") String id) { + CommentEntity comment, @PathParam("id") String id) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user); if (status.equals(Response.Status.OK)) { - PublisherEntity publishersOrig = PublisherEntity.findById(UUID.fromString(id)); - if (publishersOrig == null) { + CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id)); + if (commentOrig == null) { status = Response.Status.NOT_FOUND; } else { - publishersOrig.description = publishers.description; - publishersOrig.url = publishers.url; - publishersOrig.type = publishers.type; + commentOrig.comment = comment.comment; - publishersOrig.updated_at = LocalDateTime.now(); - if(publishers.status == 1){ - publishersOrig.deleted_at = null; - publishersOrig.status = 1; + commentOrig.updated_at = LocalDateTime.now(); + + if(comment.status == 1){ + commentOrig.deleted_at = null; + commentOrig.status = 1; } - publishersOrig.persist(); - if (!publishersOrig.isPersistent()) { + commentOrig.persist(); + if (!commentOrig.isPersistent()) { status = Response.Status.NOT_MODIFIED; } } @@ -274,13 +273,13 @@ public class CommentRessources { Response.Status status = getResponseCheck(ctx, userCookie, user); if (status.equals(Response.Status.OK)) { - PublisherEntity publishersOrig = PublisherEntity.findById(UUID.fromString(id)); - if (publishersOrig == null) { + CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id)); + if (commentOrig == null) { status = Response.Status.NOT_FOUND; } else { - publishersOrig.status = 1; - publishersOrig.persist(); - if (!publishersOrig.isPersistent()) { + commentOrig.status = 1; + commentOrig.persist(); + if (!commentOrig.isPersistent()) { status = Response.Status.NOT_MODIFIED; } } From f6018542cdeff9c86d9040004e34270b8c40f08f Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 9 Jan 2023 22:10:48 +0100 Subject: [PATCH 4/6] change name function for comment resources --- .../com/covas/Resources/CommentRessources.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/covas/Resources/CommentRessources.java b/src/main/java/com/covas/Resources/CommentRessources.java index b988191..c6e608f 100644 --- a/src/main/java/com/covas/Resources/CommentRessources.java +++ b/src/main/java/com/covas/Resources/CommentRessources.java @@ -70,7 +70,7 @@ public class CommentRessources { /// GET @GET @RolesAllowed("Admin") - public Response getPublishers(@CookieParam("user") String userCookie, @Context SecurityContext ctx, + public Response getComments(@CookieParam("user") String userCookie, @Context SecurityContext ctx, @QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages, @QueryParam("status") Short status, @QueryParam("search") String search, @@ -122,7 +122,7 @@ public class CommentRessources { @GET @RolesAllowed("Admin") @Path("{id}") - public Response getSinglePublisher(@PathParam("id") String id, @CookieParam("user") String userCookie, + public Response getSingleComment(@PathParam("id") String id, @CookieParam("user") String userCookie, @Context SecurityContext ctx) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); @@ -147,7 +147,7 @@ public class CommentRessources { @RolesAllowed({"Admin", "User"}) @Path("{id}") @Transactional - public Response createPublisher(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, CommentEntity comment) { + public Response createComment(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, CommentEntity comment) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); @@ -176,7 +176,7 @@ public class CommentRessources { @Path("{id}") @RolesAllowed({"Admin", "User"}) @Transactional - public Response changeStatusSinglePublisherToDelete(@Context SecurityContext ctx, @CookieParam("user") String userCookie, + public Response changeStatusSingleCommentToDelete(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); @@ -202,7 +202,7 @@ public class CommentRessources { @Path("/disable/{id}") @RolesAllowed({"Admin", "User"}) @Transactional - public Response changeStatusSinglePublisherToDisable(@Context SecurityContext ctx, @CookieParam("user") String userCookie, + public Response changeStatusSingleCommentToDisable(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); @@ -230,7 +230,7 @@ public class CommentRessources { @Consumes(MediaType.APPLICATION_JSON) @Transactional @Path("{id}") - public Response updatePublisherAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, + public Response updateCommentAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, CommentEntity comment, @PathParam("id") String id) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); @@ -267,7 +267,7 @@ public class CommentRessources { @Consumes(MediaType.APPLICATION_JSON) @Transactional @Path("enable/{id}") - public Response enableUserAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id) { + public Response enableCommentAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user); From 05ad21983f1bf56660df36071909a17dec092019 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 9 Jan 2023 22:22:53 +0100 Subject: [PATCH 5/6] fix publisher --- src/main/java/com/covas/Entity/PublisherEntity.java | 2 ++ src/main/java/com/covas/Resources/PublisherRessources.java | 1 + 2 files changed, 3 insertions(+) diff --git a/src/main/java/com/covas/Entity/PublisherEntity.java b/src/main/java/com/covas/Entity/PublisherEntity.java index fc5ea32..0c426ef 100644 --- a/src/main/java/com/covas/Entity/PublisherEntity.java +++ b/src/main/java/com/covas/Entity/PublisherEntity.java @@ -2,6 +2,7 @@ package com.covas.Entity; import java.io.Serializable; import java.time.LocalDateTime; +import java.util.Collection; import java.util.List; import java.util.UUID; @@ -16,6 +17,7 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; import javax.persistence.CascadeType; import org.hibernate.annotations.ColumnDefault; diff --git a/src/main/java/com/covas/Resources/PublisherRessources.java b/src/main/java/com/covas/Resources/PublisherRessources.java index aa32769..9d7ff12 100644 --- a/src/main/java/com/covas/Resources/PublisherRessources.java +++ b/src/main/java/com/covas/Resources/PublisherRessources.java @@ -155,6 +155,7 @@ public class PublisherRessources { } } Response responseHttp = Response.status(status).build(); + if (status.equals(Response.Status.OK)) { responseHttp = Response.status(status).entity(new PublisherByUser(user.pseudo, user.publisher)) .build(); From e5f9a8bab3ac92f8d520cd61d5594a9b815fbafc Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 9 Jan 2023 22:47:22 +0100 Subject: [PATCH 6/6] add comment status in README --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 63d4f45..9b59185 100644 --- a/README.md +++ b/README.md @@ -19,4 +19,14 @@ C'est la partie backend du projet COVAS généré par le générateur fourni par +## Statut du commentaire + +-1 : suppression +0 : desactivé +1 : activé +2 : censuré + + + +