-
Notifications
You must be signed in to change notification settings - Fork 0
Added messages feature via JSON as per step 3 of week 3 #7
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
base: master
Are you sure you want to change the base?
Conversation
portfolio/pom.xml
Outdated
| <dependency> | ||
| <groupId>com.google.code.gson</groupId> | ||
| <artifactId>gson</artifactId> | ||
| <version>2.8.6</version> | ||
| </dependency> |
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.
nit - let's keep dependencies alphabetical by groupId and then artifactId
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 will do.
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpServletResponse; | ||
|
|
||
| import java.util.ArrayList; |
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 run this file through the gist? Should fix these imports for us.
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 sure.
| import java.util.ArrayList; | ||
| import com.google.gson.Gson; | ||
|
|
||
| /** Servlet that returns some example content. TODO: modify this file to handle comments 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.
nit - remove this TODO comment, now that the class is handling comment 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.
Will do.
portfolio/src/main/java/com/google/sps/servlets/DataServlet.java
Outdated
Show resolved
Hide resolved
| /** Servlet that returns some example content. */ | ||
| @WebServlet("/data") | ||
| public class DataServlet extends HttpServlet { | ||
| List<String> messages = new ArrayList<>(); |
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.
Move this variable definition into the doGet method. If you define it at the class level, then every time someone refreshes your page, your code will add another 3 comments to the array. Eventually your server will OOM after so many visits.
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.
Did this change get made?
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.
It seems doGet always returns the same messages, this could be made a constant ImmutableList instead.
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.
Oh oops I don't think it got changed, I'll quickly move the variable definition.
| /** Servlet that returns some example content. */ | ||
| @WebServlet("/data") | ||
| public class DataServlet extends HttpServlet { | ||
| List<String> messages = new ArrayList<>(); |
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.
Did this change get made?
ccondit
left a comment
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.
Cool! LGTM.
This pull request uses local memory to store comments, and allows them to be fetched with a GET request. The GET request returns the comment pairs in JSON format, and the webpage displays the comments upon page load.