Aircraft Passenger Capacity Consumption API
The following environment variables are required to run the app.
- DEV_SECRET_KEY
- DATABASE_URL
-
Clone the repo.
git clone git@github.com:sitati-elsis/airplanes.git
-
cd
into the repo you have just cloned.cd airplanes/
-
Create a virtual environment and activate it.
-
Inside the virtual environment, install app dependencies.
pip install -r requirements.txt
-
Run Migrations
python manage.py migrate
-
Start the app.
python manage.py runserver
- To create a plane, use the POST method on
/api/planes/
endpoint and supply theid
andpassenger
field values in the request body.curl -X POST http://localhost:8000/api/planes/ -H "Content-Type: application/json" -d '{"id": 1234, "passengers": 5678}' # response {"id":1234,"passengers":5678}
- To view
total_airplane_fuel_consumption_per_minute
andmaximum_minutes_able_to_fly
information, send a GET request on/api/planes/
endpoint.curl -X GET http://localhost:8000/api/planes/ # response { "total_airplane_fuel_consumption_per_minute":13.829052127757778, "maximum_minutes_able_to_fly":17846.487070839885, "planes":[ { "id":1234, "litres":200, "passengers":5678, "fuel_tank_capacity":246800, "plane_fuel_comsumption":2.4730521277577786, "passenger_consumption":11.356, "total_fuel_consumption":13.829052127757778 } ] }
Interactive API documentation can be accessed through http://localhost:8000/api/docs/.
mypy
can be run to perform static checks on the code. To perform this check, run the following command;
mypy -p api
Tests can be run using the following command.
coverage run manage.py test
To view the coverage report, use the command below.
coverage report -m
Positive*
integer model fields have been used based on the assumption thatid
andpassenger
fields should not have negative values.PositiveSmallIntegerField
has been used forid
andpassenger
fields instead ofPositiveIntegerField
as might be expected.PositiveSmallIntegerField
will save at least 50% more database space thanPositiveIntegerField
while still satisfying requirements. This is based on the following assumptions;