Class PostRequestHandler

    • Constructor Detail

      • PostRequestHandler

        public PostRequestHandler​(DataService dataService,
                                  TokenService tokenService,
                                  com.google.gson.Gson gson)
    • Method Detail

      • handleGetPosts

        public Collection<Post> handleGetPosts​(spark.Request request,
                                               spark.Response response)

        GET /api/posts

        Query Parameters
        • userId - ID of User who made the Posts
        • username - login name of the User who made the Posts
        • tag - #tag in the Posts
        • on - Date the Posts were created
        • before - latest date of the Posts returned
        • after - earliest date of the Posts returned
        • sortBy - Field to Sort by
        • order - asc or desc
        • sincePostId - return posts after this Post ID
        Parameters:
        request - Spark Request
        response - Spark Response
        Returns:
        Collection of Posts according to the query parameters
      • handleGetFeedPosts

        public Collection<Post> handleGetFeedPosts​(spark.Request request,
                                                   spark.Response response)

        GET /api/user/:userId/feed

        • userId - ID of User
        Parameters:
        request - Spark Request
        response - Spark Response
        Returns:
        Collection of Posts
      • handleGetPostsByUserId

        public Collection<Post> handleGetPostsByUserId​(spark.Request request,
                                                       spark.Response response)

        GET /api/user/:userId/posts

        :userId - ID of User who made the Posts
        Parameters:
        request - Spark Request
        response - Spark Response
        Returns:
        Collection of Posts made by the User
        Throws:
        NumberFormatException - if given userId is not a number
      • handleGetPost

        public Post handleGetPost​(spark.Request request,
                                  spark.Response response)

        GET /api/post/:id

        :id - ID of Post
        Parameters:
        request - Spark Request
        response - Spark Response
        Returns:
        a single Post
        Throws:
        NotFoundException - if a Post with the given ID does not exist
        NumberFormatException - if given post id is not a number
      • handleAddPost

        public Boolean handleAddPost​(spark.Request request,
                                     spark.Response response)
                              throws IOException

        POST /api/post/add

         {
           "userId" [ID of User making the Post],
           "text" [Post Text]
         }
         
        Parameters:
        request - Spark Request
        response - Spark Response
        Returns:
        true if Add is successful
        Throws:
        IOException - if there is a JSON Parsing Issue or a JWT Validation Failure
        BadRequestException - if the request does not have a userId or text
      • handleEditPost

        public Boolean handleEditPost​(spark.Request request,
                                      spark.Response response)
                               throws IOException

        PUT /api/post/:id

        :id - ID of Post being edited
        Parameters:
        request - Spark Request
        response - Spark Response
        Returns:
        true if Update is successful
        Throws:
        IOException - if there is a JSON Parsing Issue or a JWT Validation Failure
        NotFoundException - if a Post with the given ID does not exist
      • handleDeletePost

        public Boolean handleDeletePost​(spark.Request request,
                                        spark.Response response)
                                 throws IOException

        DELETE /api/post/:id

        :id - ID of Post being deleted
        Parameters:
        request - Spark Request
        response - Spark Response
        Returns:
        true if Delete is successful
        Throws:
        IOException - if there is a JSON Parsing Issue or a JWT Validation Failure
        NotFoundException - if a Post with the given ID does not exist
      • handleGetCommentedPosts

        public Collection<Post> handleGetCommentedPosts​(spark.Request request,
                                                        spark.Response response)

        GET /api/user/:userId/commentedposts

        :userId - ID of the User who commented on these Posts
        Parameters:
        request - Spark Request
        response - Spark Response
        Returns:
        Collection of Posts that the User commented on
        Throws:
        NumberFormatException - if the given userId is not a number