Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
Merge branch 'TMU-API'
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeRomaa committed Nov 18, 2020
2 parents 1877c4c + f27b329 commit 1f069c8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ NO_REPLY = "[email protected]"

ULS_K_VALUE = "vatusa_uls_jwk_k_value"
API_KEY = "vatusa_api_key"
IDS_API_KEY = "api_key_for_ids_app"

LOGGING_WEBHOOK_URL = "https://discordapp.com/api/webhooks/channel/token"
TRAINING_WEBHOOK_URL = "https://discordapp.com/api/webhooks/channel/token"
Expand Down
7 changes: 6 additions & 1 deletion apps/api/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib import admin
from .models import Controller, ControllerSession, CurrentAtis
from .models import Controller, ControllerSession, CurrentAtis, TMUNotice


@admin.register(Controller)
Expand All @@ -15,3 +15,8 @@ class ControllerSessionAdmin(admin.ModelAdmin):
@admin.register(CurrentAtis)
class CurrentAtisAdmin(admin.ModelAdmin):
list_display = ('facility', 'atis_letter', 'config_profile', 'updated')


@admin.register(TMUNotice)
class TMUNoticeAdmin(admin.ModelAdmin):
list_display = ('id', 'time_issued', 'time_expires')
6 changes: 6 additions & 0 deletions apps/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ class CurrentAtis(models.Model):
airport_conditions = models.TextField()
notams = models.TextField()
updated = models.DateTimeField(auto_now=True)


class TMUNotice(models.Model):
info = models.TextField()
time_issued = models.DateTimeField(auto_now_add=True)
time_expires = models.DateTimeField()
32 changes: 30 additions & 2 deletions apps/api/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import calendar
import json
import os
from datetime import timedelta

from django.db.models import Sum, Q
Expand All @@ -8,9 +9,9 @@
from django.shortcuts import render
from django.utils import timezone
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from django.views.decorators.http import require_POST, require_GET

from .models import ControllerSession, CurrentAtis
from .models import ControllerSession, CurrentAtis, TMUNotice
from ..user.models import User


Expand Down Expand Up @@ -106,9 +107,36 @@ def update_atis(request):
return HttpResponse(status=200)


@require_GET
def get_atis(request, icao):
atis = CurrentAtis.objects.filter(facility=icao.upper()).first()
if atis:
return JsonResponse(model_to_dict(atis))
else:
return HttpResponse(f'ATIS for facility {icao.upper()} was not found.', status=404)


@require_POST
def post_tmu(request):
if request.POST.get('api_key') == os.getenv('IDS_API_KEY'):
notice = TMUNotice(
info=request.POST.get('info'),
time_issued=request.POST.get('time_issued'),
)
notice.save()
return HttpResponse(JsonResponse(model_to_dict(notice)))
else:
return HttpResponse('Invalid API key.', status=401)


@require_POST
def delete_tmu(request, notice_id):
if request.POST.get('api_key') == os.getenv('IDS_API_KEY'):
notice = TMUNotice.objects.filter(id=notice_id).first()
if notice:
notice.delete()
return HttpResponse(status=200)
else:
return HttpResponse(f'TMU notice with id {notice_id} was not found.', status=404)
else:
return HttpResponse('Invalid API key.', status=401)
2 changes: 2 additions & 0 deletions zhuartcc/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
path('statistics/', api.view_statistics, name='statistics'),
path('api/vatis/', api.update_atis, name='update_atis'),
path('api/vatis/<str:icao>/', api.get_atis, name='get_atis'),
path('api/tmu/', api.post_tmu, name='post_tmu'),
path('api/tmu/<int:notice_id>/delete/', api.delete_tmu, name='delete_tmu'),

# Event
path('events/', event.view_all_events, name='events'),
Expand Down

0 comments on commit 1f069c8

Please sign in to comment.