Skip to content

Backend Routes

Ruiyu Wu edited this page Aug 28, 2019 · 17 revisions

HTML

  • GET / StaticPagesController#root

API Endpoints

users

  • POST api/users UsersController#create - a user signs up and creates an account in the database. returns the user's information.
  • GET /api/user/:user_id UsersController#show - returns the user's profile information, such as first and last names, birth date, profile picture url, photos. mostly for the profile page.
  • GET /api/users UsersController#index - returns a list of all the users, ideally for a search, also for some pages
  • PATCH /api/users/:user_id UsersController#update - allows a user to update the information in the database, and returns the updated information.
  • POST /api/users/:string UsersController#search - sends a wildcard string to a SQL query searching for users with the string in their first or last names and returns those users
  • POST /api/users/:user_id/:string UsersController#friends - performs the same querying as above, except only among friends of the user whose id matches the wildcard

session

  • POST api/session SessionsController#create- user log in
  • DELETE api/session SessionsController#destroy- user logs out

posts

  • GET /api/users/:user_id/posts PostsController#index - returns all the posts that are made to a user's timeline, the comments on the post, the comments on the comments, and all the likes on the post or any of the comments
  • GET /api/posts PostsController#index - returns all the posts made to the current user's timeline, or made to any of the user's friends' timelines. This is the news feed.
  • POST /api/posts/:id PostsController#feed - searches for posts that fulfill the following parameters: (1) the user(of :id) is the author, (2) the user is the recipient, (3) the post's author AND recipient are both the user's friends.
  • GET /api/users/:user_id/posts/:post_id PostsController#show - returns a single post along with the comments and the likes for when a post is too long, and is shown on one page (will popup on page).
  • POST /api/users/:user_id/posts PostsController#create - creates a post and returns the post information
  • PATCH /api/posts/:post_id PostsController#update - updates a post and returns the updated post information
  • DELETE /api/posts/:post_id PostsController#destroy - deletes a post from the database, along with all the comments and the likes on the post
  • GET /api/posts/last PostController#last - returns the most recently created post instance

comments

  • POST /api/posts/:post_id/comments CommentsController#create - creates a comments and returns the comment information
  • PATCH /api/comments/:comment_id CommentsController#update - updates a comment and returns the updated comment information
  • DELETE /api/comments/:comment_id CommentsController#destroy - deletes a comment from the database, along with any sub-comments or likes on the comment

NOTE: comments does not have a GET route for an index because we will have the comments be rendered in api/posts/show.json.jbuilder view.

friendships

  • POST /api/friendships FriendshipsController#create - Creates a friend request between two users
  • PATCH /api/friendships/:friendship_id FriendshipsController#update - Updates a friend request from "pending" status to "accepted."
  • DELETE /api/friendships/:friendship_id FriendshipsController#destroy - Deletes a friendship instance, whether it be rejecting or cancelling a friend request, or unfriending a user

likes

  • POST /api/likes LikesController#create - creating a like
  • DELETE /api/likes/:like_id LikesController#destroy - destroying a like

tags

  • POST /api/tags TagsController#create - tagging a user to a post
  • DELETE /api/tags/:tag_id TagsController#destroy - untagging a user from a post

BONUS:

workplaces

  • POST /api/workplaces WorkplacesController#create create a workplace and return the workplace information

NOTE: will be expanded if this can become a group

educations

  • POST /api/educations EducationsController#create create a education and return the education information

NOTE: will be expanded if this can become a group

locations

  • POST /api/locations LocationsController#create create a location and return the location information

NOTE: will be expanded if this can become a group

Clone this wiki locally