Skip to content

CarlosBM18/contacts-ror-backend

Repository files navigation

Contacts Backend with Ruby on Rails

This is the backend for a contacts app where each user can have its own list of contacts. The app handles user authentication and stores the data to be persistent in a database.

Overview 📋

Live demo 🚀

https://contacts-ror-app.herokuapp.com/api/v1

Install and set up 🔧

First, clone the project and install the project dependencies, to do so run:

bundle install

Create a .env file and add a POSTGRESQL_DATABASE_USERNAME and POSTGRESQL_DATABASE_PASSWORD variable with the username and password of the PostreSQL database. Should be something like:

POSTGRESQL_DATABASE_USERNAME=YOUR_PASSWORD
POSTGRESQL_DATABASE_PASSWORD=YOUR_USERNAME

Finally, start the server with:

rails s

Tests ⚙️

To run the tests:

bundle exec rspec

Routes 🚏

POST /users

  • Body
{
  "email": "[email protected]",
  "password": "test123"
}
  • Success Response
{
  "id": 1,
  "email": "[email protected]",
  "created_at": "2021-10-03T16:20:53.280Z",
  "updated_at": "2021-10-03T16:20:53.280Z"
}
  • Error Response
    • 400 BAD REQUEST

POST /login?email={email_string}&password={password_string}

  • Parameters email and password

  • Success Response

{
  "user": {
    "id": 1,
    "email": "[email protected]",
    "created_at": "2021-10-03T15:57:38.242Z",
    "updated_at": "2021-10-03T15:57:38.242Z"
  },
  "token": "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyMH0.UX8SaCzkRQsZfJutKKujynJ5YCev8taMrIxGKjg0wQ0"
}
  • Error Response
    • 400 BAD REQUEST

GET /contacts

  • Success Response
[
  {
    "id": 1,
    "first_name": "Carlos",
    "last_name": "Bertomeu",
    "email": "[email protected]",
    "phone_number": 666777888,
    "user_id": 1,
    "created_at": "2021-10-03T19:39:40.372Z",
    "updated_at": "2021-10-03T19:39:40.372Z"
  }
]
  • Error Response
    • 401 UNAUTHORIZED

POST /contacts

  • Body
{
  "first_name": "Carlos",
  "last_name": "Bertomeu",
  "email": "[email protected]",
  "phone_number": 666777888
}
  • Success Response
{
  "id": 1,
  "first_name": "Carlos",
  "last_name": "Bertomeu",
  "email": "[email protected]",
  "phone_number": 666777888,
  "user_id": 1,
  "created_at": "2021-10-03T19:52:04.632Z",
  "updated_at": "2021-10-03T19:52:04.632Z"
}
  • Error Response
    • 400 BAD REQUEST
    • 401 UNAUTHORIZED
    • 403 FORBIDDEN

GET /contacts/{id}

  • Success Response
{
    "id": {id},
    "first_name": "Carlos",
    "last_name": "Bertomeu",
    "email": "[email protected]",
    "phone_number": 666777888,
    "user_id": 1,
    "created_at": "2021-10-03T19:39:40.372Z",
    "updated_at": "2021-10-03T19:47:18.672Z"
}
  • Error Response
    • 404 NOT FOUND
    • 401 UNAUTHORIZED
    • 403 FORBIDDEN

PATCH/PUT /contacts/{id}

  • Body
{
  "first_name": "Carlos",
  "last_name": "Bertomeu",
  "email": "[email protected]",
  "phone_number": 666777111
}
  • Success Response
{
  "id": {id},
  "first_name": "Carlos",
  "last_name": "Bertomeu",
  "email": "[email protected]",
  "phone_number": 666777111,
  "user_id": 1,
  "created_at": "2021-10-03T19:39:40.372Z",
  "updated_at": "2021-10-03T19:47:18.672Z"
}
  • Error Response
    • 400 BAD REQUEST
    • 401 UNAUTHORIZED
    • 403 FORBIDDEN

DELETE /contacts/{id}

  • Success Response

    • 200 OK
  • Error Response

    • 404 NOT FOUND
    • 401 UNAUTHORIZED
    • 403 FORBIDDEN

GET /contact_histories/{id}

  • Success Response
[
  {
    "id": 1,
    "first_name": "Carlos",
    "last_name": "Bertomeu",
    "email": "[email protected]",
    "phone_number": 666777222,
    "contact_id": {id},
    "created_at": "2021-10-03T19:39:40.408Z",
    "updated_at": "2021-10-03T19:39:40.408Z",
    "state": "created",
    "user_id": 1
  }
]
  • Error Response
    • 404 NOT FOUND
    • 401 UNAUTHORIZED
    • 403 FORBIDDEN

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published