-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments with nicknames #7
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you comment why you want to redirect user to home here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if fetch fails can you add error case here and other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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