Skip to content

This is the backend REST API made with Node.js, Express, and TypeScript for the GoBarber project. GoBarber is a web application for appointment scheduling designed for barbershops and hair salons.

Notifications You must be signed in to change notification settings

wilsonfsouza/gobarber-rest-api

Repository files navigation

GitHub top language GitHub last commit License Made by Wilson Franca

GoBarber REST API

Table of Contents

AboutHow to runUsageTestsTechnologiesAuthorLicense

💻 About the project

This is the backend REST API made with Node.js, Express, and TypeScript for the GoBarber project. GoBarber is a web application for appointment scheduling designed for barbershops and hair salons.

By signing up, users can schedule a new appointment with all available stylists working at the business. On the other hand, registered stylists have access to a web interface to manage their schedules with real-time updates (new or canceled appointments).

To see the web client, click here: GoBarber Web
To see the mobile client, click here: GoBarber Mobile


🔥 Preview

Demo credentials:

acc: [email protected] / password: demo-password-peppa

Deploy to Netlify


🚀 How to run the project

Requirements

Initial requirements: git, yarn, docker, and a code editor of your choice.

Install project and dependencies

# Clone this repository
$ git clone https://github.com/wilsonfsouza/gobarber-rest-api.git

# Access the folder in your terminal
$ cd gobarber-rest-api

# Install all dependencies
$ yarn install

# Make a copy of '.env.example' to '.env'
# and set with YOUR environment variables.
# The AWS variables do not need to be filled for development environment
$ cp .env.example .env

Setup databases

This project uses three databases:

  • Postgres: to store most of the application data (general use)
  • MongoDB: to store application's notifications
  • Redis: to store the application's cache and rate limit middleware

Postgres

# Create the instance of postgreSQL using docker
$ docker run --name postgres -e POSTGRES_USER=postgres \
              -e POSTGRES_DB=gostack_gobarber -e POSTGRES_PASSWORD=docker \
              -p 5432:5432 -d postgres

# Make a copy of 'ormconfig.example.json'
# to 'ormconfig.json'
# and set YOUR default database configuration.
$ cp ormconfig.example.json ormconfig.json

# Run typeorm migrations
$ yarn typeorm migration:run

If you do not have Postgres installed on your machine, the port 5432 should be available. Otherwise, you can use port 5433 instead. Use -d flag to run your container in detached mode. This mode allows you to start and run your container in the background.

MongoDB

# Create the instance of mongoDB using docker
$ docker run --name mongodb -p 27017:27017 -d -t mongo

# Access your ormconfig.json and add
# YOUR mongo configuration

# How do I know if MongoDB is running? Access localhost:27017 on your browser.

Redis

# Create the instance of redis using docker
$ docker run --name gobarber-redis -p 6379:6379 -d -t redis:alpine

# Access your .env file and add your REDIS configuration

For Windows users using Docker Toolbox, you might need to set the host for your databases on your .env and ormconfig.json files to 192.168.99.100 (docker machine IP) instead of localhost or 127.0.0.1.

Understanding .env

key description default
APP_API_URL Used to mount avatars' urls. http://localhost:3333
APP_WEB_URL Used to create the reset password link (front-end) sent in the recover password email. http://localhost:3000
APP_SECRET An alphanumeric random string. Used to create signed tokens. -
MAIL_DRIVER Indicate what email service use to send messages, the possible values are ethereal and ses, to use the SES service remember to to configure the AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_DEFAULT_REGION keys. ethereal
AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY These keys are necessary to AWS allow the application to use the S3 and SES services throught API. See how to get yours keys here: Set up AWS Credentials. -
AWS_DEFAULT_REGION You can see your default region in the navigation bar at the top right after login in the AWS Management Console. Read AWS service endpoints to know more about regions. -
STORAGE_DRIVER Indicate where the users's avatar will be stored, the possible values are disk and s3, to store into S3 remember to configure all the AWS_* keys. disk
REDIS_HOST Redis host. localhost
REDIS_PORT Redis port. 6379
REDIS_PASS Redis password. -

Start the application

# To start development server, run:
$ yarn dev:server

⭐ Usage

Bearer Token

This app has open and private routes. Private routes expect a Bearer token in an Authorization header. The token is generated after a user sign in into the application throughout the /sessions route. This token will expire after 2 hours.

Routes

Users

Route HTTP Method Params Description Auth method
/sessions POST Body with user's email and password. Authenticates user, return a Bearer Token and user's id and email.
/users POST Body with user's name, email, and password. Sign up for new users.
/profile GET - Shows user profile. Bearer
/profile PUT Body with user name, email, old_password, password, and password_confirmation. Updates user information. Bearer
/users/avatar PATCH Multipart payload with a avatar field with a image. Update user avatar. Bearer
/password/forgot POST Body with user's email. Sends to user the reset password email.
/password/reset POST Body with user's new password and password_confirmation. Resets user's password.

Appointments

Route HTTP Method Params Description Auth method
/appointments POST Body with appointment provider_id and date. Schedules a new appointment. Bearer
/appointments/me GET day, month and year query parameters. Returns user's scheduled appointments in a specific date. Bearer
/providers GET page query parameter. Lists providers. Bearer
/providers/:id/monthly-availability GET month and year query parameters. Lists provider's monthly availability Bearer
/providers/:id/daily-availability GET day, month and year query parameters. Lists provider's daily availability for a given day. Bearer

⚙️ Tests

# Running tests
$ yarn test

# Generating test coverage
$ yarn test --coverage

🛠 Technologies

The following tools were used in this project:

REST API (Node.js + TypeScript)

See the file package.json

Utilities


💪 How to contribute to this project

  1. Fork the project.
  2. Start a new branch with your changes: git checkout -b my-new-feature
  3. Save it and create a commit message describing what you have done: git commit -m "feature: My new feature"
  4. Send your alterations: git push origin my-feature

👨‍💻 Author



Wilson Franca


Linkedin Badge Gmail Badge


📝 License

This project is being developed under MIT License.

Made with ❤️ by Wilson Franca 👋

About

This is the backend REST API made with Node.js, Express, and TypeScript for the GoBarber project. GoBarber is a web application for appointment scheduling designed for barbershops and hair salons.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published