// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.sps.servlets;

import com.google.sps.data.GoogleShoppingResultsWrapper;
import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/photo-shopping-request")
public class PhotoShoppingServlet extends HttpServlet {
  
  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    // TODO: Based on request.getParameter("photo-category"), call methods from photo detection classes, 
    // passing request.getParameter("blob-key") as argument. These methods build the shopping query and call 
    // the {@code getShoppingResultsPage} method from GoogleShoppingResultsWrapper.

    response.setContentType("text/html");

    switch (request.getParameter("photo-category")) {
      case "product":
        response.getWriter().println(GoogleShoppingResultsWrapper.getShoppingResultsPage("Fountain pen"));
        break;
      case "list":
        response.getWriter().println(GoogleShoppingResultsWrapper.getShoppingResultsPage("Fuzzy socks"));
        break;
      case "barcode":
        response.getWriter().println(GoogleShoppingResultsWrapper.getShoppingResultsPage("Running shoes"));
        break;
      default:
        response.getWriter().println(GoogleShoppingResultsWrapper.getShoppingResultsPage("Notebook"));
    }
  }
}

@@ -1396,58 +1396,31 @@
     
-response.setContentType(%22text/html%22);%0A%0A    switch 
+String query = getQuery
 (req
@@ -1459,37 +1459,52 @@
 y%22))
- %7B
+;
 %0A    
-  case %22product%22:%0A    
+response.setContentType(%22text/html%22);%0A
     
@@ -1588,430 +1588,287 @@
 age(
-%22Founta
+query));%0A  %7D%0A%0A  private String getQuery(Str
 in
+g
  p
-en%22));%0A        break;%0A      case %22list%22:%0A        response.getWriter().println(GoogleShoppingResultsWrapper.getShoppingResultsPage(%22Fuzzy socks%22));%0A        break;%0A      case %22barcode%22:%0A        response.getWriter().println(GoogleShoppingResultsWrapper.getShoppingResultsPage(%22Running shoes%22));%0A        break;%0A      default:%0A        response.getWriter().println(GoogleShoppingResultsWrapper.getShoppingResultsPage(
+hotoCategory) %7B%0A    switch (photoCategory) %7B%0A      case %22product%22:%0A        return %22Fountain pen%22;%0A      case %22list%22:%0A        return %22Fuzzy socks%22;%0A      case %22barcode%22:%0A        return %22Running shoes%22;%0A      default:%0A        return 
 %22Not
@@ -1877,17 +1877,17 @@
 ook%22
-))
 ;
+ 
 %0A    %7D
+ 
 %0A  %7D

Add getQuery method to Photo Shopping Servlet