package com.google.sps.servlets;
import java.io.IOException;
import java.io.BufferedReader;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.gson.Gson;
import com.google.sps.data.Form;
import com.google.sps.data.RequestJsonParser;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/form-handler")
public class FormHandlerServlet extends HttpServlet {

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        
        Form form = RequestJsonParser.parseObjectFromRequest(request, Form.class);

        Entity formEntity = form.toDatastoreEntity();
        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        datastore.put(formEntity);

        response.setContentType("text/html");
        response.setStatus(HttpServletResponse.SC_OK);
    }
}

@@ -254,22 +254,242 @@
 tastore.
-Entity
+PreparedQuery;%0Aimport com.google.appengine.api.datastore.Query;%0Aimport com.google.appengine.api.datastore.Query.SortDirection;%0Aimport com.google.appengine.api.datastore.Entity;%0Aimport java.util.List;%0Aimport java.util.ArrayList
 ;%0Aimport
@@ -796,16 +796,16 @@
 ndler%22)%0A
-
 public c
@@ -851,16 +851,703 @@
 vlet %7B%0A%0A
+    @Override%0A    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException %7B%0A        List%3CForm%3E forms = new ArrayList%3C%3E();%0A        Form form = null;%0A        Query query = new Query (%22Form%22);%0A        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();%0A        PreparedQuery results = datastore.prepare(query);%0A    %0A        for(Entity entity : results.asIterable())%7B%0A            form = new Form(entity);%0A            forms.add(form);%0A        %7D%0A    %0A        Gson gson = new Gson();%0A        String json = gson.toJson(forms);%0A        response.setContentType(%22application/json%22);%0A        response.getWriter().println(json);%0A    %7D%0A%0A%0A
     @Ove

Add doGet method