Conversation
akochar-sps
left a comment
There was a problem hiding this comment.
Overall looks okay, left some improvement comments.
| response.setContentType("application/json;"); | ||
| String json = new Gson().toJson(tasks); | ||
| System.out.println("get: " + tasks); | ||
| // System.out.println("get: " + tasks); |
There was a problem hiding this comment.
Dont add code as comments. Please remove.
| //add in nickname to commstream | ||
| UserService userService = UserServiceFactory.getUserService(); | ||
| String nickname = getUserNickname(userService.getCurrentUser().getUserId()); | ||
| System.out.println("nickname: " + nickname); |
There was a problem hiding this comment.
Is there a reason you are printing this. Debug comments like this can result in privacy concerns.
| UserService userService = UserServiceFactory.getUserService(); | ||
| String nickname = getUserNickname(userService.getCurrentUser().getUserId()); | ||
| System.out.println("nickname: " + nickname); | ||
| // commStream.add(nickname + ": ") //a way to make nicknames permanent |
There was a problem hiding this comment.
Again remove commented code in all places.
| if (entity == null) { | ||
| return null; | ||
| } | ||
| String nickname = (String) entity.getProperty("nickname"); | ||
| return nickname; | ||
| } |
There was a problem hiding this comment.
You could use a try and catch block here, instead of checking for entity null and catch on NullPointerException.
| out.println("<p>Set your nickname here:</p>"); | ||
| out.println("<form method=\"POST\" action=\"/nickname\">"); | ||
| out.println("<input name=\"nickname\" value=\"" + nickname + "\" />"); | ||
| out.println("<br/>"); | ||
| out.println("<button>Submit</button>"); | ||
| out.println("</form>"); |
There was a problem hiding this comment.
you can just do
out.println("
Set your nickname here:
" +"<form method="POST" action="/nickname">" +
"<input name="nickname" value="" + nickname + "" />" +
"
"+
"Submit" +
"");
There was a problem hiding this comment.
Better yet you can move the comment to a nickname_template.html file and just read it from there. This way you separate html from java. Here and other places.
There was a problem hiding this comment.
Ok! I have put in the code in the first comment and will put it into another file in the next branch.
| // The put() function automatically inserts new data or updates existing data based on ID | ||
| datastore.put(entity); | ||
|
|
||
| response.sendRedirect("/home"); |
There was a problem hiding this comment.
Can you comment why you want to redirect user to home here?
There was a problem hiding this comment.
No particular reason other than that it was included in the week 3 user-nicknames example. Thank you for catching it! It will be deleted by the next commit
| if (entity == null) { | ||
| return ""; | ||
| } | ||
| String nickname = (String) entity.getProperty("nickname"); | ||
| return nickname; |
There was a problem hiding this comment.
try {
return (String) entity.getProperty("nickname");
} catch ( NullPointerException e) {
// TODO: Log exception in server logs for records.
return "";
}
portfolio/src/main/webapp/script.js
Outdated
| // console.log(text); | ||
| parsed = JSON.parse(text); | ||
| parsed.reverse(); | ||
| // console.log(parsed); |
There was a problem hiding this comment.
Remove debug code here and other place.
portfolio/src/main/webapp/script.js
Outdated
| document.getElementById("text-field").style.display = "none"; | ||
| } | ||
| else { | ||
| fetch('/data').then(response => response.text())//fetch from data |
There was a problem hiding this comment.
What if fetch fails can you add error case here and other places.
There was a problem hiding this comment.
Done! I have made a function that throws an error if fetch fails and have implemented in every fetch call in this js file. It will appear in the next commit
| if (entity == null) { | ||
| return ""; | ||
| } | ||
| String nickname = (String) entity.getProperty("nickname"); | ||
| return nickname; |
There was a problem hiding this comment.
try {
return (String) entity.getProperty("nickname");
} catch ( NullPointerException e) {
// TODO: Log exception in server logs for records.
return "";
}
There was a problem hiding this comment.
I see this logic being used in multiple files, maybe pull it out to its own helper or util class, so you don't have to repeat code.
There was a problem hiding this comment.
Ok! I have implemented the code in the first comment(will appear in the next commit) and will pull out the logic in the next branch I make. Thank you!
…ause the problems are addressed here; it is not a new venture or addition per se
allows users to comment with changeable nicknames