Simon-157 / fleet-api

fleet management with seamless API integration. Empowering efficient aircraft and flight data management

Home Page:https://fleet-api-awdj.onrender.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fleet API

Welcome to the Fleet API project! This API serves as the backend for managing fleet-related operations.

Table of Contents

Introduction

This API provides functionalities for managing flights, aircraft, and reports within a fleet management system.

Databse Setup

NB: No need if you want to use the deployed api [https://fleet-api-awdj.onrender.com/].

To run the Fleet API locally, you will need to set up a database.

To set up the database locally, follow these steps:

  1. Ensure you have PostgreSQL installed on your machine. If not, download and install it from PostgreSQL Downloads.

  2. Create a new PostgreSQL database using the following command:

    createdb -U postgres dbname
    
  3. Navigate to the project directory:

    cd fleet_api/db
  4. Modify the sql connection string in the migration code (main.go) to match your PostgreSQL credentials "user=username password=password dbname=fleet sslmode=disable"

  5. Run the database migrations while in the db dir:

    go run main.go
  6. The locat config file and change the db credentials as needed

Installation

To install and run the Fleet API locally, follow these steps:

  1. Clone this repository:

    git clone https://github.com/Simon-157/fleet-api.git
  2. Navigate to the project directory:

    cd fleet_api
  3. Install dependencies:

    go mod tidy
  4. Build the application:

    go build -o fleet-api cmd/fleet-api/main.go
  5. Run the application:

    ./fleet-api

Usage

Once the application is running, you can access the API endpoints using a tool like Postman or by making HTTP requests from your application.

For detailed API documentation, refer to the API Endpoints section below.

Docker

Alternatively, you can run the Fleet API using Docker. Follow these steps:

  1. Build the Docker image:

    docker build -t fleet-api .
  2. Run the Docker container:

    docker run -p 5000:5000 fleet-api

API Endpoints

For quick testing of the API, you can use the following endpoints with the deployed base URL of https://fleet-api-awdj.onrender.com/.

Endpoint Method Description Query Params Required Body Content
/api/flight GET Retrieve all flights N/A N/A
/api/flight/{id} GET Retrieve flight by ID N/A N/A
/api/flight POST Create a new flight (provide the an id as search params when creating with an assigned aircraft) N/A Flight data
/api/flight/{id} PUT Update flight details by ID N/A Updated flight data
/api/flight/{id} DELETE Delete flight by ID N/A N/A
/api/flight/search GET search by departure_airport,arrival_airport departure_airport,arrival_airport N/A
/api/aircraft GET Retrieve all aircrafts N/A N/A
/api/aircraft/{id} GET Retrieve aircraft by ID N/A N/A
/api/aircraft POST Create a new aircraft N/A Aircraft data
/api/aircraft/{id} PUT Update aircraft details by ID N/A Updated aircraft data
/api/aircraft/{id} DELETE Delete aircraft by ID N/A N/A
/api/report/departure_airport GET Retrieve all start_time and end_time N/A

Sample Testing with Postman

can replace localhost with the base url https://fleet-api-awdj.onrender.com/.

API Endpoints

Aircraft Endpoints:

Create Aircraft:

Create Flight with Aircraft ID:

  • Method: POST
  • URL: http://localhost:8080/api/flight
  • Body: JSON
    {
        "departure_airport": "LHR",
        "arrival_airport": "ICN",
        "departure_datetime": "2024-05-24T08:00:00Z",
        "arrival_datetime": "2024-05-24T15:00:00Z",
        "aircraft_id": 2
    }

Create Flight without Aircraft ID:

  • Method: POST
  • URL: http://localhost:8080/api/flight
  • Body: JSON
    {
        "departure_airport": "IST",
        "arrival_airport": "NRT",
        "departure_datetime": "2024-05-26T08:00:00Z",
        "arrival_datetime": "2024-05-26T18:00:00Z"
    }

Search Flights Route:

Reports Route:

Contributing

Contributions to the Fleet API project are welcome! To contribute, please follow these steps:

  1. Fork the repository
  2. Create a new branch (git checkout -b feature/your-feature)
  3. Make your changes
  4. Commit your changes (git commit -am 'Add new feature')
  5. Push to the branch (git push origin feature/your-feature)
  6. Create a new pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

fleet management with seamless API integration. Empowering efficient aircraft and flight data management

https://fleet-api-awdj.onrender.com/


Languages

Language:Go 99.0%Language:Dockerfile 1.0%