From c051f3adec58752d66969311cdfea164879bc4b6 Mon Sep 17 00:00:00 2001 From: jtmst Date: Wed, 18 Dec 2024 12:01:16 -0500 Subject: [PATCH] update response object --- bloom_nofos/nofos/api/api.py | 9 ++++----- bloom_nofos/nofos/api/schemas.py | 2 -- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/bloom_nofos/nofos/api/api.py b/bloom_nofos/nofos/api/api.py index 35b7ba0..d04841c 100644 --- a/bloom_nofos/nofos/api/api.py +++ b/bloom_nofos/nofos/api/api.py @@ -41,11 +41,10 @@ def create_nofo(request, payload: NofoSchema): _build_nofo(nofo, sections) nofo.save() - return 201, { - "message": f"NOFO {nofo.id} imported successfully", - "Location": f"/api/nofos/{nofo.id}", - "nofo": nofo, - } + serialized_nofo = NofoSchema.from_orm(nofo) + return_response = api.create_response(request, serialized_nofo, status=201) + return_response.headers["Location"] = f"/api/nofos/{nofo.id}" + return return_response except ValidationError as e: return 400, {"message": "Model validation error", "details": e.message_dict} diff --git a/bloom_nofos/nofos/api/schemas.py b/bloom_nofos/nofos/api/schemas.py index 757a779..071b35a 100644 --- a/bloom_nofos/nofos/api/schemas.py +++ b/bloom_nofos/nofos/api/schemas.py @@ -76,6 +76,4 @@ class ErrorSchema(Schema): class SuccessSchema(Schema): - message: str - Location: str nofo: NofoSchema