Skip to content

v0.2.47..v0.2.48 changeset UserResource.java

Garret Voltz edited this page Sep 27, 2019 · 1 revision
diff --git a/hoot-services/src/main/java/hoot/services/controllers/osm/user/UserResource.java b/hoot-services/src/main/java/hoot/services/controllers/osm/user/UserResource.java
index 0231aee..4076d83 100644
--- a/hoot-services/src/main/java/hoot/services/controllers/osm/user/UserResource.java
+++ b/hoot-services/src/main/java/hoot/services/controllers/osm/user/UserResource.java
@@ -29,7 +29,6 @@ package hoot.services.controllers.osm.user;
 import static hoot.services.models.db.QUsers.users;
 import static hoot.services.utils.DbUtils.createQuery;
 
-import java.sql.Timestamp;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
@@ -63,7 +62,7 @@ import hoot.services.utils.XmlDocumentBuilder;
  * Service endpoint for OSM user information
  */
 @Controller
-@Path("/user")
+@Path("/api/0.6/user")
 @Transactional
 public class UserResource {
     public UserResource() {
@@ -76,15 +75,26 @@ public class UserResource {
          return Response.ok().entity(user).build();
     }
 
+    private Response userResponse(HttpServletRequest request, Users user) throws ParserConfigurationException {
+
+        if (user == null) {
+            return Response.status(Status.NOT_FOUND).build();
+        }
+
+        String contentType = null;
+        if(request != null) { contentType = request.getHeader("Content-Type"); }
+        if(contentType == null || contentType.trim().equalsIgnoreCase("application/xml")) {
+            Document responseDoc = writeResponse(new User(user));
+            return Response.ok().entity(new DOMSource(responseDoc)).type(MediaType.APPLICATION_XML).build();
+        } else {
+            return Response.ok().entity(user).type(MediaType.APPLICATION_JSON).build();
+        }
+    }
+
     /**
-     * Service method endpoint for retrieving OSM user information
-     * <p>
-     * This is currently implemented as a dummy method to appease iD. It always
-     * retrieves information for the first user record in the services database.
-     * It cannot properly be implemented until user authentication is first
-     * implemented.
-     * <p>
-     * GET hoot-services/osm/api/0.6/user/details
+     * Service method endpoint for retrieving Hoot user information by id
+     *
+     * GET hoot-services/osm/api/0.6/user/{userId}
      *
      * @param userId ID of the user to retrieve information for
      * @return Response with the requested user's information
@@ -98,17 +108,22 @@ public class UserResource {
                 .where(users.id.eq(userId))
                 .fetchOne();
 
-        if (user == null) {
-            return Response.status(Status.NOT_FOUND).build();
-        }
-        String contentType = null;
-        if(request != null) { contentType = request.getHeader("Content-Type"); }
-        if(contentType == null || contentType.trim().equalsIgnoreCase("application/xml")) {
-            Document responseDoc = writeResponse(new User(user));
-            return Response.ok().entity(new DOMSource(responseDoc)).type(MediaType.APPLICATION_XML).build();
-        } else {
-            return Response.ok().entity(user).type(MediaType.APPLICATION_JSON).build();
-        }
+        return userResponse(request, user);
+    }
+
+    /**
+     * Service method endpoint for retrieving Hoot user
+     *
+     * GET hoot-services/osm/api/0.6/user/details
+     *
+     * @return Response with the user's information
+     */
+    @GET
+    @Path("/details")
+    public Response getDetails(@Context HttpServletRequest request) throws ParserConfigurationException {
+        Users user = Users.fromRequest(request);
+
+        return userResponse(request, user);
     }
 
     @GET
@@ -120,17 +135,7 @@ public class UserResource {
                 .where(users.displayName.equalsIgnoreCase(displayName))
                 .fetchOne();
 
-        if (user == null) {
-            return Response.status(Status.NOT_FOUND).build();
-        }
-        String contentType = null;
-        if(request != null) { contentType = request.getHeader("Content-Type"); }
-        if(contentType == null || contentType.trim().equalsIgnoreCase("application/xml")) {
-            Document responseDoc = writeResponse(new User(user));
-            return Response.ok().entity(new DOMSource(responseDoc)).type(MediaType.APPLICATION_XML).build();
-        } else {
-            return Response.ok().entity(user).type(MediaType.APPLICATION_JSON).build();
-        }
+        return userResponse(request, user);
     }
 
     /**
Clone this wiki locally