Welcome to the Fleet API project! This API serves as the backend for managing fleet-related operations.
This API provides functionalities for managing flights, aircraft, and reports within a fleet management system.
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:
-
Ensure you have PostgreSQL installed on your machine. If not, download and install it from PostgreSQL Downloads.
-
Create a new PostgreSQL database using the following command:
createdb -U postgres dbname
-
Navigate to the project directory:
cd fleet_api/db
-
Modify the sql connection string in the migration code (main.go) to match your PostgreSQL credentials "user=username password=password dbname=fleet sslmode=disable"
-
Run the database migrations while in the db dir:
go run main.go
-
The locat config file and change the db credentials as needed
To install and run the Fleet API locally, follow these steps:
-
Clone this repository:
git clone https://github.com/Simon-157/fleet-api.git
-
Navigate to the project directory:
cd fleet_api
-
Install dependencies:
go mod tidy
-
Build the application:
go build -o fleet-api cmd/fleet-api/main.go
-
Run the application:
./fleet-api
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.
Alternatively, you can run the Fleet API using Docker. Follow these steps:
-
Build the Docker image:
docker build -t fleet-api .
-
Run the Docker container:
docker run -p 5000:5000 fleet-api
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 |
can replace localhost with the base url https://fleet-api-awdj.onrender.com/
.
- Method: POST
- URL: http://localhost:8080/api/aircraft
- Body: JSON
{ "serial_number": "JKL013", "manufacturer": "Embraer" }
- 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 }
- 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" }
- Method: GET
- URL: http://localhost:8080/api/flight/search
- Params:
departure_airport
: Departure airport code (e.g., LHR)arrival_airport
: Arrival airport code (e.g., JFK)
- Example: Searching for flights from London Heathrow Airport (LHR) to John F. Kennedy International Airport (JFK): URL: http://localhost:8080/api/flight/search?departure_airport=LHR&arrival_airport=JFK
- Method: GET
- URL: http://localhost:8080/api/report/departure_airports
- Params:
start_time
: Start time for the search range (e.g., 2024-05-01T00:00:00Z)end_time
: End time for the search range (e.g., 2024-05-31T23:59:59Z)
- Example: Get departure airports with in-flight aircraft for the month of May 2024: URL: http://localhost:8080/api/report/departure_airports?start_time=2024-05-01T00:00:00Z&end_time=2024-05-31T23:59:59Z
Contributions to the Fleet API project are welcome! To contribute, please follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature/your-feature
) - Make your changes
- Commit your changes (
git commit -am 'Add new feature'
) - Push to the branch (
git push origin feature/your-feature
) - Create a new pull request
This project is licensed under the MIT License - see the LICENSE file for details.