Skip to content

Commit

Permalink
Merge pull request #2 from OlegatorLE/develop
Browse files Browse the repository at this point in the history
PR with added postgres and security
  • Loading branch information
OlegatorLE authored Nov 3, 2023
2 parents dae4f86 + be61efe commit 13717ae
Show file tree
Hide file tree
Showing 38 changed files with 1,887 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SECRET_KEY=SECRET_KEY
POSTGRES_HOST=POSTGRES_HOST
POSTGRES_DB=POSTGRES_DB
POSTGRES_USER=POSTGRES_USER
POSTGRES_PASSWORD=POSTGRES_PASSWORD
86 changes: 85 additions & 1 deletion Readme.MD
Original file line number Diff line number Diff line change
@@ -1 +1,85 @@
"# airport-api-service"
# Airport API Service

Django Rest Framework project for managing Airport Service.
The project implements management of flights, planes, and crews. And the ability to create orders has also been implemented.

## Install via GitHub

Python3 & Postgres must be already installed
```shell
git clone https://github.com/OlegatorLE/airport-api-service.git
cd airport-api-service
python -m venv venv
source venv/bin/activate # or venv\Scripts\activate in Windows
pip install -r requirements.txt
create .env file by .env.sample
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
```

## JWT endpoints:
- create user:
- api/user/register
- get access token:
- api/user/token
- verify access token:
- api/user/token/verify
- refresh token:
- api/user/token/refresh
- manage user:
- api/user/me

## Features

- Different accesses to APIRoot endpoint for anonymous and authorized users
- Admin panel /admin/
- Documentation at /api/doc/swagger
- Creating orders by auth users
- Creating airports by admins
- Creating airplanes with some type by admins
- Creating routes from source to destination by admins
- Adding flights with some routes and airplanes by admins
- Filtering airports by name, city or country
- Pagination airports and orders

## DB Schema

![db.png](https://github.com/OlegatorLE/airport-api-service/blob/develop/demo_images/db.png)

## Demo
### Anonymous user APIRoot endpoint:

![anonym_api_root.png](https://github.com/OlegatorLE/airport-api-service/blob/develop/demo_images/anonym_api_root.png)

### Auth user APIRoot endpoint:

![auth_api_root.png](https://github.com/OlegatorLE/airport-api-service/blob/develop/demo_images/auth_api_root.png)

### Admin Airport-list endpoint:

![airport-list.png](https://github.com/OlegatorLE/airport-api-service/blob/develop/demo_images/airport-list.png)

### User Airport-detail endpoint:

![airport-detial.png](https://github.com/OlegatorLE/airport-api-service/blob/develop/demo_images/airport-detial.png)

### User Flight-list endpoint:

![flight-list.png](https://github.com/OlegatorLE/airport-api-service/blob/develop/demo_images/flight-list.png)

### User Flight-detail endpoint:

![flight-detail.png](https://github.com/OlegatorLE/airport-api-service/blob/develop/demo_images/flight-detail.png)

### Order-list endpoint:

![order-list.png](https://github.com/OlegatorLE/airport-api-service/blob/develop/demo_images/order-list.png)

### Order-detail endpoint:

![order-detail.png](https://github.com/OlegatorLE/airport-api-service/blob/develop/demo_images/order-detail.png)

### Admin page:

![admin-page.png](https://github.com/OlegatorLE/airport-api-service/blob/develop/demo_images/admin-page.png)
Empty file added airport/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions airport/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.contrib import admin

from airport.models import (
Airport,
Route,
AirplaneType,
Airplane,
Crew,
Flight,
Order,
Ticket,
)

class TicketInLine(admin.TabularInline):
model = Ticket
extra = 1


@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
inlines = (TicketInLine,)


admin.site.register(Airport)
admin.site.register(Route)
admin.site.register(AirplaneType)
admin.site.register(Airplane)
admin.site.register(Crew)
admin.site.register(Flight)
6 changes: 6 additions & 0 deletions airport/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AirportConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "airport"
170 changes: 170 additions & 0 deletions airport/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# Generated by Django 4.2.6 on 2023-10-19 11:15

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="Airplane",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
("rows", models.IntegerField()),
("seats_in_row", models.IntegerField()),
],
),
migrations.CreateModel(
name="AirplaneType",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name="Airport",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
("closest_big_city", models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name="Crew",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("first_name", models.CharField(max_length=255)),
("last_name", models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name="Flight",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("departure_time", models.DateTimeField()),
("arrival_time", models.DateTimeField()),
],
),
migrations.CreateModel(
name="Order",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
],
options={
"ordering": ["-created_at"],
},
),
migrations.CreateModel(
name="Ticket",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("row", models.IntegerField()),
("seat", models.IntegerField()),
(
"flight",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="airport.flight"
),
),
(
"order",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="airport.order"
),
),
],
),
migrations.CreateModel(
name="Route",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("distance", models.IntegerField()),
(
"destination",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="arrival_routes",
to="airport.airport",
),
),
(
"source",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="departure_routes",
to="airport.airport",
),
),
],
),
]
50 changes: 50 additions & 0 deletions airport/migrations/0002_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Generated by Django 4.2.6 on 2023-10-19 11:15

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("airport", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="order",
name="user",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
),
),
migrations.AddField(
model_name="flight",
name="airplane",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="airport.airplane"
),
),
migrations.AddField(
model_name="flight",
name="crew",
field=models.ManyToManyField(to="airport.crew"),
),
migrations.AddField(
model_name="flight",
name="route",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="airport.route"
),
),
migrations.AddField(
model_name="airplane",
name="airplane_type",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="airport.airplanetype"
),
),
]
31 changes: 31 additions & 0 deletions airport/migrations/0003_alter_ticket_flight_alter_ticket_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.2.6 on 2023-10-19 18:57

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
("airport", "0002_initial"),
]

operations = [
migrations.AlterField(
model_name="ticket",
name="flight",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="tickets",
to="airport.flight",
),
),
migrations.AlterField(
model_name="ticket",
name="order",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="tickets",
to="airport.order",
),
),
]
Loading

0 comments on commit 13717ae

Please sign in to comment.