package com.google.sps.servlets;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.sps.data.Event;
import com.google.sps.utilities.CommonUtils;
import com.google.sps.utilities.EventRanker;
import com.google.sps.utilities.SpannerTasks;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/event-ranker")
public class EventRankerServlet extends HttpServlet {
  /** Returns events in order of relevance */
  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    User user = UserServiceFactory.getUserService().getCurrentUser();
    // TODO: Replace getAllEvents() with the appropriate method to get all results to display
    Set<Event> relevantEvents = SpannerTasks.getAllEvents();
    List<Event> rankedRelevantEvents = EventRanker.rankEvents(relevantEvents);
    response.setContentType("application/json;");
    response.getWriter().println(CommonUtils.convertToJson(rankedRelevantEvents));
  }
}

@@ -31,52 +31,8 @@
 s;%0A%0A
-import com.google.appengine.api.users.User;%0A
 impo
@@ -85,16 +85,16 @@
 actory;%0A
+
 import c
@@ -119,16 +119,49 @@
 .Event;%0A
+import com.google.sps.data.User;%0A
 import c
@@ -335,24 +335,51 @@
 .util.List;%0A
+import java.util.Optional;%0A
 import java.
@@ -813,17 +813,20 @@
     
-User user
+String email
  = U
@@ -876,18 +876,195 @@
 ntUser()
-;%0A
+.getEmail();%0A    Optional%3CUser%3E userOptional = SpannerTasks.shallowReadUserFromEmail(email);%0A    User user;%0A    if (userOptional.isPresent()) %7B%0A      user = userOptional.get();%0A  
     // T
@@ -1153,16 +1153,18 @@
 lay%0A    
+  
 Set%3CEven
@@ -1208,24 +1208,26 @@
 llEvents();%0A
+  
     List%3CEve
@@ -1276,16 +1276,22 @@
 kEvents(
+user, 
 relevant
@@ -1299,24 +1299,26 @@
 vents);%0A    
+  
 response.set
@@ -1351,16 +1351,18 @@
 son;%22);%0A
+  
     resp
@@ -1436,14 +1436,114 @@
 ents));%0A
+    %7D else %7B%0A      response.sendError(HttpServletResponse.SC_BAD_REQUEST, %22User not found.%22);%0A    %7D%0A
   %7D%0A%7D%0A

Add event ranking servlet