GithubHelp home page GithubHelp logo

contact-list-backend-ormartins02's Introduction

API Documentation

Content Table



1. Overview

Contact list is an API that consists of creating users and their respective contacts..

These were the main technologies used in this project:

Team


2. Entity Relationship Diagram

Back to the top

Diagram


3. Endpoints

Back to the top

Index


4. Authentication

Back to the top

Some routes need authentication. The authentication used is the Bearer Token type.

The token is generated automatically at user login.

Thus, to access routes with authentication, it is necessary to have a user and be logged in with the user.

Also, some routes require the user to be an admin, user, or owner of the contact.

Please read each route's documentation to understand which authentications are required.



1. USERS

Back to Endpoints


The User object is defined as:

Field Type Description
id string User's unique identifier
name string User name *
email string User email *
phone string Contact Phone *
password string User password *
isAdm boolean Defines whether a user is an administrator or not
createdAt string Date when the user was created



Endpoints


Method Routes Description
POST /users Create user
GET /users List all users
GET /users/:id Lists a user using its ID as a parameter
PATCH /user/:id Update user
DELETE /delete/:id Delete user


1.1 User Creation

Back to Endpoints


POST /users


Request:


Request body:

{
  "name": "Ricardo",
  "email": "[email protected]",
  "phone": "0xx 9xxxx-xxxx",
  "password": "1234",
  "isAdm": true
}

Expected Response:


Status 201 - CREATED

{

  {
    "id": "7fd311fe-f80a-465e-9ed9-8bb4e28bbf45",
    "name": "Ricardo",
    "email": "[email protected]",
    "phone" : "0xx 9xxxx-xxxx",
    "isAdm": true,
    "createdAt": "2022-10-29T00:41:28.717Z",
  }
}

Error Responses:


Status 409 - CONFLICTS - Email already exists

{
  "message": "This email already exists"
}


1.2 List Users

Back to Endpoints


GET /users


Request:


Request headers:

{
  "authorization": "Bearer Token"
}

Expected Response:


Status 200 - OK

{
  [
    {
    "id": "7fd311fe-f80a-465e-9ed9-8bb4e28bbf45",
    "name": "Ricardo",
    "email": "[email protected]",
    "phone" : "0xx 9xxxx-xxxx",
    "isAdm": true,
    "createdAt": "2022-10-29T00:41:28.717Z",
    }
    ...
  ]
}

Error Responses:


Status 401 - UNAUTHORIZED - "Token required"

{
  "message": "Missing authorization token"
}

Status 403 - UNAUTHORIZED - "User is not an admin"

{
  "message": "User is not an admin"
}

1.3 List User by Id

Back to Endpoints


GET /users/:id


Request:


Request headers:

{
  "authorization": "Bearer Token"
}

Expected Response:


Status 200 - OK

{

   {
    "id": "7fd311fe-f80a-465e-9ed9-8bb4e28bbf45",
    "name": "Ricardo",
    "email": "[email protected]",
    "phone" : "0xx 9xxxx-xxxx",
    "isAdm": true,
    "createdAt": "2022-10-29T00:41:28.717Z",
    "contacts": []
    }
}

Error Responses:


Status 401 - UNAUTHORIZED - "Token required"

{
  "message": "Missing authorization token"
}

1.4 Update User by Id

Back to Endpoints


PATCH /users/:id


Request:


Request headers:

{
  "authorization": "Bearer Token"
}

Expected Response:


Status 200 - OK

{

  {
    "name": "Ricardo Martins",
    "phone" : "0xx 98xxx-xxxx",
    "email": "[email protected]",
  }
}

Error Responses:


Status 401 - UNAUTHORIZED - "Missing authorization token"

{
  "message": "Missing authorization token"
}

Status 401 - UNAUTHORIZED - "Only admin can update or delete other users"

{
  "message": "Only admin can update or delete other users"
}

1.5 Delete User by Id

Back to Endpoints


DELETE /users/:id


Request:


Request headers:

{
  "authorization": "Bearer Token"
}

Expected Response:


Status 204 - No Content

No body returned for response

Error Responses:


Status 401 - UNAUTHORIZED - "Missing authorization token"

{
  "message": "Missing authorization token"
}

Status 403 - FORBIDDEN - "Only admin can update or delete other users"

{
  "message": "Only admin can update or delete other users"
}

Status 400 - Bad Request - "User already deleted"

{
  "message": "User already deleted"
}

Status 404 - Not Found - "User not found id invalid"

{
  "message": "User not found"
}

2. Contacts

Back to Endpoints


The User object is defined as:

Field Type Description
id string Contact unique identifier
name string Contact name *
email string Contact email *
phone string Contact Phone *
user string Defines which user owns this contact
createdAt string Date when the contact was created


Endpoints


Method Routes Description
POST /contacts Create contacts
GET /contacts List all contacts
PATCH /contacts/:id Update contacts
DELETE /contacts/:id Delete contacts


