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