Running the application (source code)
Running the application (Docker)
🇬🇧 This repository contains a Web API project built with .NET 7 with the goal of implementing functionalities for a motorcycles rental app, including logins with secure password storage, JWT Bearer authentication, registration, rental and return of motorcycles.
🇧🇷 Este repositório contém um projeto Web API construído em .NET 7 com o objetivo de implementar funcionalidades de um aplicativo de aluguel de motocicletas, incluindo logins com armazenamento seguro de senhas, autenticação JWT Bearer, cadastro, aluguel e devolução de motocicletas.
To run the application, you must have these tools installed:
Or
Download or clone the project from: https://github.com/MatheusMGrassano/RentalWebAPI.git
Make sure to change the database connection credentials in the appsettings.json file to match your setting.
At your terminal, access the project folder Rental_WebApi and type the following command:
dotnet watch runA new browser tab will open with the Swagger UI showing all the endpoints available.
Create a docker-compose.yml file with following code inside
version: '3.8' services: rental-api: image: matheusgrassano/rental-api:latest ports: - "5000:80" depends_on: - postgres postgres: image: postgres:15.5-bullseye restart: always environment: POSTGRES_USER: root POSTGRES_PASSWORD: root POSTGRES_DB: RentalDb ports: - "5432:5432" volumes: - pgdata:/var/lib/postgresql/data volumes: pgdata:Warning: if you make changes to the docker-compose.yml don't forget to apply those changes to the app connection string at appsettings.json
At your terminal, go to the folder where the docker-compose.yml is and run the following command:
docker compose up -dNow, both containers (rental-api and postgres) should be running
On your browser, go to localhost:5000/swagger/index.html and the Swagger UI should appear with all the endpoints available.
In order to test all endpoints, first you must create a user (whether Admin/create or Driver/create). After creating the user, use the login endpoint to generate your access token.
Enter the new token in the JWT Authorization header using the Bearer scheme. Enter 'Bearer' [space] and then your token in the header.
Example: "Bearer 12345abcdef"
Now, you are able to access all endpoints using the access token.
| Method | Route | JSON Body | Action |
|---|---|---|---|
| POST | /api/Admin/login | email + password | Generate an access token |
| POST | /api/Admin/create | email + password | Create an admin user |
| PUT | /api/Admin/passwordupdate | email + password + newPassword | Update an admin's password |
| DELETE | /api/Admin/delete | email + password | Remove an admin user |
| Method | Route | JSON Body | Action |
|---|---|---|---|
| POST | /api/Driver/login | email + password | Generate a access token |
| POST | /api/Driver/create | email + password + driver's info | Create a driver user |
| POST | /api/Driver/rent | email + password + rentDays | Rents an available motorcycle |
| POST | /api/Driver/return | email + password + plate + endDate | Return a rented motorcycle |
| Method | Route | JSON Body | Action |
|---|---|---|---|
| GET | /api/Motorcycle?offset=5&limit=5 | Get the motorcycles list | |
| GET | /api/Motorcycle/id/{id} | Get a motorcycle by id | |
| GET | /api/Motorcycle/plate/{plate} | Get a motorcycle by plate | |
| POST | /api/Motorcycle/create | manufactureYear + model + plate | Register a motorcycle |
| PUT | /api/Motorcycle/update | id + newPlate | Update a motorcycle's plate |
| DELETE | /api/Motorcycle/delete/{id} | Remove a motorcycle |
{ "email": "string", "password": "string" }{ "data": { "id": 0, "manufactureYear": 0, "model": "string", "plate": "string", "available": true }, "statusCode": 100, "message": "string" }