Skip to content

leonardo-otero390/Linkr_backend

Repository files navigation

Linkr Backend

The Linkr is the best new social media to save and share links.

This project is the backend with PostgreSQL for Linkr. You can check the frontend repository for more information.

You can use the endpoint deployed to heroku Below are the implemented features:

  • Sign-up, log-in, and logout
  • Get posts
  • Get trending
  • Follow/unfollow
  • Like posts
  • Search users

Endpoints

All following needs token authorization

Authorization - send a Bearer token on headers like this:
{
  "headers": {
    "authorization": "Bearer 1cf7cccf-48ad-4edd-8b9d-121b1199aaf4"
  }
}
  • it returns 400 for empty auth, without Bearer or token not uuid

  • it returns 401 for unauthorized

POST /posts send body request like this:
{
  "link": "https://www.google.com/",
  "text": "awesome #search engine"
}
  • text is optional

  • it returns status 201 for success

and object like this

{
  "post": {
    "id": 49,
    "link": "https://www.google.com/",
    "text": "awesome #search engine",
    "time": "2022-03-29T23:48:56.636Z",
    "linkTitle": "Google",
    "linkDescription": "Link doesn't have a description",
    "linkImage": "/images/branding/googleg/1x/googleg_standard_color_128dp.png"
  },
  "user": {
    "id": 2,
    "email": "goku@kame.com",
    "name": "goku",
    "pictureUrl": "https://dragonball.com/goku.jpeg"
  },
  "like": []
}
GET /hashtags/trending
  • it returns status 200 for success

and array like this

[
  {
    "count": "10",
    "name": "#topTrending",
    "id": 13
  },
  {
    "count": "5",
    "name": "miranha",
    "id": 12
  }
]
  • count is the number of mentions
GET /hashtags/HASHTAG/posts
  • change HASHTAG to the hashtag you're looking for

  • it returns status 200 for success

and array like this

[
  {
    "id": 27,
    "text": "testing is cool #teste",
    "link": "https://www.google.com/",
    "linkTitle": "Google",
    "linkDescription": "Link doesn't have a description",
    "linkImage": "/images/branding/googleg/1x/googleg_standard_color_128dp.png",
    "authorId": 2,
    "name": "goku",
    "pictureUrl": "https://dragonball.com/goku.jpeg",
    "likes": [],
    "hashtags": []
  },
]
  • count is the number of mentions
GET /posts
  • it returns status 404 if there are no follows or posts of follows

  • it returns status 200 for success

and array like this

[
  {
    "id": 3,
    "link": "https://www.google.com/",
    "text": "",
    "authorId": 1,
    "linkTitle": "Google",
    "linkDescription": "Link doesn't have a description",
    "linkImage": "/images/branding/googleg/1x/googleg_standard_color_128dp.png",
    "name": "cat",
    "pictureUrl": "https://http.cat/411.jpg",
    "likes": [
      {
        "postId": 1,
        "userId": 2,
        "userName": "simpson"
      }
    ]
  },
]
PUT /users/USERID/follow
  • it returns status 200 for success

  • change USERID to the user id you're following or unfollowing

  • it return status 400 if USERID is not a number or if is the same user requesting

  • it return status 404 if there isn't a user with USERID

GET /users/follows
  • it returns status 200 for success

and array like this

[
  {
    "id": 5,
    "followedId": 1,
    "followerId": 2
  }
  {
    "id": 6,
    "followedId": 5,
    "followerId": 2
  }
]

Technologies

Requirements

install npm
wget -qO- <https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh> | bash

## Or this command
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

# Close and open terminal
nvm install --lts
nvm use --lts
# Verify node version
node --version # Must show v14.16.1
# Verify npm version
npm -v
install postgres
sudo apt install postgresql postgresql-contrib

How to run

  1. Clone this repository
  2. Install dependencies
npm i
  1. Create database with given script
  • open ./database and run sql scripts
  1. set your .env file

  2. Run the project with

npm run start (deploy)
  1. Run the project in development mode (nodemon)
npm run start:dev

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors 4

  •  
  •  
  •  
  •