Skip to content

About

GoBarber API to manage barbershop scheduling, developed copying the instructor coding during the Rocketseat's GoStack Course.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

GoBarber API πŸ’ˆ

GoBarber API to manage barbershop scheduling, developed copying the instructor coding during the Rocketseat's GoStack Course.

πŸ“ Features

Public endpoints

Authentication
{
  "post": "/sessions",
  "request": {
    "headers": {
      "Content-Type": "application/json"
    },
    "data": {
      "email": "string",
      "password": "string"
    }
  },
  "response": {
    "200": {
      "user": {
        "id": "string",
        "name": "string",
        "email": "string",
        "avatar": "string",
        "created_at": "Timestamp ISO-8601",
        "updated_at": "Timestamp ISO-8601",
        "avatar_url": "string"
      },
      "token": "string"
    }
  }
}
Create user
{
  "post": "/users",
  "request": {
    "headers": {
      "Content-Type": "application/json"
    },
    "data": {
      "name": "string",
      "email": "string",
      "password": "string"
    }
  },
  "response": {
    "200": {
      "id": "string",
      "name": "string",
      "email": "string",
      "created_at": "Timestamp ISO-8601",
      "updated_at": "Timestamp ISO-8601",
      "avatar_url": null
    }
  }
}
Start the password recovery process
{
  "post": "/passwords/forgot",
  "request": {
    "headers": {
      "Content-Type": "application/json"
    },
    "data": {
      "email": "string"
    }
  },
  "response": {
    "204": {}
  }
}
Create new password
{
  "post": "/passwords/reset",
  "request": {
    "headers": {
      "Content-Type": "application/json"
    },
    "data": {
      "token": "string",
      "password": "string",
      "password_confirmation": "string"
    }
  },
  "response": {
    "204": {}
  }
}

Protected endpoints

Update the user avatar image
{
  "patch": "/users/avatar",
  "request": {
    "headers": {
      "Authorization": "Bearer <token>",
      "Content-Type": "multipart/form-data"
    },
    "data": {
      "avatar": "file",
    }
  },
  "response": {
    "200": {
      "id": "string",
      "name": "string",
      "email": "string",
      "avatar": "string",
      "created_at": "Timestamp ISO-8601",
      "updated_at": "Timestamp ISO-8601",
      "avatar_url": "string"
    }
  }
}
Get the user profile
{
  "get": "/profile",
  "request": {
    "headers": {
      "Authorization": "Bearer <token>"
    },
  },
  "response": {
    "200": {
      "id": "string",
      "name": "string",
      "email": "string",
      "avatar": "string",
      "created_at": "Timestamp ISO-8601",
      "updated_at": "Timestamp ISO-8601",
      "avatar_url": "string"
    }
  }
}
Get provider appointments of a day
{
  "get": "/appointments/provider/me",
  "request": {
    "headers": {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json"
    },
    "data": {
      "year": "integer",
      "month": "integer",
      "day": "integer"
    }
  },
  "response": {
    "200": [
      {
        "id": "string",
        "provider_id": "string",
        "user_id": "string",
        "date": "Timestamp ISO-8601",
        "created_at": "Timestamp ISO-8601",
        "updated_at": "Timestamp ISO-8601",
        "user": {
          "id": "string",
          "name": "string",
          "email": "string",
          "avatar": "string",
          "created_at": "Timestamp ISO-8601",
          "updated_at": "Timestamp ISO-8601",
          "avatar_url": "string"
        }
      }
    ]
  }
}
Get user appointments
{
  "get": "/appointments/user/me",
  "request": {
    "headers": {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json"
    },
  },
  "response": {
    "200": [
      {
        "id": "string",
        "provider_id": "string",
        "user_id": "string",
        "date": "Timestamp ISO-8601",
        "created_at": "Timestamp ISO-8601",
        "updated_at": "Timestamp ISO-8601",
        "provider": {
          "id": "string",
          "name": "string",
          "email": "string",
          "avatar": "string",
          "created_at": "Timestamp ISO-8601",
          "updated_at": "Timestamp ISO-8601",
          "avatar_url": "string"
        }
      }
    ]
  }
}
Create an appointment
{
  "post": "/appointments",
  "request": {
    "headers": {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json"
    },
    "data": {
      "provider_id": "string",
      "date": "Timestamp ISO-8601"
    }
  },
  "response": {
    "200": {
      "id": "string",
      "provider_id": "string",
      "user_id": "string",
      "date": "Timestamp ISO-8601",
      "created_at": "Timestamp ISO-8601",
      "updated_at": "Timestamp ISO-8601"
    }
  }
}
Get all providers except the own user
{
  "get": "/providers",
  "request": {
    "headers": {
      "Authorization": "Bearer <token>",
    }
  },
  "response": {
    "200": [
      {
        "id": "string",
        "name": "string",
        "email": "string",
        "avatar": "string",
        "created_at": "Timestamp ISO-8601",
        "updated_at": "Timestamp ISO-8601",
        "avatar_url": "string"
      }
    ]
  }
}
Get the provider availability in each day of a month
{
  "get": "/providers/:id/month-availability",
  "request": {
    "headers": {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json"
    },
    "data": {
      "month": "integer",
      "year": "integer"
    }
  },
  "response": {
    "200": [
      {
        "day": "integer",
        "available": "boolean"
      }
    ]
  }
}
Get the provider availability in each hour of a day
{
  "get": "/providers/:id/day-availability",
  "request": {
    "headers": {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json"
    },
    "data": {
      "day": "integer",
      "month": "integer",
      "year": "integer"
    }
  },
  "response": {
    "200": [
      {
        "hour": "integer",
        "available": "boolean"
      }
    ]
  }
}

