Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/murilodamarioo/find-a-friend
- Owner: murilodamarioo
- Created: 2025-01-05T01:02:58.000Z (11 days ago)
- Default Branch: main
- Last Pushed: 2025-01-15T02:17:33.000Z (about 20 hours ago)
- Last Synced: 2025-01-15T04:00:37.332Z (about 19 hours ago)
- Topics: api-server, docker-compose, fastify, jwt, typescript
- Language: TypeScript
- Homepage:
- Size: 225 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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 ContainerTo 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
````