message ressources
This commit is contained in:
parent
0dba06a39b
commit
905fc40851
@ -147,27 +147,26 @@ public class MessageRessources {
|
|||||||
@RolesAllowed({"Admin", "User"})
|
@RolesAllowed({"Admin", "User"})
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@Transactional
|
@Transactional
|
||||||
public Response createComment(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, CommentEntity comment) {
|
public Response createMessage(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, MessageEntity message) {
|
||||||
|
|
||||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||||
UsersEntity user = UsersEntity.findById(kid);
|
UsersEntity user = UsersEntity.findById(kid);
|
||||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||||
CommentEntity newComment = new CommentEntity();
|
MessageEntity newMessage = new MessageEntity();
|
||||||
PublisherEntity publishers = PublisherEntity.findById(UUID.fromString(id));
|
|
||||||
if (status.equals(Response.Status.OK)) {
|
if (status.equals(Response.Status.OK)) {
|
||||||
newComment.comment = comment.comment;
|
newMessage.content = message.content;
|
||||||
newComment.users = user;
|
newMessage.conversation = message.conversation;
|
||||||
newComment.publishers = publishers;
|
newMessage.users = user;
|
||||||
newComment.created_at = LocalDateTime.now();
|
newMessage.created_at = LocalDateTime.now();
|
||||||
newComment.updated_at = LocalDateTime.now();
|
newMessage.updated_at = LocalDateTime.now();
|
||||||
newComment.persist();
|
newMessage.persist();
|
||||||
if (newComment.isPersistent()) {
|
if (newMessage.isPersistent()) {
|
||||||
status = Response.Status.CREATED;
|
status = Response.Status.CREATED;
|
||||||
} else {
|
} else {
|
||||||
status = Response.Status.NO_CONTENT;
|
status = Response.Status.NO_CONTENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Response.status(status).entity(newComment).build();
|
return Response.status(status).entity(newMessage).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -176,21 +175,21 @@ public class MessageRessources {
|
|||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed({"Admin", "User"})
|
@RolesAllowed({"Admin", "User"})
|
||||||
@Transactional
|
@Transactional
|
||||||
public Response changeStatusSingleCommentToDelete(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
public Response changeStatusSingleMessageToDelete(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
||||||
@PathParam("id") String id) {
|
@PathParam("id") String id) {
|
||||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||||
UsersEntity user = UsersEntity.findById(kid);
|
UsersEntity user = UsersEntity.findById(kid);
|
||||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||||
if (status.equals(Response.Status.OK)) {
|
if (status.equals(Response.Status.OK)) {
|
||||||
CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult();
|
MessageEntity singleMessage= MessageEntity.find("id", UUID.fromString(id)).firstResult();
|
||||||
if (singleComment == null) {
|
if (singleMessage == null) {
|
||||||
status = Response.Status.NOT_FOUND;
|
status = Response.Status.NOT_FOUND;
|
||||||
} else {
|
} else {
|
||||||
singleComment.status = -1;
|
singleMessage.status = -1;
|
||||||
singleComment.updated_at = LocalDateTime.now();
|
singleMessage.updated_at = LocalDateTime.now();
|
||||||
singleComment.deleted_at = LocalDateTime.now();
|
singleMessage.deleted_at = LocalDateTime.now();
|
||||||
singleComment.persist();
|
singleMessage.persist();
|
||||||
if (!singleComment.isPersistent()) {
|
if (!singleMessage.isPersistent()) {
|
||||||
status = Response.Status.NOT_MODIFIED;
|
status = Response.Status.NOT_MODIFIED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,23 +199,23 @@ public class MessageRessources {
|
|||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/disable/{id}")
|
@Path("/disable/{id}")
|
||||||
@RolesAllowed({"Admin", "User"})
|
@RolesAllowed("Admin")
|
||||||
@Transactional
|
@Transactional
|
||||||
public Response changeStatusSingleCommentToDisable(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
public Response changeStatusSingleMessageToDisable(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
||||||
@PathParam("id") String id) {
|
@PathParam("id") String id) {
|
||||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||||
UsersEntity user = UsersEntity.findById(kid);
|
UsersEntity user = UsersEntity.findById(kid);
|
||||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||||
if (status.equals(Response.Status.OK)) {
|
if (status.equals(Response.Status.OK)) {
|
||||||
CommentEntity singleComment = CommentEntity.find("id", UUID.fromString(id)).firstResult();
|
MessageEntity singleMessage = MessageEntity.find("id", UUID.fromString(id)).firstResult();
|
||||||
if (singleComment == null) {
|
if (singleMessage == null) {
|
||||||
status = Response.Status.NOT_FOUND;
|
status = Response.Status.NOT_FOUND;
|
||||||
} else {
|
} else {
|
||||||
singleComment.status = 0;
|
singleMessage.status = 0;
|
||||||
singleComment.updated_at = LocalDateTime.now();
|
singleMessage.updated_at = LocalDateTime.now();
|
||||||
singleComment.deleted_at = LocalDateTime.now();
|
singleMessage.deleted_at = LocalDateTime.now();
|
||||||
singleComment.persist();
|
singleMessage.persist();
|
||||||
if (!singleComment.isPersistent()) {
|
if (!singleMessage.isPersistent()) {
|
||||||
status = Response.Status.NOT_MODIFIED;
|
status = Response.Status.NOT_MODIFIED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -230,29 +229,29 @@ public class MessageRessources {
|
|||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Transactional
|
@Transactional
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
public Response updateCommentAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
public Response updateMessageAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
||||||
CommentEntity comment, @PathParam("id") String id) {
|
MessageEntity message, @PathParam("id") String id) {
|
||||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||||
UsersEntity user = UsersEntity.findById(kid);
|
UsersEntity user = UsersEntity.findById(kid);
|
||||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||||
|
|
||||||
if (status.equals(Response.Status.OK)) {
|
if (status.equals(Response.Status.OK)) {
|
||||||
|
|
||||||
CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id));
|
MessageEntity messageOrig = MessageEntity.findById(UUID.fromString(id));
|
||||||
if (commentOrig == null) {
|
if (messageOrig == null) {
|
||||||
status = Response.Status.NOT_FOUND;
|
status = Response.Status.NOT_FOUND;
|
||||||
} else {
|
} else {
|
||||||
commentOrig.comment = comment.comment;
|
messageOrig.content = message.content;
|
||||||
|
|
||||||
|
|
||||||
commentOrig.updated_at = LocalDateTime.now();
|
messageOrig.updated_at = LocalDateTime.now();
|
||||||
|
|
||||||
if(comment.status == 1){
|
if(message.status == 1){
|
||||||
commentOrig.deleted_at = null;
|
messageOrig.deleted_at = null;
|
||||||
commentOrig.status = 1;
|
messageOrig.status = 1;
|
||||||
}
|
}
|
||||||
commentOrig.persist();
|
messageOrig.persist();
|
||||||
if (!commentOrig.isPersistent()) {
|
if (!messageOrig.isPersistent()) {
|
||||||
status = Response.Status.NOT_MODIFIED;
|
status = Response.Status.NOT_MODIFIED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -263,7 +262,7 @@ public class MessageRessources {
|
|||||||
|
|
||||||
|
|
||||||
@PATCH
|
@PATCH
|
||||||
@RolesAllowed({"Admin", "User"})
|
@RolesAllowed("Admin")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Transactional
|
@Transactional
|
||||||
@Path("enable/{id}")
|
@Path("enable/{id}")
|
||||||
@ -273,13 +272,13 @@ public class MessageRessources {
|
|||||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||||
if (status.equals(Response.Status.OK)) {
|
if (status.equals(Response.Status.OK)) {
|
||||||
|
|
||||||
CommentEntity commentOrig = CommentEntity.findById(UUID.fromString(id));
|
MessageEntity messageOrig = MessageEntity.findById(UUID.fromString(id));
|
||||||
if (commentOrig == null) {
|
if (messageOrig == null) {
|
||||||
status = Response.Status.NOT_FOUND;
|
status = Response.Status.NOT_FOUND;
|
||||||
} else {
|
} else {
|
||||||
commentOrig.status = 1;
|
messageOrig.status = 1;
|
||||||
commentOrig.persist();
|
messageOrig.persist();
|
||||||
if (!commentOrig.isPersistent()) {
|
if (!messageOrig.isPersistent()) {
|
||||||
status = Response.Status.NOT_MODIFIED;
|
status = Response.Status.NOT_MODIFIED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user