Implement API

This commit is contained in:
zandercymatics 2023-11-20 16:20:37 -07:00
parent 67f9de03d4
commit e52954f984
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 35 additions and 0 deletions

32
src/api/report_views.py Normal file
View file

@ -0,0 +1,32 @@
"""Internal API views"""
from django.apps import apps
from django.views.decorators.http import require_http_methods
from django.http import FileResponse, JsonResponse
import requests
from registrar.utility import csv_export
from login_required import login_not_required
@require_http_methods(["GET"])
@login_not_required
def get_current_full(request):
# Generate the CSV file
with open("current-full.csv", "w") as file:
csv_export.export_data_full_to_csv(file)
# Serve the CSV file
response = FileResponse(open('current-full.csv', 'rb'))
return response
@require_http_methods(["GET"])
@login_not_required
def get_current_federal(request):
# Generate the CSV file
with open("current-federal.csv", "w") as file:
csv_export.export_data_federal_to_csv(file)
# Serve the CSV file
response = FileResponse(open('current-federal.csv', 'rb'))
return response

View file

@ -12,6 +12,7 @@ from registrar import views
from registrar.views.application import Step
from registrar.views.utility import always_404
from api.views import available
from api.report_views import get_current_federal, get_current_full
APPLICATION_NAMESPACE = views.ApplicationWizard.URL_NAMESPACE
application_urls = [
@ -73,6 +74,8 @@ urlpatterns = [
path("openid/", include("djangooidc.urls")),
path("register/", include((application_urls, APPLICATION_NAMESPACE))),
path("api/v1/available/<domain>", available, name="available"),
path("api/v1/get-report/current-federal", get_current_federal, name="get-current-federal"),
path("api/v1/get-report/current-full", get_current_full, name="get-current-full"),
path(
"todo",
lambda r: always_404(r, "We forgot to include this link, sorry."),