@@ -0,0 +1,2766 @@
+// Copyright 2019 Google LLC%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     https://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A%0Apackage com.google.growpod.servlets;%0A%0Aimport com.google.cloud.datastore.DatastoreOptions;%0Aimport com.google.growpod.controllers.GardenController;%0Aimport com.google.growpod.data.Garden;%0Aimport com.google.gson.Gson;%0Aimport java.io.IOException;%0Aimport java.util.List;%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.annotation.WebServlet;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0A/**%0A * Servlet that returns gardens close to either a given ZIP code or %0A * the logged-in user's ZIP code, upon a GET request.%0A */%0A@WebServlet(%7B%22/find-gardens%22%7D)%0Apublic class FindGardensServlet extends HttpServlet %7B%0A%0A  static final long serialVersionUID = 1L;%0A%0A  private DatastoreOptions datastoreInstance;%0A  private GardenController controller;%0A%0A  /** Initializes the servlet. Connects it to Datastore. */%0A  @Override%0A  public void init() throws ServletException %7B%0A    this.datastoreInstance = DatastoreOptions.getDefaultInstance();%0A    this.controller = new GardenController(datastoreInstance);%0A  %7D%0A%0A  /**%0A   * Processes HTTP GET requests for the /find-gardens servlet. The optional argument%0A   * %60zip-code%60 can specify where to look for gardens, otherwise, the user's zip code%0A   * suffices.%0A   *%0A   * @param request Information about the GET Request%0A   * @param response Information about the servlet's response%0A   */%0A  @Override%0A  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException %7B%0A    %0A    String zipCode = request.getParameter(%22zip-code%22);%0A    if (zipCode == null) %7B%0A      zipCode = %2211201%22; // MOCK VALUE%0A    %7D%0A%0A    response.setContentType(%22application/json;%22);%0A    response.getWriter().println(%22%7B%7D%22);%0A  %7D%0A%0A  /** Getters and Setters for connected objects. */%0A  public DatastoreOptions getDatastoreInstance() %7B%0A    return datastoreInstance;%0A  %7D%0A%0A  public void setDatastoreInstance(DatastoreOptions datastoreInstance) %7B%0A    this.datastoreInstance = datastoreInstance;%0A  %7D%0A%0A  public GardenController getController() %7B%0A    return controller;%0A  %7D%0A%0A  public void setController(GardenController controller) %7B%0A    this.controller = controller;%0A  %7D%0A%7D%0A

Initialize servlet