Package com.jms.socialmedia.handlers
Class PostRequestHandler
- java.lang.Object
-
- com.jms.socialmedia.handlers.RequestHandler
-
- com.jms.socialmedia.handlers.PostRequestHandler
-
public class PostRequestHandler extends RequestHandler
-
-
Field Summary
-
Fields inherited from class com.jms.socialmedia.handlers.RequestHandler
dataService, tokenService
-
-
Constructor Summary
Constructors Constructor Description PostRequestHandler(DataService dataService, TokenService tokenService, com.google.gson.Gson gson)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Boolean
handleAddPost(spark.Request request, spark.Response response)
POST /api/post/addBoolean
handleDeletePost(spark.Request request, spark.Response response)
DELETE /api/post/:idBoolean
handleEditPost(spark.Request request, spark.Response response)
PUT /api/post/:idCollection<Post>
handleGetCommentedPosts(spark.Request request, spark.Response response)
GET /api/user/:userId/commentedpostsCollection<Post>
handleGetFeedPosts(spark.Request request, spark.Response response)
GET /api/user/:userId/feedPost
handleGetPost(spark.Request request, spark.Response response)
GET /api/post/:idCollection<Post>
handleGetPosts(spark.Request request, spark.Response response)
GET /api/postsCollection<Post>
handleGetPostsByUserId(spark.Request request, spark.Response response)
GET /api/user/:userId/posts-
Methods inherited from class com.jms.socialmedia.handlers.RequestHandler
authorizeRequest, authorizeRequest, checkParameter, checkParameter, checkParameter, extractBodyContent, handleAuthorizeRequest, throwBadRequestExceptionIf, throwExceptionIfNecessary
-
-
-
-
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 Requestresponse
- Spark Response- Returns:
- Collection of
Post
s 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 Requestresponse
- Spark Response- Returns:
- Collection of
Post
s
-
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 Requestresponse
- Spark Response- Returns:
- Collection of
Post
s 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 Requestresponse
- Spark Response- Returns:
- a single
Post
- Throws:
NotFoundException
- if a Post with the given ID does not existNumberFormatException
- 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 Requestresponse
- Spark Response- Returns:
true
if Add is successful- Throws:
IOException
- if there is a JSON Parsing Issue or a JWT Validation FailureBadRequestException
- 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 Requestresponse
- Spark Response- Returns:
true
if Update is successful- Throws:
IOException
- if there is a JSON Parsing Issue or a JWT Validation FailureNotFoundException
- 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 Requestresponse
- Spark Response- Returns:
true
if Delete is successful- Throws:
IOException
- if there is a JSON Parsing Issue or a JWT Validation FailureNotFoundException
- 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 Requestresponse
- Spark Response- Returns:
- Collection of
Post
s that the User commented on - Throws:
NumberFormatException
- if the given userId is not a number
-
-