Coder Social home page Coder Social logo

kunzeleric / gym__api__solid Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 564 KB

An API that works like GymPass application, where a user creates and account and checks in nearby gyms. Built with Fastify and Typescript, including Unit and E2E tests with CI.

TypeScript 100.00%

gym__api__solid's Introduction

Gympass style app

This is an API was developed during the SOLID module of Rocketseat's Ignite track, featuring clean code practices as well. It is similar to a GymPass application, making it possible for a user to register his\her account and check-in nearby gyms, in a close-to-reality scenario.

Functionalities

  • User can register an account
  • User can register gyms
  • User can check in in Gyms nearby
  • User is authenticated
  • User can search gyms based on query parameters
  • User can check check-ins metrics & history

Technologies Used

  • Node.js
  • Typescript
  • Fastify
  • Zod
  • PostgreSQL
  • Docker
  • Vitest
  • Supertest

Installing the Project

git clone *projet-url*

cd *projects-directory*

npm install

Load Docker Image (PostgreSQL)

*Reminder: Docker software must be installed previously.

docker compose up -d

Functional Requirements

  • User registration must be possible.
  • User authentication must be possible.
  • It must be possible to obtain the profile of a logged-in user.
  • It must be possible to obtain the number of check-ins performed by the logged-in user.
  • It must be possible to obtain the check-in history of a user.
  • It must be possible to search for gyms near the user (up to 10km).
  • It must be possible to search for gyms by name.
  • The user must be able to check-in at a gym.
  • Validating a user's check-in must be possible.
  • It must be possible to register a gym.

Non-Functional Requirements

  • The user's password needs to be encrypted.
  • Application data must be persisted in a PostgresSQL database.
  • All data lists must be paginated with 20 items per page.
  • The user must be identified by a JWT (JSON Web Token).

Business Rules

  • The user should not be able to register with a duplicate email.
  • The user cannot make 2 check-ins on the same day.
  • The user cannot check-in if not near the gym (100m).
  • The check-in can only be validated up to 20 minutes after it is created.
  • The check-in can only be validated by administrators.
  • The gym can only be registered by administrators.

Routes

User

Register User

  POST /user
Body Data Type Description
name string Mandatory. Users name
email string Mandatory. Users email.
password string Mandatory. Users password.

Authenticate User

  POST /authenticate
Body Data Type Description
email string Mandatory. Users email.
password string Mandatory. Users password.

Refresh Token

  PATCH /token/refresh

Profile

  GET /me

Gym

Create a Gym

  POST /gyms
Body Data Type Description
title string Mandatory. Gyms title.
description string Mandatory. Gyms description.
phone string Mandatory. Gyms phone.
latitude number Mandatory. Gyms latitude position.
longitude number Mandatory. Gyms longitude position.

Find Gyms

  GET /gyms/search
Query Data Type Description
q string Mandatory. Query search field.
page number Mandatory. Pagination number for search.

Fetch Nearby Gyms

  GET /gyms/nearby
Query Data Type Description
latitude number Mandatory. Users latitude position.
longitude number Mandatory. Users longitude position.

Check In

Create a Check In

  POST /gyms/:gymId/check-ins
Param Data Type Description
gymId string Mandatory. Gym's ID that the check-in is being made in.
Body Data Type Description
latitude number Mandatory. Users latitude position.
longitude number Mandatory. Users longitude position.

Validate Check In

  PATCH /check-ins/:checkInId/validate
Param Data Type Description
checkInId string Mandatory. Check-In ID that's being validated.

Check-Ins History

  GET /check-ins/history
Query Data Type Description
page number Mandatory. Pagination number to search check-ins history.

Check-Ins Metrics

  GET /check-ins/metrics

Take Aways

  • Environment Variables validation with Zod
  • Build Docker compose file to run PostgreSQL image
  • Principle of inverse dependency and single responsibility
  • Automated tests through Github Actions
  • Build test environment for Vitest
  • Build application separating layers (HTTP, Repository, Use-Case)

gym__api__solid's People

Contributors

kunzeleric avatar

Watchers

 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.