fixed the comment object that was wrong

This commit is contained in:
Massimiliano Assante 2023-02-02 20:35:48 +01:00
parent 60e025cb5a
commit 4fb2cebe8d
1 changed files with 3 additions and 15 deletions

View File

@ -193,21 +193,11 @@ public class Comments {
String context = ScopeProvider.instance.get();
ResponseBean responseBean = new ResponseBean();
Status status = Status.OK;
//check that the postId exists first
String postId = comment.getPostid();
try {
CassandraConnection.getInstance().getDatabookStore().readPost(postId);
} catch(Exception e){
responseBean.setMessage("You're probably trying comment a post with id " + postId + " that does not exist ");
responseBean.setSuccess(false);
status = Status.INTERNAL_SERVER_ERROR;
return Response.status(status).entity(responseBean).build();
}
SocialMessageParser messageParser = new SocialMessageParser(comment.getText());
String escapedCommentText = messageParser.getParsedMessage();
// parse
String key = UUID.randomUUID().toString();
String postId = comment.getPostid();
String commentText = escapedCommentText;
String userid = username;
Date time = new Date();
@ -227,15 +217,13 @@ public class Comments {
}
String fullName = user.getFirstName() + " " + user.getLastName();
String thumbnailURL = user.getUserAvatarURL();
Date lastEditTime = null;
Comment theComment = new Comment(key, userid, lastEditTime, userid, commentText, fullName, thumbnailURL);
Comment theComment = new Comment(key, userid, time, postId, commentText, fullName, thumbnailURL);
boolean result = false;
try {
result = CassandraConnection.getInstance().getDatabookStore().addComment(theComment);
logger.info("Added comment? " + comment.toString() + " Result is " +result);
logger.info("Added comment? " + theComment.toString() + " Result is " +result);
} catch(Exception e){
e.printStackTrace();
responseBean.setMessage("Could not reach the DB to write the comment, something went wrong");