Basic api for car rentals to study Golang
- The Go programming language
- A PostgreSQL database
- Clone the project
- Run the command
mv .env.example .env
to rename the.env.example
file to.env
- Fill in with the environment variables in the
.env
file - Run the database migrations with the command
go run database/migrate.go
- Run the server with the command
go run main.go
- PORT: The port you want the server to run in. Example:
4000
(defaults to 8080) - DSN: A string with the information to connect to the database. Example:
"user=gorm password=gorm dbname=gorm port=9920 sslmode=disable"
- JWT_SECRET: A secret string to use to hash the jwt. Example:
uidgqw78dgqw78giodcqwuih
All application routes
GET /brands
used to get the list of all brandsPOST /brands
used to create a new brand- Name
[string, required]
- Name
GET /brands/:id
used to get a brand by idPUT /brands/:id
used to update a brand by id- Name
[string, required]
- Name
DELETE /brands/:id
used to delete a brand by id
GET /cars
used to get the list of all carsPOST /cars
used to create a new car- BrandId
[uuid, required]
- Model
[string, required]
- RentalPriceDailyInUsd
[float, required]
- HorsePower
[int, required]
- TorqueInLb
[float, required]
- TopSpeedInKm
[int, required]
- AccelerationSpeedInKm
[float, required]
- WeightInKg
[int, required]
- BrandId
GET /cars/:id
used to get a car by idPUT /cars/:id
used to update a car by id- BrandId
[uuid, required]
- Model
[string, required]
- RentalPriceDailyInUsd
[float, required]
- HorsePower
[int, required]
- TorqueInLb
[float, required]
- TopSpeedInKm
[int, required]
- AccelerationSpeedInKm
[float, required]
- WeightInKg
[int, required]
- BrandId
DELETE /cars/:id
used to delete a car by id
POST /auth/register
used to register new user- Name
[string, required]
- Email
[string, required]
- Password
[string, required]
- Name
POST /auth/login
used to login- Email
[string, required]
- Password
[string, required]
- Email
GET /auth/me
used to get logged in user data[requires auth]
GET /auth/me/rentals
used to get logged in user rentals[requires auth]
- CarId - if specified it will return only the rentals for this CarId
[optional]
- StartsAt - if specified it will return only the rentals that have a StartsAt greater than or equal to the specified date
[optional]
- EndsAt - if specified it will return only the rentals that have an EndsAt lesser than or equal to the specified date
[optional]
- CarId - if specified it will return only the rentals for this CarId
GET /rentals
used to get the list of all rentals- CarId - if specified it will return only the rentals for this CarId
[optional]
- StartsAt - if specified it will return only the rentals that have a StartsAt greater than or equal to the specified date
[optional]
- EndsAt - if specified it will return only the rentals that have an EndsAt lesser than or equal to the specified date
[optional]
- CarId - if specified it will return only the rentals for this CarId
POST /rentals
used to rent a car[requires auth]
- CarId - The id of the car you want to rent
[required]
- StartsAt - The start date for which you want to rent the car
[required]
- EndsAt - The end date for which you want to rent the car
[required]
- CarId - The id of the car you want to rent
PATCH /rentals/:id/cancel
used to cancel a rental[requires auth]
The /auth/register
and the /auth/login
endpoints return an accessToken
, send it as a Bearer token in the request, as the Authorization header, for example: Bearer accessToken_here