// 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.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.PreparedQuery;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.Query.SortDirection;
import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/** Servlet responsible for deleting tasks. */
@WebServlet("/delete-data")
public class DeleteServlet extends HttpServlet {

  @Override
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    long messageId = Long.parseLong(request.getParameter(BlogConstants.ID_PARAMETER));

    Key postEntityKey = KeyFactory.createKey(BlogConstants.BLOG_ENTITY_KIND, messageId);
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    datastore.delete(postEntityKey);

    response.setContentType("text/html");
    response.getWriter().println("Success! Post Deleted.");
  }
}
@@ -1087,24 +1087,44 @@
 OException;%0A
+import java.util.*;%0A
 import javax
@@ -1289,16 +1289,17 @@
 onse;%0A%0A%0A
+%0A
 /** Serv
@@ -1331,13 +1331,31 @@
 ing 
-tasks
+entities from datastore
 . */
@@ -1554,25 +1554,24 @@
    long 
-messageId
+entityID
  = Long.
@@ -1615,16 +1615,23 @@
 nstants.
+ENTITY_
 ID_PARAM
@@ -1642,53 +1642,52 @@
 ));%0A
-%0A
     
-Key postEntityKey = KeyFactory.createKey
+String entityKind = request.getParameter
 (Blo
@@ -1701,13 +1701,8 @@
 nts.
-BLOG_
 ENTI
@@ -1712,19 +1712,83 @@
 KIND
-, messageId
+_PARAMETER);%0A%0A    Key EntityKey = KeyFactory.createKey(entityKind, entityID
 );%0A 
@@ -1891,12 +1891,8 @@
 ete(
-post
 Enti
@@ -1950,65 +1950,285 @@
     
-response.getWriter().println(%22Success! Post Deleted.%22);%0A  %7D%0A%7D
+if (entityKind.equals(BlogConstants.BLOG_ENTITY_KIND)) %7B%0A      response.getWriter().println(%22Success! Post Deleted.%22);%0A    %7D%0A    if (entityKind.equals(BlogConstants.TAG_QUERY)) %7B%0A      response.getWriter().println(%22Success! You unfollow this tag.%22);%0A    %7D%0A  %7D%0A%0A%7D%0A/* End Of File */%0A

Update DeleteServlet to