// 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 java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/scheduling")
public class SchedulingServlet extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("plain/text");
        response.getWriter().println("To be implemented");
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("plain/text");
        response.getWriter().println("To be implemented");
    }
}

@@ -627,27 +627,284 @@
 ort 
-java.io.IOException
+com.google.sps.data.Tutor;%0Aimport com.google.sps.data.TimeRange;%0Aimport com.google.sps.data.TutorSession;%0Aimport com.google.sps.data.SampleData;%0Aimport com.google.gson.Gson;%0Aimport java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List
 ;%0Aim
@@ -1076,16 +1076,94 @@
 esponse;
+%0Aimport javax.servlet.*; // Can be deleted after hardcoded database is removed
 %0A%0A@WebSe
@@ -1235,16 +1235,164 @@
 ervlet %7B
+%0A    SampleData hardcoded;%0A%0A    public void init(ServletConfig servletconfig) throws ServletException %7B %0A        hardcoded = new SampleData();%0A    %7D
 %0A%0A    @O
@@ -1721,32 +1721,897 @@
 s IOException %7B%0A
+        String tutorID = request.getParameter(%22tutorID%22);%0A        String start = request.getParameter(%22start%22);%0A        String end = request.getParameter(%22end%22);%0A        String studentEmail = request.getParameter(%22studentEmail%22);%0A        String subtopics = request.getParameter(%22subtopics%22);%0A        String questions = request.getParameter(%22questions%22);%0A%0A        TimeRange timeslot = TimeRange.fromStartToEnd(Integer.parseInt(start), Integer.parseInt(end));%0A%0A        TutorSession tutoringSession = new TutorSession(studentEmail, tutorID, subtopics, questions, timeslot);%0A%0A        // Update scheduledSessions%0A        hardcoded.addToScheduledSessionsByEmail(tutorID, tutoringSession);%0A%0A        // Remove available timeslot%0A        hardcoded.deleteAvailabilityByTimeRange(tutorID, timeslot);%0A%0A        String json = convertToJsonUsingGson(hardcoded.getSampleTutors());%0A
         response
@@ -2623,34 +2623,41 @@
 ontentType(%22
-plain/text
+application/json;
 %22);%0A        
@@ -2685,36 +2685,277 @@
 println(
-%22To be implemented%22)
+json);%0A        return;%0A    %7D%0A%0A    // Converts the hardcoded into a JSON string using the Gson library.%0A    private String convertToJsonUsingGson(List%3CTutor%3E tutors) %7B%0A        Gson gson = new Gson();%0A        String json = gson.toJson(tutors);%0A        return json
 ;%0A    %7D%0A

Write dopost function for the scheduling servlet.