Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/juanmachuca95/conductores_go

Challenge - Golang Gin-Framework, MySQL, Seeders. GoMocks, Clean Architecture, Unit-Testing
https://github.com/juanmachuca95/conductores_go

clean-architecture gin golang gomock mysql sqlmock testing

Last synced: 9 days ago
JSON representation

Challenge - Golang Gin-Framework, MySQL, Seeders. GoMocks, Clean Architecture, Unit-Testing

Awesome Lists containing this project

README

        

# Deployment

Para este challenge utilizaré docker y docker-compose para crear el contenedor de la api y para la conexión a la base de datos con mysql, simplemente configuraré las variables de entorno (```.env```) al servicio externo.

## Step by Step

Iniciamos nuestra conexion via ssh o de su preferencia para conectarse con su instancia para deploy de aplicación de acuerdo a su proveedor, en mi caso será un ubuntu 20.04 - en digitalocean. Primero clonamos el repositorio:

```sh
git clone https://github.com/juanmachuca95/conductores_go
```

```sh
cd conductores_go
nano .env
```

2. Seteamos nuestras variables de entorno:

```
DATABASE=""
PORT="3306"
USERNAME=""
PASSWORD=""
HOSTNAME=""

TOKEN_API_AUTH=""
API_PORT=":8080"
```

3. Una vez especificada nuestra conexión a la base de datos externa.
En nuestro directorio raiz ```/db/mysq.sql``` se encuentra el archivo que importaremos en nuestro servicio mysql.
Al termniar la importación podemos continuar con docker.

```docker
docker-compose build
docker-compose up -d
```

4. 👍 Todo listo! La esta en marcha.



## Primeras pruebas
Lancemos algunas solicitudes a la api para comprobar su correcto funcionamiento. Vamos logearnos con un usuario administrador.

```sh
curl -X POST http://localhost:8080/login -H 'Content-Type: application/json' -d '{"email":"[email protected]", "password":"123456"}'
```

Con el token de la respuesta. Nos dirigimos a https://jwt.io y pegamos nuestro token.

```json
{
"user": {
"id": 1,
"name": "Administrador",
"email": "[email protected]"
},
"roles": [
"admin"
],
"exp": 1653711999
}
```

Ingresamos una cuenta de conductor:
```bash
curl -X POST http://localhost:8080/login -H 'Content-Type: application/json' -d '{"email":"[email protected]", "password":"123456"}'
```

```json
{
"user": {
"id": 102,
"name": "Conductor test",
"email": "[email protected]"
},
"roles": [
"conductor"
],
"exp": 1653712180
}
```

2. Obtener los conductores - utilizando paginación

```sh
curl -X GET http://localhost:8080/conductores -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoxLCJuYW1lIjoiQWRtaW5pc3RyYWRvciIsImVtYWlsIjoiYWRtaW5Ac3BhY2VndXJ1LmNvbSJ9LCJyb2xlcyI6WyJhZG1pbiJdLCJleHAiOjE2NTM2OTYzMzJ9.TKWpE2ut1HfKFlsjmi7jvpWRd_jwJepcW_lAwOeVp00' -d '{"page":5}'
```

```json
{
"conductores": [
{
"id": 11,
"users_id": 31,
"name": "Mrs. Clarissa McDermott",
"email": "[email protected]",
"matricula": "472",
"vehiculo": "Prof. Emely Goodwin",
"created_at": "2022-05-25 17:11:13",
"updated_at": "2022-05-25 17:11:13"
},
{
"id": 12,
"users_id": 37,
"name": "Miss Zita Emard",
"email": "[email protected]",
"matricula": "1502",
"vehiculo": "Miss Dasia Nienow",
"created_at": "2022-05-25 17:11:13",
"updated_at": "2022-05-25 17:11:13"
},
{
"id": 13,
"users_id": 45,
"name": "Queen Juana Schroeder",
"email": "[email protected]",
"matricula": "171",
"vehiculo": "Queen Mikayla Walker",
"created_at": "2022-05-25 17:11:13",
"updated_at": "2022-05-25 17:11:13"
},
{
"id": 14,
"users_id": 39,
"name": "Princess Kenyatta Mertz",
"email": "[email protected]",
"matricula": "1719",
"vehiculo": "Queen Jeanne Jacobs",
"created_at": "2022-05-25 17:11:13",
"updated_at": "2022-05-25 17:11:13"
},
{
"id": 15,
"users_id": 34,
"name": "Princess Hortense Gleason",
"email": "[email protected]",
"matricula": "1371",
"vehiculo": "Lady Callie Labadie",
"created_at": "2022-05-25 17:11:13",
"updated_at": "2022-05-25 17:11:13"
}
],
"status": "Success"
}
```

3. Obtener los conductores que no esta realizando viajes

```sh
curl -X GET http://localhost:8080/conductoresdisponibles -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoxLCJuYW1lIjoiQWRtaW5pc3RyYWRvciIsImVtYWlsIjoiYWRtaW5Ac3BhY2VndXJ1LmNvbSJ9LCJyb2xlcyI6WyJhZG1pbiJdLCJleHAiOjE2NTM2OTYzMzJ9.TKWpE2ut1HfKFlsjmi7jvpWRd_jwJepcW_lAwOeVp00'
```

Respuesta:

```json
{
"conductores": [
{
"id": 2,
"users_id": 69,
"name": "Ms. Kimberly Monahan",
"email": "[email protected]",
"matricula": "1674",
"vehiculo": "Dr. Sunny Runolfsdottir",
"created_at": "2022-05-25 17:11:13",
"updated_at": "2022-05-25 17:11:13"
},
{
"id": 3,
"users_id": 57,
"name": "Ms. Libby O\"Keefe",
"email": "[email protected]",
"matricula": "622",
"vehiculo": "Dr. Madalyn Roberts",
"created_at": "2022-05-25 17:11:13",
"updated_at": "2022-05-25 17:11:13"
},
{
"id": 4,
"users_id": 47,
"name": "Miss Leilani Towne",
"email": "[email protected]",
"matricula": "359",
"vehiculo": "Dr. Jaunita Cronin",
"created_at": "2022-05-25 17:11:13",
"updated_at": "2022-05-25 17:11:13"
},
],
"message": "Conductores disponibles que no están realizando viajes",
"status": "Success"
}
```