Skip to content

An API for a application that allows users to find gyms and check-in at them.

Notifications You must be signed in to change notification settings

LeonardoSPereira/Fit-Connect

Repository files navigation

Fit Connect

This is an API for a application that allows users to find gyms and check-in at them.

📝 Table of Contents

🧐 About

  • This is an API for a application that allows users to find gyms and check-in at them.
  • The API allows users to register, authenticate, find gyms, check-in at gyms, and more.
  • The API is built using Node.js, Fastify, Prisma, and PostgreSQL, using SOLID principles and TDD.

🏁 Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

You will need to have the following installed on your machine:

Installing

With the prerequisites installed, and with docker running, you can run the following commands to get the project up and running:

  1. Clone the repository or download the zip file and extract it:
git clone https://github.com/LeonardoSPereira/Fit-Connect.git
  1. Install the dependencies:
npm install
  1. Create a .env file in the root of the project with the following content:
NODE_ENV=dev

PORT=

DATABASE_URL="postgresql://docker:docker@localhost:5432/fitconnectapi?schema=public"

JWT_SECRET=appjwtsecret
  1. Start the database:
docker-compose up -d
  1. Run the migrations:
npx prisma migrate dev
  1. Start the server:
npm run dev

🏗️ Structure

The project is structured as follows:

├── .github: folder where the project's GitHub actions are located.

├── prisma: folder where the Prisma configuration files are located, with the schema and migrations.

├── src: folder where application files are located.

│   ├── @types: folder where jwt types are located.

│   ├── env: folder where environment variables are located.

│   ├── http: folder where are located the folders that contain the routes, controllers with it's e2e tests, and the middlewares. 

│   ├── lib: folder where the files that contain the configuration of the dependencies used in the application are located.

│   ├── repositories: folder where the folders that contain the interfaces, implementations, and the in-memory implementation of the repositories are located.

│   ├── use-cases: folder where are located the application's use cases with it's unit tests, the errors handlers an the factories, that are responsible for abstracting the creation of the use cases.

│   ├──  utils: folder where the files that contain utility functions are located.

│   ├── app.ts: file that contains the application configuration.

│   └── server.ts: file that contains the server configuration.

└── vitest-environment: folder where the environment configuration for the e2e tests is located.

🔧 Running the tests

The tests are divided into unit tests and e2e tests. To run the tests, you can run the following commands:

  1. To run the unit tests:
npm run test
  1. To run the e2e tests:
npm run test:e2e

Remember that to run the e2e tests, the database must be running.

  • To run the tests with coverage, you can run the following commands:
npm run test:coverage

Break down into end to end tests

The e2e tests test the application's routes, controllers, and middlewares, simulating the user's interaction with the application.

🎈 Features

FRs (Functional Requirements)

  • Users must be able to register;
  • Users must be able to authenticate;
  • Users must be able to retrieve the profile of a logged-in user;
  • Users must be able to obtain the number of check-ins performed by the logged-in user;
  • Users must be able to retrieve their check-in history;
  • Users must be able to search for nearby gyms (until 10km);
  • Users must be able to search for gyms by name;
  • Users must be able to check in at a gym;
  • Users must be able to validate a user's check-in;
  • Admins must be able to register a gym;

BRs (Business Requirements)

  • Users must not be able to register with a duplicate email;
  • Users cannot check in twice on the same day;
  • Users cannot check in if they are not close (100m) to the gym;
  • Check-ins can only be validated up to 20 minutes after creation;
  • Check-ins can only be validated by admins;
  • Gyms can only be registered by admins;

NFRs (Non-functional Requirements)

  • User passwords need to be encrypted;
  • Application data must be persisted in a PostgreSQL database;
  • All data lists must be paginated with 20 items per page;
  • Users must be identified by a JSON Web Token (JWT);

🎈 Usage

To use the API, you can use the following routes:

Users Routes

POST /users - Register a user

POST /sessions - Authenticate a user

GET /me - Retrieve the profile of a logged-in user

PATCH /token/refresh - Refresh the user's JWT token

Gyms Routes

POST /gyms - Register a gym (only for admins)

GET /gyms/nearby - Retrieve a list of gyms near the user

GET /gyms/search - Retrieve a list of gyms by name

Check-ins Routes

POST /gyms/:gymId/check-ins - Check in at a gym
  - Params: gymId

GET /check-ins/history - Retrieve the check-in history of the logged-in user

GET /check-ins/metrics - Retrieve the number of check-ins performed by the logged-in user

PATCH /check-ins/:checkInId/validate - Validate a user's check-in (only for admins)
  - Params: checkInId

⛏️ Built Using

About

An API for a application that allows users to find gyms and check-in at them.

Topics

Resources

Stars

Watchers

Forks