POST /contacts


Request:


Request body:

{
  "name": "Guilherme",
  "email": "[email protected]",
  "phone": "0xx 9xxxx-xxxx",
}

Expected Response:


Status 201 - CREATED

{

  {
	  "id": "341f4ee4-8d77-4866-bf47-8d3e32d531e8",
    "name": "Guilherme Martins",
    "email": "[email protected]",
    "phone": "11999897898",
    "user": "7fd311fe-f80a-465e-9ed9-8bb4e28bbf45",
    "createdAt": "2023-02-08T03:23:20.977Z"
  }
}

Error Responses:


Status 409 - CONFLICTS - You already have this contact

{
  "message": "You already have this contact"
}

If that contact is already on your list.

Different users can have the same contact.


1.2 List Contacts

Back to Endpoints


GET /contacts


Request:


Request headers:

{
  "authorization": "Bearer Token"
}

Expected Response:


Status 200 - OK

{
  [
    {
      "id": "341f4ee4-8d77-4866-bf47-8d3e32d531e8",
      "name": "Guilherme Martins",
      "email": "[email protected]",
      "phone": "11999897898",
      "user": "7fd311fe-f80a-465e-9ed9-8bb4e28bbf45",
      "createdAt": "2023-02-08T03:23:20.977Z"
    }
    ...
  ]
}

Error Responses:


Status 401 - UNAUTHORIZED - "Token required"

{
  "message": "Token required."
}

Status 403 - UNAUTHORIZED - "User is not admin"

{
  "message": "User is not an admin"
}

1.3 Update Contact by Id

Back to Endpoints


PATCH /contacts/:id


Request:


Request headers:

{
  "authorization": "Bearer Token"
}

Expected Response:


Status 200 - OK

{

  {
    "name": "Guilherme Martins",
    "phone" : "0xx 97xxx-xxx2",
    "email": "[email protected]",
  }
}

Error Responses:


Status 401 - UNAUTHORIZED - "Missing authorization token"

{
  "message": "Token required"
}

Status 401 - UNAUTHORIZED - "You can only edit your own contact"

{
  "message": "You can only edit your own contact"
}

Status 404 - NOT FOUND - "This contact dont exist"

{
  "message": "This contact dont exist"
}

1.4 Delete User by Id

Back to Endpoints


DELETE /contacts/:id


Request:


Request headers:

{
  "authorization": "Bearer Token"
}

Expected Response:


Status 204 - No Content

No body returned for response

Error Responses:


Status 401 - UNAUTHORIZED - "Missing authorization token"

{
  "message": "Missing authorization token"
}

Status 401 - UNAUTHORIZED - "You can only update or delete your own contact"

{
  "message": "You can only update or delete your own contact"
}

Status 404 - Not Found - "Contact not found"

{
  "message": "Contact not found"
}

3. SESSIONS

Back to Endpoints


The Session object is defined as:

Field Type Description
email string Registered user email
password string Registered user password

Endpoints


Method Routes Description
POST /sessions Create user


3.1 Session

Back to Endpoints


POST /sessions


Request:


Request body:

{
  "email": "[email protected]",
	"password": "123456"
}

Expected Response:


Status 200 - OK

{
  {
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijc4NWFjMDRmLWE4NWMtNGJlMy05YTc5LTY3NmFjYzZhYmUyYiIsImlzQWRtIjp0cnVlLCJpYXQiOjE2NzU4MjQyMDQsImV4cCI6MTY3NTkxMDYwNCwic3ViIjoiNzg1YWMwNGYtYTg1Yy00YmUzLTlhNzktNjc2YWNjNmFiZTJiIn0.2Fwg3Fl4DBJcbZyR3mMSyJ76wV7BI-HQrCGZBYQYdX8"
  }
}

Error Responses:


Status 403 - FORBIDDEN - "Missing authorization token"

{
	"message": "Invalid user or password"
}

4. PROFILE

Back to Endpoints


Endpoints


Method Routes Description
GET /profile Get all data from the user who owns the token


6.1 Profile

Back to Endpoints


POST /profile


Request:


No body Request:


Expected Response:


Status 200 - OK

{
  {
    "id": "7fd311fe-f80a-465e-9ed9-8bb4e28bbf45",
    "name": "Ricardo",
    "email": "[email protected]",
    "phone" : "0xx 9xxxx-xxxx",
    "isAdm": true,
    "createdAt": "2022-10-29T00:41:28.717Z",
    "contacts": []
  }
}

Error Responses:


Status 403 - FORBIDDEN - "Missing authorization token"



Getting Started with DOCKER

Available Scripts

In the project directory, you can run:

docker-compose up

contact-list-backend-ormartins02's People

Contributors

ormartins01 avatar

Stargazers

Edson Rodrigues avatar

Watchers

Mauricio Giacomini avatar Lorena Belo avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.