From 2b8a9fab2d2b1fe72449b6289c79a057ab72a921 Mon Sep 17 00:00:00 2001 From: jtmst Date: Fri, 13 Dec 2024 12:55:25 -0500 Subject: [PATCH] cleanup, export ep --- bloom_nofos/nofos/api/api.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/bloom_nofos/nofos/api/api.py b/bloom_nofos/nofos/api/api.py index cd5fb449..bf626383 100644 --- a/bloom_nofos/nofos/api/api.py +++ b/bloom_nofos/nofos/api/api.py @@ -1,10 +1,9 @@ from ninja import NinjaAPI, Schema from ninja.security import HttpBearer -from ninja.errors import HttpError from django.core.exceptions import ValidationError from .schemas import NofoSchema, ErrorSchema, SuccessSchema from nofos.models import Nofo -from nofos.views import _build_nofo # reusing the existing build function +from nofos.views import _build_nofo class BearerAuth(HttpBearer): @@ -18,19 +17,10 @@ def authenticate(self, request, token): api = NinjaAPI( auth=BearerAuth(), urls_namespace="api", - docs_url="/docs", # API documentation at /api/docs + docs_url="/docs", ) -class TestSchema(Schema): - message: str - - -@api.post("/test") -def test_post(request, data: TestSchema): - return {"received": data.message} - - @api.post("/nofo/import", response={201: SuccessSchema, 400: ErrorSchema}) def import_nofo(request, payload: NofoSchema): try: @@ -51,3 +41,13 @@ def import_nofo(request, payload: NofoSchema): return 400, {"message": "Validation error", "details": e.message_dict} except Exception as e: return 400, {"message": str(e)} + + +@api.get("/nofo/{nofo_id}", response={200: NofoSchema, 404: ErrorSchema}) +def export_nofo(request, nofo_id: int): + """Export a NOFO by ID""" + try: + nofo = Nofo.objects.get(id=nofo_id) + return 200, nofo + except Nofo.DoesNotExist: + return 404, {"message": "NOFO not found"}