This application allows users to check in at nearby gyms, view their check-in history, and search for gyms by name. Additionally, administrators can validate check-ins and register new gyms.
In this flow, we present the steps for authentication, check-in, check-in validation, gym search, and obtaining metrics.
Setting up the environment
Make sure you have Node.js, Docker, and Docker Compose installed on your system.
-
Cloning the repository
git clone https://github.com/your-username/gym-app.git cd gym-app
-
Installing dependencies
npm install
-
Configuring environment variables
Copy the .env.example to a .env file in the root of the project
-
Running with Docker Compose
Use the provided Docker Compose file to set up the PostgreSQL database:
Then run:
docker-compose up -d
-
Running database migrations
npx prisma migrate dev
-
Running the application
npm run dev
Access http://localhost:3000 in your browser.
Endpoints
-
POST /users: Create a new user
{ "name": "John Doe", "email": "johndoe@gmail.com", "password": "1a2b3c" }
-
POST /sessions: Create a session (login) for the user
{ "email": "johndoe@gmail.com", "password": "1a2b3c" }
-
POST /sessions/refresh: Refresh access token
{ "email": "johndoe@gmail.com", "password": "1a2b3c" }
-
GET /me: Get the profile of the logged-in user
-
GET /check-ins/history: Get the user's check-in history
-
GET /check-ins/metrics: Get total check-in metrics for the user
-
POST /gyms/:gymId/check-ins: Check in at a gym
{ "gymId": "1234567890" }
-
PATCH /check-ins/:checkInId/validate: Validate a check-in (Admins only)
{ "checkInId": "0987654321" }
-
GET /gyms/search: Search gyms by name
- Query Params:
- name: Name of the gym to search for
- Query Params:
-
GET /gyms/nearby: Get nearby gyms (within 10km)
- Query Params:
- latitude: User's latitude
- longitude: User's longitude
- Query Params:
-
POST /gyms: Register a new gym (Admins only)
{ "name": "Test Gym", "latitude": "-23.5505", "longitude": "-46.6333" }
The application is covered by unit and E2E tests
- Should be possible to register;
- Should be possible to authenticate;
- Should be possible to get logged user profile information;
- Should be possible to obtain the total check-in quantity of the logged user;
- Should be possible to the user to get his check-in history;
- Should be possible to get the closest gyms (in a 10km range);
- Should be possible to search for gyms by their name;
- Should be possible to the user to do a check-in operation in a gym;
- Should be possible to validate user check-in;
- Should be possible to register a gym;
- User cant register with a duplicate email address;
- User cant do 2 check-ins in the same day;
- User cant do a check-in operation if he's close (100mts) to the gym;
- Check-in can only be validated until after 20 minutes after creation;
- Check-in can only be validated by admins;
- Gym can only be registered by admins;
- User's password must be cryptographed;
- Application data must be persisted on a PostgreSQL database;
- All data lists must be paginated with 20 items per page;
- User must be identified by a JWT token (JSON Web Token);
User passwords are encrypted before being stored in the database.
All application data is persisted in a PostgreSQL database.
All data lists are paginated, displaying 20 items per page.
The user is identified by a JWT (JSON Web Token) during the session.