Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/murilodamarioo/find-a-friend


https://github.com/murilodamarioo/find-a-friend

api-server docker-compose fastify jwt typescript

Last synced: about 4 hours ago
JSON representation

Awesome Lists containing this project

README

        

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

## ๐Ÿš€๐ŸŒŸ **Project** **Find a Friend App**

## RFs (Functional Requirements)
- [X] It should be possible to register a pet.
- [X] It should be possible to list all pets available for adoption in a city.
- [X] It should be possible to filter pets by their characteristics.
- [X] It should be possible to view the details of a pet for adoption.
- [X] It should be possible to register as an organization (ORG).
- [X] It should be possible to login as an ORG.

## BRs (Business Rules)
- [X] To list the pets, the city must be provided.
- [X] An ORG must have an address and a WhatsApp number.
- [X] A pet must be linked to an ORG.
- [X] The user who wants to adopt will contact the ORG via WhatsApp.
- [X] All filters, in addition to the city, are optional.
- [X] For an ORG to access the application as an admin, it must be logged in.

---

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

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

---

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

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

2๏ธโƒฃ **๐Ÿ“‚ Navigate to the project directory:**
```bash
cd find-a-friend
```

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
```

---

## ๐Ÿข Organizations Routes

### ๐Ÿ“ **Register Organization**
- ๐Ÿ› ๏ธ **Method:** `POST`
- ๐ŸŒ **URL:** `/orgs`
- ๐Ÿ“ **Description:** Registers a new org.
- ๐Ÿ“จ **Request:**
```json
{
"name": "Best Friends",
"email": "[email protected]",
"whatsapp": "1199884423",
"password": "123456",
"cep": "1322890",
"state": "SP",
"city": "Sรฃo Paulo",
"neighborhood": "Moema",
"street": "Rua Moema",
"latitude": -23.6020717,
"longitude": -46.6771666
}
```
- ๐Ÿ“ค **Response:**
```
status: 201
```

### ๐Ÿ”‘ **Authenticate Organization**
- ๐Ÿ› ๏ธ **Method:** `POST`
- ๐ŸŒ **URL:** `/auth`
- ๐Ÿ“ **Description:** Authenticates a organization.
- ๐Ÿ“จ **Request:**
```json
{
"email": "string",
"password": "string"
}
```
- ๐Ÿ“ค **Response:**

`status: 200`
```json
{
"token": "string"
}
```

### ๐Ÿ“ **Fetch Nearby Organizations**
- ๐Ÿ› ๏ธ **Method:** `GET`
- ๐ŸŒ **URL:** `/orgs/nearby`
- ๐Ÿ“จ **Query Parameters**
- `latidude`: `number` **(required)**
- `longitude`: `number` **(required)**
- ๐Ÿ“ **Description:** Retrieves a list of organizations near the given location.
- ๐Ÿ“ค **Response:**

`status: 200`
```json
{
"orgs": [
{
"id": "a729b53e-e566-447a-bb50-4ecaff5a8d0d",
"name": "Best Friends",
"email": "[email protected]",
"whatsapp": "1199884423",
"cep": "1322890",
"state": "SP",
"city": "Sรฃo Paulo",
"neighborhood": "Moema",
"street": "Rua Moema",
"latitude": "-23.6020717",
"longitude": "-46.6771666"
}
]
}
```
## ๐Ÿพ Pets Routes

### ๐Ÿ“‹ **Register Pet**
- ๐Ÿ› ๏ธ **Method:** `Post`
- ๐ŸŒ **URL:** `/orgs/pets`
- ๐Ÿ” **Middleware**: JWT verification is required
- ๐Ÿ“ **Description:** Registers a new pet under an authenticated organization.
- ๐Ÿ“จ **Request:**
```json
{
"name": "Peanut",
"about": "Corgi",
"age": "1",
"size": "small",
"energy_level": "high",
"environment": "indoor",
"isAvailable": true
}
```
- ๐Ÿ“ค **Response:**

`status: 201`
```json
{
"id": "49f9c161-26ba-4c89-9516-c11ffc3bddab",
"name": "Peanut",
"about": "Corgi",
"age": "1",
"size": "small",
"energy_level": "high",
"environment": "indoor",
"isAvailable": true,
"org_id": "a729b53e-e566-447a-bb50-4ecaff5a8d0d"
}
```

### ๐Ÿ” **Get Pet by ID**
- ๐Ÿ› ๏ธ **Method:** `GET`
- ๐ŸŒ **URL:** `/orgs/pets/:id`
- ๐Ÿ“ **Description:** Fetches details of a pet by its ID.
- ๐Ÿ“ค **Response:**

`status: 200`
```json
{
"id": "49f9c161-26ba-4c89-9516-c11ffc3bddab",
"name": "Peanut",
"about": "Corgi",
"age": "1",
"size": "small",
"energy_level": "high",
"environment": "indoor",
"isAvailable": true,
"org_id": "a729b53e-e566-447a-bb50-4ecaff5a8d0d"
}
```

### ๐Ÿ” **Search Pets**
- ๐Ÿ› ๏ธ **Method:** `GET`
- ๐ŸŒ **URL:** `/orgs/pets`
- ๐Ÿ” Query Parameters:
- `city`: `string` **(required)**
- `age`: `string` **(optional)**
- `energy_level`: `string` **(optional)**
- `environment`: `string` **(optional)**
- `size`: `string` **(optional)**
- ๐Ÿ“ **Description:** Searches for pets based on query parameters.

- ๐Ÿ“ค **Response:**

`status: 200`
```json
{
"pets": [
{
"id": "2f16bbe1-3a8d-413c-9fbf-eb7c63d10a6f",
"name": "Peanut",
"about": "Cute dog",
"age": "1",
"size": "small",
"energy_level": "high",
"environment": "indoor",
"isAvailable": true,
"org_id": "a729b53e-e566-447a-bb50-4ecaff5a8d0d"
},
]
}
```

---

## ๐Ÿงช **Tests**

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

Runs the tests and watches for changes in the `src/use-cases/` 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
````