Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/murilodamarioo/gympass-style-app


https://github.com/murilodamarioo/gympass-style-app

docker-compose fastify jwt typescipt

Last synced: about 21 hours ago
JSON representation

Awesome Lists containing this project

README

        

# ๐Ÿ“šโœจ **API Documentation**

## ๐Ÿš€๐ŸŒŸ **Project** **Gympass Style App**

## RFs (Functional Requirements)
- [X] It must be possible to register;
- [X] It must be possible to authenticate;
- [X] It must be possible to retrieve the profile of a logged-in user;
- [X] It must be possible to get the number of check-ins performed by the logged-in user;
- [X] It must be possible for the user to access their check-in history;
- [X] It must be possible for the user to search for nearby gyms (10km);
- [X] It must be possible for the user to search for gyms by name;
- [X] It must be possible for the user to check in at a gym;
- [X] It must be possible to validate a user's check-in;
- [X] It must be possible to register a gym;

## RNs (Business Rules)
- [X] User must not be able to register with a duplicate email;
- [X] User cannot perform more than one check-in on the same day;
- [X] User cannot check in unless they are within 100 meters of the gym;
- [X] Check-in can only be validated up to 20 minutes after it is created;
- [X] Check-in can only be validated by administrators;
- [X] A gym can only be registered by administrators;

## RNFs (Non-Functional Requirements)
- [X] User passwords must be encrypted;
- [X] Application data must be persisted in a PostgreSQL database;
- [X] All data lists must be paginated with 20 items per page;
- [X] Users must be identified by a JWT (JSON Web Token);

---

## ๐Ÿ› ๏ธ๐Ÿ’ป **Technologies Used**

- ๐ŸŸข **Language:** [Node.js, Typescript]
- ๐Ÿ—๏ธ **Framework:** [Fastify]
- ๐Ÿ—„๏ธ **Database:** [PostgreSQL]
- ๐Ÿ”’ **Authentication:** [JWT]
- ๐Ÿšข **Other Technologies:** [Docker, CI]

---

## ๐Ÿ“ฆโš™๏ธ **Installation & Configuration**

1๏ธโƒฃ **๐Ÿ“ฅ Clone the repository:**
```bash
git clone https://github.com/murilodamarioo/gympass-style-app.git
```

2๏ธโƒฃ **๐Ÿ“‚ Navigate to the project directory:**
```bash
cd gympass-style-app
```

3๏ธโƒฃ **๐Ÿ“ฆ Install dependencies:**
```bash
npm install
```

4๏ธโƒฃ **๐Ÿ“ Set up environment variables:**
Create a `.env` file based on `.env.example` and adjust as needed.

5๏ธโƒฃ **๐Ÿš€ Start the server:**
```bash
npm start
```
---
## ๐Ÿšข Docker Container

To up a PostgreSQL Container
```bash
docker compose up -d
```

To stop PostgreSQL image
```bash
docker compose stop
```

---

## ๐Ÿ”‘๐Ÿ›ก๏ธ **Authentication**

This API uses **๐Ÿ” JWT (JSON Web Token)** for authentication. Make sure to include the token in the ๐Ÿ“จ header of protected requests.

**๐Ÿ“ Header Example:**
```http
Authorization: Bearer
```

---

## ๐Ÿ“š๐Ÿ“Š **Main Endpoints**

### ๐Ÿ“๐Ÿ‘ค **1. Register User**
- ๐Ÿ› ๏ธ **Method:** `POST`
- ๐ŸŒ **URL:** `/users`
- ๐Ÿ“ **Description:** Registers a new user.
- ๐Ÿ“จ **Request:**
```json
{
"name": "string",
"email": "string",
"password": "string"
}
```
- ๐Ÿ“ค **Response:**
```json
{
"status": 201,
}
```

