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(); String context = ScopeProvider.instance.get();
ResponseBean responseBean = new ResponseBean(); ResponseBean responseBean = new ResponseBean();
Status status = Status.OK; 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()); SocialMessageParser messageParser = new SocialMessageParser(comment.getText());
String escapedCommentText = messageParser.getParsedMessage(); String escapedCommentText = messageParser.getParsedMessage();
// parse // parse
String key = UUID.randomUUID().toString(); String key = UUID.randomUUID().toString();
String postId = comment.getPostid();
String commentText = escapedCommentText; String commentText = escapedCommentText;
String userid = username; String userid = username;
Date time = new Date(); Date time = new Date();
@ -228,14 +218,12 @@ public class Comments {
String fullName = user.getFirstName() + " " + user.getLastName(); String fullName = user.getFirstName() + " " + user.getLastName();
String thumbnailURL = user.getUserAvatarURL(); String thumbnailURL = user.getUserAvatarURL();
Date lastEditTime = null; Comment theComment = new Comment(key, userid, time, postId, commentText, fullName, thumbnailURL);
Comment theComment = new Comment(key, userid, lastEditTime, userid, commentText, fullName, thumbnailURL);
boolean result = false; boolean result = false;
try { try {
result = CassandraConnection.getInstance().getDatabookStore().addComment(theComment); 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){ } catch(Exception e){
e.printStackTrace(); e.printStackTrace();
responseBean.setMessage("Could not reach the DB to write the comment, something went wrong"); responseBean.setMessage("Could not reach the DB to write the comment, something went wrong");