Git Product home page Git Product logo

go-car-rental-api's Introduction

Car Rental API in GO

Basic api for car rentals to study Golang

Requirements

Instructions

  1. Clone the project
  2. Run the command mv .env.example .env to rename the .env.example file to .env
  3. Fill in with the environment variables in the .env file
  4. Run the database migrations with the command go run database/migrate.go
  5. Run the server with the command go run main.go

Environment Variables

  • 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

Routes

All application routes

Brands

  • GET /brands used to get the list of all brands
  • POST /brands used to create a new brand
    Data (json):
    • Name [string, required]
  • GET /brands/:id used to get a brand by id
  • PUT /brands/:id used to update a brand by id
    Data (json):
    • Name [string, required]
  • DELETE /brands/:id used to delete a brand by id

Cars

  • GET /cars used to get the list of all cars
  • POST /cars used to create a new car
    Data (json):
    • BrandId [uuid, required]
    • Model [string, required]
    • RentalPriceDailyInUsd [float, required]
    • HorsePower [int, required]
    • TorqueInLb [float, required]
    • TopSpeedInKm [int, required]
    • AccelerationSpeedInKm [float, required]
    • WeightInKg [int, required]
  • GET /cars/:id used to get a car by id
  • PUT /cars/:id used to update a car by id
    Data (json):
    • BrandId [uuid, required]
    • Model [string, required]
    • RentalPriceDailyInUsd [float, required]
    • HorsePower [int, required]
    • TorqueInLb [float, required]
    • TopSpeedInKm [int, required]
    • AccelerationSpeedInKm [float, required]
    • WeightInKg [int, required]
  • DELETE /cars/:id used to delete a car by id

Auth

  • POST /auth/register used to register new user
    Data (json):
    • Name [string, required]
    • Email [string, required]
    • Password [string, required]
  • POST /auth/login used to login
    Data (json):
    • Email [string, required]
    • Password [string, required]
  • 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]
    Filters (query params):
    • 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]

Rentals

  • GET /rentals used to get the list of all rentals
    Filters (query params):
    • 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]
  • POST /rentals used to rent a car [requires auth]
    Data (json)
    • 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]
  • PATCH /rentals/:id/cancel used to cancel a rental [requires auth]

Insomnia import file

How to Authenticate

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

Tech Stack

go-car-rental-api's People

Contributors

wfl-junior avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.