### ๐Ÿ”‘ **2. Authenticate User**
- ๐Ÿ› ๏ธ **Method:** `POST`
- ๐ŸŒ **URL:** `/sessions`
- ๐Ÿ“ **Description:** Authenticates a user.
- ๐Ÿ“จ **Request:**
```json
{
"email": "string",
"password": "string"
}
```
- ๐Ÿ“ค **Response:**
```json
{
"status": 200,
"token": "string"
}
```

### ๐Ÿ‘ค **4. Get Profile**
- ๐Ÿ› ๏ธ **Method:** `GET`
- ๐ŸŒ **URL:** `/me`
- ๐Ÿ“ **Description:** Returns authenticated user profile.
- ๐Ÿ“ค **Response:**
```json
{
"status": 200,
"id": 1,
"name": "John Doe",
"email": "[email protected]"
}
```

### ๐Ÿ‹๏ธโ€โ™‚๏ธ **5. Search Gyms**
- ๐Ÿ› ๏ธ **Method:** `GET`
- ๐ŸŒ **URL:** `/gyms/search`
- ๐Ÿ“ **Description:** Searches gyms by query.
- - ๐Ÿ“จ **Query Params:**
```json
{
"query": "string",
"page": "number"
}
```
- ๐Ÿ“ค **Response:**
```json
{
"status": 200,
"gyms": []
}
```

### ๐Ÿ“ **6. Nearby Gyms**
- ๐Ÿ› ๏ธ **Method:** `GET`
- ๐ŸŒ **URL:** `/gyms/nearby`
- ๐Ÿ“ **Description:** Finds nearby gyms.
- ๐Ÿ“ค **Response:**
```json
{
"status": 200,
"gyms": []
}
```

### ๐Ÿ—๏ธ **7. Create Gym (ADMIN)**
- ๐Ÿ› ๏ธ **Method:** `POST`
- ๐ŸŒ **URL:** `/gyms`
- ๐Ÿ“ **Description:** Creates a new gym.
- - ๐Ÿ“จ **Request:**
```json
{
"title": "string",
"description": "string",
"phone": "string",
"latitude": "number",
"longitude": "number"
}
```
- ๐Ÿ“ค **Response:**
```json
{
"status": 201,
}
```

### ๐Ÿ“‹ **8. Check-in History**
- ๐Ÿ› ๏ธ **Method:** `GET`
- ๐ŸŒ **URL:** `/check-ins/history`
- ๐Ÿ“ **Description:** Retrieves check-in history.
- ๐Ÿ“ค **Response:**
```json
{
"status": 200,
"checkIns": [
"id": "string",
"created_at": "Date",
"validated_at": "Date",
"gym_id": "string",
"user_id": "string",
]
}
```

### ๐Ÿ“Š **9. Check-in Metrics**
- ๐Ÿ› ๏ธ **Method:** `GET`
- ๐ŸŒ **URL:** `/check-ins/metrics`
- ๐Ÿ“ **Description:** Displays check-in metrics.
- ๐Ÿ“ค **Response:**
```json
{
"status": 200,
"checkInsCount": 10
}
```

### โœ… **10. Validate Check-in (Admin)**
- ๐Ÿ› ๏ธ **Method:** `PATCH`
- ๐ŸŒ **URL:** `/check-ins/:checkInId/validate`
- ๐Ÿ“ **Description:** Validates a check-in.
- ๐Ÿ“ค **Response:**
```json
{
"status": 204,
}
```
---

## ๐Ÿงช **Tests**

### 1. **Unit Tests**
Runs all unit tests located in the `test/` directory.
```bash
npm run test
````

Runs the tests and watches for changes in the test/ directory. Tests will automatically rerun on any changes.
```bash
npm run test:watch
````

### 2. **E2E Tests**
Runs the tests for integration/HTTP files located in the `src/http` directory, typically used for testing client-server communication.
```bash
npm run test:e2e
````
### 3. Test Coverage
Runs all tests and generates a coverage report, showing the percentage of code covered by tests.
```bash
npm run test:coverage
````