Compare commits
43 Commits
127ed20959
...
master
Author | SHA1 | Date | |
---|---|---|---|
a500acf9bc | |||
22c68e7b21 | |||
04c018f5c0 | |||
809055f432 | |||
a88079f5fa | |||
905fc40851 | |||
0dba06a39b | |||
90ba63afd5 | |||
6d60e93d10 | |||
11c8437eb0 | |||
00a4875838 | |||
14420e101e | |||
b072ad7b70 | |||
efab19818d | |||
dcd00285f2 | |||
a29b534bba | |||
f8752395d4 | |||
981ed99434 | |||
c767a448e8 | |||
b6fc5783c9 | |||
4b8477b176 | |||
ee446fceb2 | |||
96bd7dec0e | |||
84d295e08f | |||
e3ab679f51 | |||
1e990820d1 | |||
b597bdb255 | |||
4b3b307d6d | |||
8aadc04fd5 | |||
3881009353 | |||
92f1eb8217 | |||
0803c18abb | |||
3c053b94ee | |||
2cb02ca223 | |||
d0f69044c4 | |||
48c535bf48 | |||
dac58bd99a | |||
69d5d3d5ee | |||
e5f9a8bab3 | |||
05ad21983f | |||
f6018542cd | |||
fecd1799a2 | |||
9233c16656 |
26
README.md
26
README.md
@@ -19,4 +19,30 @@ 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é
|
||||
|
||||
|
||||
## Statut de l'event
|
||||
|
||||
-1 : suppression
|
||||
0 : desactivé
|
||||
1 : activé
|
||||
2 : annulé
|
||||
|
||||
|
||||
|
||||
## Statut du groupe
|
||||
|
||||
-1 : suppression
|
||||
0 : desactivé
|
||||
1 : activé
|
||||
2 : bloqué
|
||||
|
||||
|
||||
|
||||
|
||||
|
6
pom.xml
6
pom.xml
@@ -80,6 +80,10 @@
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-redis-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-mongodb-panache</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-junit5</artifactId>
|
||||
@@ -132,7 +136,6 @@
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>native</id>
|
||||
|
||||
<activation>
|
||||
<property>
|
||||
<name>native</name>
|
||||
@@ -150,7 +153,6 @@
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
|
||||
<systemPropertyVariables>
|
||||
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
|
20
src/main/java/com/covas/Entity/BlacklistEntity.java
Normal file
20
src/main/java/com/covas/Entity/BlacklistEntity.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.covas.Entity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
|
||||
import io.quarkus.mongodb.panache.PanacheMongoEntity;
|
||||
import io.quarkus.mongodb.panache.common.MongoEntity;
|
||||
|
||||
@MongoEntity(collection="blacklist")
|
||||
public class BlacklistEntity extends PanacheMongoEntity {
|
||||
|
||||
public String owner;
|
||||
|
||||
public Collection<String> blocked;
|
||||
public Short status;
|
||||
|
||||
public LocalDateTime created_at;
|
||||
public LocalDateTime updated_at;
|
||||
public LocalDateTime deleted_at;
|
||||
}
|
@@ -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;
|
||||
|
||||
|
19
src/main/java/com/covas/Entity/ConversationEntity.java
Normal file
19
src/main/java/com/covas/Entity/ConversationEntity.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.covas.Entity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
|
||||
import io.quarkus.mongodb.panache.PanacheMongoEntity;
|
||||
import io.quarkus.mongodb.panache.common.MongoEntity;
|
||||
|
||||
@MongoEntity(collection="conversation")
|
||||
public class ConversationEntity extends PanacheMongoEntity {
|
||||
|
||||
|
||||
public Collection<String> users;
|
||||
public Short status;
|
||||
|
||||
public LocalDateTime created_at;
|
||||
public LocalDateTime updated_at;
|
||||
public LocalDateTime deleted_at;
|
||||
}
|
36
src/main/java/com/covas/Entity/EventEntity.java
Normal file
36
src/main/java/com/covas/Entity/EventEntity.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.covas.Entity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
|
||||
import com.covas.Enum.Confidentialite;
|
||||
import com.covas.Json.Organisateurs;
|
||||
|
||||
import io.quarkus.mongodb.panache.PanacheMongoEntity;
|
||||
import io.quarkus.mongodb.panache.common.MongoEntity;
|
||||
|
||||
@MongoEntity(collection="event")
|
||||
public class EventEntity extends PanacheMongoEntity {
|
||||
|
||||
public String name;
|
||||
|
||||
public Short status;
|
||||
|
||||
public String address;
|
||||
|
||||
public Organisateurs organisateurs;
|
||||
|
||||
public Collection<String> participants;
|
||||
|
||||
public Collection<String> interesses;
|
||||
|
||||
public Collection<String> publication;
|
||||
|
||||
public String reservation;
|
||||
|
||||
public Confidentialite confidentialite;
|
||||
|
||||
public LocalDateTime created_at;
|
||||
public LocalDateTime updated_at;
|
||||
public LocalDateTime deleted_at;
|
||||
}
|
20
src/main/java/com/covas/Entity/FriendEntity.java
Normal file
20
src/main/java/com/covas/Entity/FriendEntity.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.covas.Entity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
|
||||
import io.quarkus.mongodb.panache.PanacheMongoEntity;
|
||||
import io.quarkus.mongodb.panache.common.MongoEntity;
|
||||
|
||||
@MongoEntity(collection="friend")
|
||||
public class FriendEntity extends PanacheMongoEntity {
|
||||
|
||||
public String owner;
|
||||
|
||||
public Collection<String> friends;
|
||||
public Short status;
|
||||
|
||||
public LocalDateTime created_at;
|
||||
public LocalDateTime updated_at;
|
||||
public LocalDateTime deleted_at;
|
||||
}
|
25
src/main/java/com/covas/Entity/GroupEntity.java
Normal file
25
src/main/java/com/covas/Entity/GroupEntity.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.covas.Entity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
|
||||
import io.quarkus.mongodb.panache.PanacheMongoEntity;
|
||||
import io.quarkus.mongodb.panache.common.MongoEntity;
|
||||
|
||||
@MongoEntity(collection="group")
|
||||
public class GroupEntity extends PanacheMongoEntity {
|
||||
|
||||
public String name;
|
||||
|
||||
public Short status;
|
||||
|
||||
public Collection<String> admins;
|
||||
|
||||
public Collection<String> membres;
|
||||
|
||||
public Collection<String> publication;
|
||||
|
||||
public LocalDateTime created_at;
|
||||
public LocalDateTime updated_at;
|
||||
public LocalDateTime deleted_at;
|
||||
}
|
61
src/main/java/com/covas/Entity/MessageEntity.java
Normal file
61
src/main/java/com/covas/Entity/MessageEntity.java
Normal file
@@ -0,0 +1,61 @@
|
||||
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.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 io.quarkus.hibernate.orm.panache.PanacheEntityBase;
|
||||
|
||||
|
||||
@Entity
|
||||
@Table(name = "message")
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "Message.bySearch", query = "from MessageEntity u where u.content like :content"),
|
||||
})
|
||||
public class MessageEntity 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 content;
|
||||
|
||||
@Column(nullable = false)
|
||||
public LocalDateTime created_at;
|
||||
@Column(nullable = false)
|
||||
public LocalDateTime updated_at;
|
||||
@ColumnDefault("null")
|
||||
public LocalDateTime deleted_at;
|
||||
|
||||
public String conversation;
|
||||
|
||||
@ColumnDefault("1")
|
||||
public Short status;
|
||||
|
||||
@ManyToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "users_id", referencedColumnName = "id")
|
||||
public UsersEntity users;
|
||||
|
||||
|
||||
public static List<MessageEntity> findByUsers(String uuid){
|
||||
return find("users_id", uuid).list();
|
||||
}
|
||||
}
|
@@ -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;
|
||||
|
@@ -80,6 +80,9 @@ public class UsersEntity extends PanacheEntityBase implements Serializable {
|
||||
@OneToMany(mappedBy = "users")
|
||||
public Collection<CommentEntity> comment;
|
||||
|
||||
@OneToMany(mappedBy = "users")
|
||||
public Collection<MessageEntity> message;
|
||||
|
||||
public static UsersEntity findByPseudo(String pseudo){
|
||||
return find("pseudo", pseudo).firstResult();
|
||||
}
|
||||
@@ -102,8 +105,6 @@ public class UsersEntity extends PanacheEntityBase implements Serializable {
|
||||
users.created_at = LocalDateTime.now();
|
||||
users.updated_at = LocalDateTime.now();
|
||||
users.description = "";
|
||||
|
||||
users.persist();
|
||||
|
||||
}
|
||||
}
|
6
src/main/java/com/covas/Enum/Confidentialite.java
Normal file
6
src/main/java/com/covas/Enum/Confidentialite.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package com.covas.Enum;
|
||||
|
||||
public enum Confidentialite {
|
||||
PUBLIC, FRIEND, PRIVATE
|
||||
|
||||
}
|
22
src/main/java/com/covas/Json/MessageByUser.java
Normal file
22
src/main/java/com/covas/Json/MessageByUser.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.covas.Json;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.covas.Entity.MessageEntity;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
public class MessageByUser {
|
||||
|
||||
public final String pseudo;
|
||||
public final Collection<MessageEntity> message;
|
||||
|
||||
public MessageByUser(String pseudo, Collection<MessageEntity> message){
|
||||
this.pseudo = pseudo;
|
||||
this.message = message;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
21
src/main/java/com/covas/Json/Organisateurs.java
Normal file
21
src/main/java/com/covas/Json/Organisateurs.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.covas.Json;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
public class Organisateurs {
|
||||
|
||||
public Collection<String> users_id;
|
||||
public Collection<String> groups_id;
|
||||
|
||||
public Organisateurs(){
|
||||
|
||||
}
|
||||
|
||||
public Organisateurs(Collection<String> users_id, Collection<String> groups_id){
|
||||
this.users_id = users_id;
|
||||
this.groups_id = groups_id;
|
||||
}
|
||||
}
|
235
src/main/java/com/covas/Resources/BlacklistRessources.java
Normal file
235
src/main/java/com/covas/Resources/BlacklistRessources.java
Normal file
@@ -0,0 +1,235 @@
|
||||
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.BlacklistEntity;
|
||||
import com.covas.Entity.UsersEntity;
|
||||
|
||||
import io.quarkus.panache.common.Page;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
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("blacklist")
|
||||
public class BlacklistRessources {
|
||||
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 getBlacklist(@CookieParam("user") String userCookie, @Context SecurityContext ctx,
|
||||
@QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages) {
|
||||
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<BlacklistEntity> listBlacklist = BlacklistEntity.findAll().page(Page.of(page, nbPages)).list();
|
||||
responseHttp = Response.ok(listBlacklist).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(BlacklistEntity.count()).build();
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
@GET
|
||||
@RolesAllowed("Admin")
|
||||
@Path("{id}")
|
||||
public Response getSingleBlacklist(@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)) {
|
||||
BlacklistEntity blacklist = BlacklistEntity.findById(new ObjectId(id));
|
||||
responseHttp = Response.status(Response.Status.NOT_FOUND).build();
|
||||
if (blacklist != null) {
|
||||
responseHttp = Response.ok(blacklist).build();
|
||||
}
|
||||
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@RolesAllowed("Admin")
|
||||
@Path("/user/{id}")
|
||||
public Response getSingleBlacklistbyOwner(@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)) {
|
||||
BlacklistEntity blacklist = BlacklistEntity.find("owner", id).firstResult();
|
||||
responseHttp = Response.status(Response.Status.NOT_FOUND).build();
|
||||
if (blacklist != null) {
|
||||
responseHttp = Response.ok(blacklist).build();
|
||||
}
|
||||
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
|
||||
// PUT
|
||||
@PUT
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Path("{id}")
|
||||
@Transactional
|
||||
public Response createBlacklist(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, BlacklistEntity blacklist) {
|
||||
|
||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||
UsersEntity user = UsersEntity.findById(kid);
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
BlacklistEntity newBlacklist = new BlacklistEntity();
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
newBlacklist.owner = blacklist.owner;
|
||||
newBlacklist.blocked = blacklist.blocked;
|
||||
newBlacklist.created_at = LocalDateTime.now();
|
||||
newBlacklist.updated_at = LocalDateTime.now();
|
||||
newBlacklist.persist();
|
||||
status = Response.Status.CREATED;
|
||||
|
||||
}
|
||||
return Response.status(status).entity(newBlacklist).build();
|
||||
}
|
||||
|
||||
|
||||
// DELETE
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Transactional
|
||||
public Response changeStatusSingleBlacklistToDelete(@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)) {
|
||||
BlacklistEntity singleBlacklist = BlacklistEntity.find("id", new ObjectId(id)).firstResult();
|
||||
if (singleBlacklist == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
singleBlacklist.status = -1;
|
||||
singleBlacklist.updated_at = LocalDateTime.now();
|
||||
singleBlacklist.deleted_at = LocalDateTime.now();
|
||||
singleBlacklist.persist();
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// PATCH
|
||||
@PATCH
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Transactional
|
||||
@Path("{id}")
|
||||
public Response updateBlacklist(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
||||
BlacklistEntity blacklist, @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)) {
|
||||
|
||||
BlacklistEntity blacklistOrig = BlacklistEntity.findById(new ObjectId(id));
|
||||
if (blacklistOrig == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
blacklistOrig.owner = blacklist.owner;
|
||||
blacklistOrig.blocked = blacklist.blocked;
|
||||
|
||||
|
||||
blacklistOrig.updated_at = LocalDateTime.now();
|
||||
|
||||
if(blacklist.status == 1){
|
||||
blacklistOrig.deleted_at = null;
|
||||
blacklistOrig.status = 1;
|
||||
}
|
||||
blacklistOrig.persist();
|
||||
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
}
|
288
src/main/java/com/covas/Resources/CommentRessources.java
Normal file
288
src/main/java/com/covas/Resources/CommentRessources.java
Normal file
@@ -0,0 +1,288 @@
|
||||
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 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 getComments(@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<CommentEntity> listComments = CommentEntity.findAll().page(Page.of(page, nbPages)).list();
|
||||
|
||||
|
||||
responseHttp = Response.ok(listComments).build();
|
||||
if(uuid != null){
|
||||
CommentEntity commentSingle = CommentEntity.findById(UUID.fromString(uuid));
|
||||
responseHttp = Response.ok(commentSingle).build();
|
||||
}
|
||||
|
||||
if(search != null){
|
||||
List<CommentEntity> 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 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);
|
||||
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 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);
|
||||
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 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);
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult();
|
||||
if (singleComment == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
singleComment.status = -1;
|
||||
singleComment.updated_at = LocalDateTime.now();
|
||||
singleComment.deleted_at = LocalDateTime.now();
|
||||
singleComment.persist();
|
||||
if (!singleComment.isPersistent()) {
|
||||
status = Response.Status.NOT_MODIFIED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/disable/{id}")
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Transactional
|
||||
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);
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult();
|
||||
if (singleComment == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
singleComment.status = 0;
|
||||
singleComment.updated_at = LocalDateTime.now();
|
||||
singleComment.deleted_at = LocalDateTime.now();
|
||||
singleComment.persist();
|
||||
if (!singleComment.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 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);
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
|
||||
CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id));
|
||||
if (commentOrig == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
commentOrig.comment = comment.comment;
|
||||
|
||||
|
||||
commentOrig.updated_at = LocalDateTime.now();
|
||||
|
||||
if(comment.status == 1){
|
||||
commentOrig.deleted_at = null;
|
||||
commentOrig.status = 1;
|
||||
}
|
||||
commentOrig.persist();
|
||||
if (!commentOrig.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 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);
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
|
||||
CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id));
|
||||
if (commentOrig == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
commentOrig.status = 1;
|
||||
commentOrig.persist();
|
||||
if (!commentOrig.isPersistent()) {
|
||||
status = Response.Status.NOT_MODIFIED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
}
|
213
src/main/java/com/covas/Resources/ConversationRessources.java
Normal file
213
src/main/java/com/covas/Resources/ConversationRessources.java
Normal file
@@ -0,0 +1,213 @@
|
||||
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.ConversationEntity;
|
||||
import com.covas.Entity.UsersEntity;
|
||||
|
||||
import io.quarkus.panache.common.Page;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
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("conversation")
|
||||
public class ConversationRessources {
|
||||
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 getFriends(@CookieParam("user") String userCookie, @Context SecurityContext ctx,
|
||||
@QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages) {
|
||||
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<ConversationEntity> listConversations = ConversationEntity.findAll().page(Page.of(page, nbPages)).list();
|
||||
responseHttp = Response.ok(listConversations).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(ConversationEntity.count()).build();
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
@GET
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Path("{id}")
|
||||
public Response getSingleFriend(@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)) {
|
||||
ConversationEntity conversation = ConversationEntity.findById(new ObjectId(id));
|
||||
responseHttp = Response.status(Response.Status.NOT_FOUND).build();
|
||||
if (conversation != null) {
|
||||
responseHttp = Response.ok(conversation).build();
|
||||
}
|
||||
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// PUT
|
||||
@PUT
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Path("{id}")
|
||||
@Transactional
|
||||
public Response createFriend(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, ConversationEntity conversation) {
|
||||
|
||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||
UsersEntity user = UsersEntity.findById(kid);
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
ConversationEntity newConversation = new ConversationEntity();
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
newConversation.users = conversation.users;
|
||||
newConversation.created_at = LocalDateTime.now();
|
||||
newConversation.updated_at = LocalDateTime.now();
|
||||
newConversation.persist();
|
||||
status = Response.Status.CREATED;
|
||||
|
||||
}
|
||||
return Response.status(status).entity(newConversation).build();
|
||||
}
|
||||
|
||||
|
||||
// DELETE
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Transactional
|
||||
public Response changeStatusSingleFriendToDelete(@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)) {
|
||||
ConversationEntity singleConversation = ConversationEntity.find("id", new ObjectId(id)).firstResult();
|
||||
if (singleConversation == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
singleConversation.status = -1;
|
||||
singleConversation.updated_at = LocalDateTime.now();
|
||||
singleConversation.deleted_at = LocalDateTime.now();
|
||||
singleConversation.persist();
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// PATCH
|
||||
@PATCH
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Transactional
|
||||
@Path("{id}")
|
||||
public Response updateFriend(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
||||
ConversationEntity conversation, @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)) {
|
||||
|
||||
ConversationEntity conversationOrig = ConversationEntity.findById(new ObjectId(id));
|
||||
if (conversationOrig == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
conversationOrig.users = conversation.users;
|
||||
|
||||
|
||||
conversationOrig.updated_at = LocalDateTime.now();
|
||||
|
||||
if(conversation.status == 1){
|
||||
conversationOrig.deleted_at = null;
|
||||
conversationOrig.status = 1;
|
||||
}
|
||||
conversationOrig.persist();
|
||||
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
}
|
300
src/main/java/com/covas/Resources/EventRessources.java
Normal file
300
src/main/java/com/covas/Resources/EventRessources.java
Normal file
@@ -0,0 +1,300 @@
|
||||
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.EventEntity;
|
||||
import com.covas.Entity.UsersEntity;
|
||||
|
||||
import io.quarkus.panache.common.Page;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
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("event")
|
||||
public class EventRessources {
|
||||
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 getEvents(@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<EventEntity> listEvents = EventEntity.findAll().page(Page.of(page, nbPages)).list();
|
||||
|
||||
|
||||
responseHttp = Response.ok(listEvents).build();
|
||||
if(uuid != null){
|
||||
EventEntity eventSingle= EventEntity.findById(new ObjectId(uuid));
|
||||
responseHttp = Response.ok(eventSingle).build();
|
||||
}
|
||||
|
||||
if(search != null){
|
||||
List<EventEntity> eventsList = EventEntity.find("name", search).page(Page.of(page, nbPages)).list();
|
||||
responseHttp = Response.ok(eventsList).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(EventEntity.count()).build();
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
@GET
|
||||
@RolesAllowed("Admin")
|
||||
@Path("{id}")
|
||||
public Response getSingleEvent(@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)) {
|
||||
EventEntity event = EventEntity.findById(new ObjectId(id));
|
||||
responseHttp = Response.status(Response.Status.NOT_FOUND).build();
|
||||
if (event != null) {
|
||||
responseHttp = Response.ok(event).build();
|
||||
}
|
||||
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
|
||||
// PUT
|
||||
@PUT
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Path("{id}")
|
||||
@Transactional
|
||||
public Response createEvent(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, EventEntity event) {
|
||||
|
||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||
UsersEntity user = UsersEntity.findById(kid);
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
EventEntity newEvent = new EventEntity();
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
newEvent.name = event.name;
|
||||
newEvent.address = event.address;
|
||||
newEvent.organisateurs = event.organisateurs;
|
||||
newEvent.reservation = event.reservation;
|
||||
newEvent.confidentialite = event.confidentialite;
|
||||
newEvent.created_at = LocalDateTime.now();
|
||||
newEvent.updated_at = LocalDateTime.now();
|
||||
newEvent.persist();
|
||||
status = Response.Status.CREATED;
|
||||
|
||||
}
|
||||
return Response.status(status).entity(newEvent).build();
|
||||
}
|
||||
|
||||
|
||||
// DELETE
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Transactional
|
||||
public Response changeStatusSingleEventToDelete(@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)) {
|
||||
EventEntity singleEvent = EventEntity.find("id", new ObjectId(id)).firstResult();
|
||||
if (singleEvent == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
singleEvent.status = -1;
|
||||
singleEvent.updated_at = LocalDateTime.now();
|
||||
singleEvent.deleted_at = LocalDateTime.now();
|
||||
singleEvent.persist();
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/disable/{id}")
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Transactional
|
||||
public Response changeStatusSingleEventToDisable(@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)) {
|
||||
EventEntity singleEvent = EventEntity.find("id", new ObjectId(id)).firstResult();
|
||||
if (singleEvent == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
singleEvent.status = 0;
|
||||
singleEvent.updated_at = LocalDateTime.now();
|
||||
singleEvent.deleted_at = LocalDateTime.now();
|
||||
singleEvent.persist();
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
|
||||
// PATCH
|
||||
@PATCH
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Transactional
|
||||
@Path("{id}")
|
||||
public Response updateEvent(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
||||
EventEntity event, @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)) {
|
||||
|
||||
EventEntity eventOrig = EventEntity.findById(new ObjectId(id));
|
||||
if (eventOrig == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
eventOrig.name = event.name;
|
||||
|
||||
|
||||
eventOrig.updated_at = LocalDateTime.now();
|
||||
|
||||
if(event.status == 1){
|
||||
eventOrig.deleted_at = null;
|
||||
eventOrig.status = 1;
|
||||
}
|
||||
eventOrig.persist();
|
||||
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PATCH
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Transactional
|
||||
@Path("enable/{id}")
|
||||
public Response enableEvent(@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)) {
|
||||
|
||||
EventEntity eventOrig = EventEntity.findById(new ObjectId(id));
|
||||
if (eventOrig == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
eventOrig.status = 1;
|
||||
eventOrig.persist();
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
|
||||
// Patch
|
||||
|
||||
@PATCH
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Path("{id}")
|
||||
@Transactional
|
||||
public Response createPublishers(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, @PathParam("publisher") String publisher) {
|
||||
|
||||
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)) {
|
||||
EventEntity singleEvent = EventEntity.find("id", new ObjectId(id)).firstResult();
|
||||
status = Response.Status.NOT_FOUND;
|
||||
if(singleEvent != null){
|
||||
status = Response.Status.NOT_MODIFIED;
|
||||
if(singleEvent.publication.add(publisher)){
|
||||
singleEvent.updated_at = LocalDateTime.now();
|
||||
singleEvent.persist();
|
||||
status = Response.Status.CREATED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
}
|
233
src/main/java/com/covas/Resources/FriendRessources.java
Normal file
233
src/main/java/com/covas/Resources/FriendRessources.java
Normal file
@@ -0,0 +1,233 @@
|
||||
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.FriendEntity;
|
||||
import com.covas.Entity.UsersEntity;
|
||||
|
||||
import io.quarkus.panache.common.Page;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
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("friend")
|
||||
public class FriendRessources {
|
||||
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 getFriends(@CookieParam("user") String userCookie, @Context SecurityContext ctx,
|
||||
@QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages) {
|
||||
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<FriendEntity> listFriends = FriendEntity.findAll().page(Page.of(page, nbPages)).list();
|
||||
responseHttp = Response.ok(listFriends).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(FriendEntity.count()).build();
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
@GET
|
||||
@RolesAllowed("Admin")
|
||||
@Path("{id}")
|
||||
public Response getSingleFriend(@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)) {
|
||||
FriendEntity friend = FriendEntity.findById(new ObjectId(id));
|
||||
responseHttp = Response.status(Response.Status.NOT_FOUND).build();
|
||||
if (friend != null) {
|
||||
responseHttp = Response.ok(friend).build();
|
||||
}
|
||||
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@RolesAllowed("Admin")
|
||||
@Path("/user/{id}")
|
||||
public Response getSingleFriendbyOwner(@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)) {
|
||||
FriendEntity friend = FriendEntity.find("owner", id).firstResult();
|
||||
responseHttp = Response.status(Response.Status.NOT_FOUND).build();
|
||||
if (friend != null) {
|
||||
responseHttp = Response.ok(friend).build();
|
||||
}
|
||||
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
|
||||
// PUT
|
||||
@PUT
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Path("{id}")
|
||||
@Transactional
|
||||
public Response createFriend(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, FriendEntity friend) {
|
||||
|
||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||
UsersEntity user = UsersEntity.findById(kid);
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
FriendEntity newFriend = new FriendEntity();
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
newFriend.owner = friend.owner;
|
||||
newFriend.friends = friend.friends;
|
||||
newFriend.created_at = LocalDateTime.now();
|
||||
newFriend.updated_at = LocalDateTime.now();
|
||||
newFriend.persist();
|
||||
status = Response.Status.CREATED;
|
||||
|
||||
}
|
||||
return Response.status(status).entity(newFriend).build();
|
||||
}
|
||||
|
||||
|
||||
// DELETE
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Transactional
|
||||
public Response changeStatusSingleFriendToDelete(@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)) {
|
||||
FriendEntity singleFriend = FriendEntity.find("id", new ObjectId(id)).firstResult();
|
||||
if (singleFriend == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
singleFriend.status = -1;
|
||||
singleFriend.updated_at = LocalDateTime.now();
|
||||
singleFriend.deleted_at = LocalDateTime.now();
|
||||
singleFriend.persist();
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// PATCH
|
||||
@PATCH
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Transactional
|
||||
@Path("{id}")
|
||||
public Response updateFriend(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
||||
FriendEntity friend, @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)) {
|
||||
|
||||
FriendEntity friendOrig = FriendEntity.findById(new ObjectId(id));
|
||||
if (friendOrig == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
friendOrig.owner = friend.owner;
|
||||
friendOrig.friends = friend.friends;
|
||||
|
||||
|
||||
friendOrig.updated_at = LocalDateTime.now();
|
||||
|
||||
if(friend.status == 1){
|
||||
friendOrig.deleted_at = null;
|
||||
friendOrig.status = 1;
|
||||
}
|
||||
friendOrig.persist();
|
||||
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
}
|
298
src/main/java/com/covas/Resources/GroupRessources.java
Normal file
298
src/main/java/com/covas/Resources/GroupRessources.java
Normal file
@@ -0,0 +1,298 @@
|
||||
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.GroupEntity;
|
||||
import com.covas.Entity.UsersEntity;
|
||||
|
||||
import io.quarkus.panache.common.Page;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
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("group")
|
||||
public class GroupRessources {
|
||||
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 getGroups(@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<GroupEntity> listGroups = GroupEntity.findAll().page(Page.of(page, nbPages)).list();
|
||||
|
||||
|
||||
responseHttp = Response.ok(listGroups).build();
|
||||
if(uuid != null){
|
||||
GroupEntity groupSingle= GroupEntity.findById(new ObjectId(uuid));
|
||||
responseHttp = Response.ok(groupSingle).build();
|
||||
}
|
||||
|
||||
if(search != null){
|
||||
List<GroupEntity> groupsList = GroupEntity.find("name", search).page(Page.of(page, nbPages)).list();
|
||||
responseHttp = Response.ok(groupsList).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(GroupEntity.count()).build();
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
@GET
|
||||
@RolesAllowed("Admin")
|
||||
@Path("{id}")
|
||||
public Response getSingleGroup(@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)) {
|
||||
GroupEntity group = GroupEntity.findById(new ObjectId(id));
|
||||
responseHttp = Response.status(Response.Status.NOT_FOUND).build();
|
||||
if (group != null) {
|
||||
responseHttp = Response.ok(group).build();
|
||||
}
|
||||
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
|
||||
// PUT
|
||||
@PUT
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Path("{id}")
|
||||
@Transactional
|
||||
public Response createGroup(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, GroupEntity group) {
|
||||
|
||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||
UsersEntity user = UsersEntity.findById(kid);
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
GroupEntity newGroup = new GroupEntity();
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
newGroup.name = group.name;
|
||||
newGroup.admins = group.admins;
|
||||
newGroup.created_at = LocalDateTime.now();
|
||||
newGroup.updated_at = LocalDateTime.now();
|
||||
newGroup.persist();
|
||||
status = Response.Status.CREATED;
|
||||
|
||||
}
|
||||
return Response.status(status).entity(newGroup).build();
|
||||
}
|
||||
|
||||
// Patch
|
||||
|
||||
@PATCH
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Path("{id}")
|
||||
@Transactional
|
||||
public Response createPublishers(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, @PathParam("publisher") String publisher) {
|
||||
|
||||
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)) {
|
||||
GroupEntity singleGroup = GroupEntity.find("id", new ObjectId(id)).firstResult();
|
||||
status = Response.Status.NOT_FOUND;
|
||||
if(singleGroup != null){
|
||||
status = Response.Status.NOT_MODIFIED;
|
||||
if(singleGroup.publication.add(publisher)){
|
||||
singleGroup.updated_at = LocalDateTime.now();
|
||||
singleGroup.persist();
|
||||
status = Response.Status.CREATED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
|
||||
|
||||
// DELETE
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Transactional
|
||||
public Response changeStatusSingleGroupToDelete(@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)) {
|
||||
GroupEntity singleGroup = GroupEntity.find("id", new ObjectId(id)).firstResult();
|
||||
if (singleGroup == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
singleGroup.status = -1;
|
||||
singleGroup.updated_at = LocalDateTime.now();
|
||||
singleGroup.deleted_at = LocalDateTime.now();
|
||||
singleGroup.persist();
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/disable/{id}")
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Transactional
|
||||
public Response changeStatusSingleGroupToDisable(@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)) {
|
||||
GroupEntity singleGroup = GroupEntity.find("id", new ObjectId(id)).firstResult();
|
||||
if (singleGroup == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
singleGroup.status = 0;
|
||||
singleGroup.updated_at = LocalDateTime.now();
|
||||
singleGroup.deleted_at = LocalDateTime.now();
|
||||
singleGroup.persist();
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
|
||||
// PATCH
|
||||
@PATCH
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Transactional
|
||||
@Path("{id}")
|
||||
public Response updateGroup(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
||||
GroupEntity group, @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)) {
|
||||
|
||||
GroupEntity groupOrig = GroupEntity.findById(new ObjectId(id));
|
||||
if (groupOrig == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
groupOrig.name = group.name;
|
||||
|
||||
|
||||
groupOrig.updated_at = LocalDateTime.now();
|
||||
|
||||
if(group.status == 1){
|
||||
groupOrig.deleted_at = null;
|
||||
groupOrig.status = 1;
|
||||
}
|
||||
groupOrig.persist();
|
||||
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PATCH
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Transactional
|
||||
@Path("enable/{id}")
|
||||
public Response enableGroup(@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)) {
|
||||
|
||||
GroupEntity groupOrig = GroupEntity.findById(new ObjectId(id));
|
||||
if (groupOrig == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
groupOrig.status = 1;
|
||||
groupOrig.persist();
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
}
|
312
src/main/java/com/covas/Resources/MessageRessources.java
Normal file
312
src/main/java/com/covas/Resources/MessageRessources.java
Normal file
@@ -0,0 +1,312 @@
|
||||
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.MessageEntity;
|
||||
import com.covas.Entity.UsersEntity;
|
||||
import com.covas.Json.MessageByUser;
|
||||
|
||||
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("message")
|
||||
public class MessageRessources {
|
||||
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 getMessages(@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<MessageEntity> listMessages = MessageEntity.findAll().page(Page.of(page, nbPages)).list();
|
||||
|
||||
|
||||
responseHttp = Response.ok(listMessages).build();
|
||||
if(uuid != null){
|
||||
MessageEntity messageEntity= MessageEntity.findById(UUID.fromString(uuid));
|
||||
responseHttp = Response.ok(messageEntity).build();
|
||||
}
|
||||
|
||||
if(search != null){
|
||||
List<MessageEntity> messagesList = MessageEntity.find("#Message.bySearch", Parameters.with("content", search)).page(Page.of(page, nbPages)).list();
|
||||
|
||||
responseHttp = Response.ok(messagesList).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(MessageEntity.count()).build();
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
@GET
|
||||
@RolesAllowed("Admin")
|
||||
@Path("{id}")
|
||||
public Response getSingleMessage(@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);
|
||||
MessageEntity message = MessageEntity.findById(uid);
|
||||
responseHttp = Response.status(Response.Status.NOT_FOUND).build();
|
||||
if (message != null) {
|
||||
responseHttp = Response.ok(message).build();
|
||||
}
|
||||
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
@GET
|
||||
@RolesAllowed("User")
|
||||
@Path("info")
|
||||
public Response getInfoMessage(@Context SecurityContext ctx, @CookieParam("user") String userCookie) {
|
||||
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)) {
|
||||
if (user == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
}
|
||||
if (!checkUserCookie(userCookie, user)) {
|
||||
status = Response.Status.FORBIDDEN;
|
||||
}
|
||||
}
|
||||
Response responseHttp = Response.status(status).build();
|
||||
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
responseHttp = Response.status(status).entity(new MessageByUser(user.pseudo, user.message))
|
||||
.build();
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// PUT
|
||||
@PUT
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Path("{id}")
|
||||
@Transactional
|
||||
public Response createMessage(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, MessageEntity message) {
|
||||
|
||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||
UsersEntity user = UsersEntity.findById(kid);
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
MessageEntity newMessage = new MessageEntity();
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
newMessage.content = message.content;
|
||||
newMessage.conversation = message.conversation;
|
||||
newMessage.users = user;
|
||||
newMessage.created_at = LocalDateTime.now();
|
||||
newMessage.updated_at = LocalDateTime.now();
|
||||
newMessage.persist();
|
||||
if (newMessage.isPersistent()) {
|
||||
status = Response.Status.CREATED;
|
||||
} else {
|
||||
status = Response.Status.NO_CONTENT;
|
||||
}
|
||||
}
|
||||
return Response.status(status).entity(newMessage).build();
|
||||
}
|
||||
|
||||
|
||||
// DELETE
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Transactional
|
||||
public Response changeStatusSingleMessageToDelete(@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)) {
|
||||
MessageEntity singleMessage= MessageEntity.find("id", UUID.fromString(id)).firstResult();
|
||||
if (singleMessage == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
singleMessage.status = -1;
|
||||
singleMessage.updated_at = LocalDateTime.now();
|
||||
singleMessage.deleted_at = LocalDateTime.now();
|
||||
singleMessage.persist();
|
||||
if (!singleMessage.isPersistent()) {
|
||||
status = Response.Status.NOT_MODIFIED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/disable/{id}")
|
||||
@RolesAllowed("Admin")
|
||||
@Transactional
|
||||
public Response changeStatusSingleMessageToDisable(@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)) {
|
||||
MessageEntity singleMessage = MessageEntity.find("id", UUID.fromString(id)).firstResult();
|
||||
if (singleMessage == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
singleMessage.status = 0;
|
||||
singleMessage.updated_at = LocalDateTime.now();
|
||||
singleMessage.deleted_at = LocalDateTime.now();
|
||||
singleMessage.persist();
|
||||
if (!singleMessage.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 updateMessageAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
||||
MessageEntity message, @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)) {
|
||||
|
||||
MessageEntity messageOrig = MessageEntity.findById(UUID.fromString(id));
|
||||
if (messageOrig == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
messageOrig.content = message.content;
|
||||
|
||||
|
||||
messageOrig.updated_at = LocalDateTime.now();
|
||||
|
||||
if(message.status == 1){
|
||||
messageOrig.deleted_at = null;
|
||||
messageOrig.status = 1;
|
||||
}
|
||||
messageOrig.persist();
|
||||
if (!messageOrig.isPersistent()) {
|
||||
status = Response.Status.NOT_MODIFIED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PATCH
|
||||
@RolesAllowed("Admin")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Transactional
|
||||
@Path("enable/{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);
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
|
||||
MessageEntity messageOrig = MessageEntity.findById(UUID.fromString(id));
|
||||
if (messageOrig == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
messageOrig.status = 1;
|
||||
messageOrig.persist();
|
||||
if (!messageOrig.isPersistent()) {
|
||||
status = Response.Status.NOT_MODIFIED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
}
|
||||
}
|
@@ -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;
|
||||
@@ -159,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();
|
||||
|
@@ -33,3 +33,6 @@ quarkus.http.cors.access-control-allow-credentials=true
|
||||
|
||||
#quarkus.native.additional-build-args=-H:IncludeResources=.*\\.pem,.\\*.txt
|
||||
quarkus.native.additional-build-args=-H:ResourceConfigurationFiles=${RESOURCES:resource-config.json}
|
||||
|
||||
quarkus.mongodb.connection-string=mongodb://${MONGO_USER:admin}:${MONGO_PASSWORD:mongo}@${MONGO_HOST:mongo}:${MONGO_PORT:27017}
|
||||
quarkus.mongodb.database = ${MONGO_DATABASE:admin}:
|
Reference in New Issue
Block a user