Response Error

Generic error
{
  "400": {
    "status": "error",
    "message": "string"
  },
}
Too many requests
{
  "429": {
    "status": "error",
    "message": "Too many requests"
  }
}

Routes

🧰 Main languages and libraries

Github top language

Fixed lib Fixed lib Fixed lib

πŸš€ Publishing

Github Actions is being used to deploy and deliver the applications on Digital Ocean server.

πŸ§ͺ Test Coverage Report (Jest library)

Image Image

βš™οΈ Setup

  1. Environment:
  • NodeJS: v12.18.0
  • Yarn: v1.22.5
  1. Project
# clone this repo
$ git clone https://github.com/danielynx/rocketseat-gobarber-api.git

# go to project folder
$ cd rocketseat-gobarber-api

# install dependencies
$ yarn install

# Config the environment variables on .env file

# Start the development environment
$ yarn dev:server

πŸ“– Main concepts that I learned in this project

  • User authentication using JWT.
  • How connect with Postgres using TypeOrm component.
  • How structure applications follow some SOLID principles.
  • Learned that Drive Domain Development (DDD) define that the application's folders, files and class must be separated into modules according to the domain that the application cover.
  • Refactored the application to apply the Dependency Inversion principle.
  • Control the dependency injection with the Tsyringe library.
  • How to use Jest Library to make unitary test that validate the business rules, that in turn are isolated into the Service layer.
  • To vendors dependencies it's necessary create a provider module, that isolate the vendor dependency and connect these provider with my application using an interface.
  • Used the Ethereal library to manage email sending on development environment.
  • Created the notification module to stores, into the MongoDB, the messages that need be delivered to users.
  • Created validations to route's body parameters using Celebrate and Joi libraries.
  • Isolated the environment variables using Dotenv library.
  • How expose and exclude entities fields on response using ClassTranform library.
  • Created the mail provider to send mail by AmazonAWS SES.
  • Created the storage provider to upload file to AmazonAWS S3.
  • Created the cache provider that use Redis as cache storage.
  • Using the same Redis as storage, limited the number of requests per second using RateLimiterFlexible library.
  • Create Github actions to build and deploy to the server.
  • Config Nginx and PM2 on DigitalOcean Server to delivery a NodeJS application.
  • Create SSL certification with certbot tools.

About

GoBarber API to manage barbershop scheduling, developed copying the instructor coding during the Rocketseat's GoStack Course.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages