Skip to content

Latest commit

 

History

43 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Airport API

A REST API for an airport service: airports, routes, airplanes, flights, crews and ticket orders. Built with Django and Django REST Framework.

The code lives on the develop branch.

Stack

Python · Django 5 · Django REST Framework · SimpleJWT · drf-spectacular · SQLite

Data model

Model Notes
Airport name + closest big city, unique together
Route source → destination airports and distance; rejects a route to itself
AirplaneType, Airplane seat count is derived: rows × seats_in_rows
Crew unique by first + last name
Flight route, airplane, departure/arrival times, crew; rejects an arrival at or before departure
Order, Ticket a ticket is unique per (row, seat, flight) and is checked against the airplane's real seat layout

Validation sits in the models rather than in the serializers: Route and Flight call full_clean() inside save(), so the rules hold whichever entry point writes the row — API, admin or shell.

API

Seven resources are registered on a DRF DefaultRouter under /api/:

crews/ · airports/ · routes/ · airplane-types/ · airplanes/ · flights/ · orders/

  • Separate serializers per action — list, create and retrieve each get their own, so a list response stays cheap and a detail response stays informative.
  • Filtering by query parameters: ?full_name=, ?name=, ?from=&to=, and date/route filters on flights.
  • Pagination — page number, 10 per page, ?page_size= up to 1000.
  • select_related on routes, so the list view does not walk into an N+1 query.
  • Throttling — 100 requests/day anonymous, 1000/day authenticated.
  • PermissionsIsAdminOrIfAuthenticatedReadOnly: authenticated users read, staff writes.

Authentication

JWT (djangorestframework-simplejwt) over a custom user model keyed on email instead of username.

Endpoint Purpose
POST /api/user/create/ register
POST /api/user/token/ obtain an access + refresh pair
POST /api/user/token/refresh/ refresh the access token
POST /api/user/token/verify/ verify a token
GET, PATCH /api/user/me/ read or update your own profile

Send the access token as Authorization: Bearer <token>.

Running locally

git clone -b develop https://github.com/Zonda001/AirportAPI.git
cd AirportAPI

python -m venv venv
source venv/bin/activate          # Windows: venv\Scripts\activate
pip install -r requirements.txt

cp .env.sample .env               # then put a real SECRET_KEY in it
python manage.py migrate
python manage.py createsuperuser  # create your own admin account
python manage.py runserver

What is not in here

Written as a study project in early 2024 and kept as it was, so that the repository says what it is:

  • no test suite
  • no Docker or deployment config
  • drf-spectacular is installed and the views carry @extend_schema annotations, but no schema endpoint is wired into the URLconf yet
  • the database is SQLite; psycopg2 sits in requirements.txt unused

About

Django REST API for an airport service: models with validation in save(), per-action serializers, ViewSets with filtering, pagination and throttling, JWT auth on a custom user model (code on the develop branch)

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages