From db4ed05815bf9f74c4d9fa932e28a405d42df694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Greinhofer?= Date: Thu, 31 Oct 2024 08:59:41 -0500 Subject: [PATCH] Fix POST submission endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensures the HTTP statuc code for a POST request is 201. Signed-off-by: Rémy Greinhofer --- lambdas/src/bin/cities/post-cities-submissions.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lambdas/src/bin/cities/post-cities-submissions.rs b/lambdas/src/bin/cities/post-cities-submissions.rs index 8ebd0b0..f879d82 100644 --- a/lambdas/src/bin/cities/post-cities-submissions.rs +++ b/lambdas/src/bin/cities/post-cities-submissions.rs @@ -1,8 +1,9 @@ use dotenv::dotenv; -use effortless::{api::parse_request_body, error::APIErrors}; +use effortless::{api::parse_request_body, error::APIErrors, response::make_json_created_response}; use entity::wrappers::submission::SubmissionPost; -use lambda_http::{run, service_fn, Body, Error, IntoResponse, Request, Response}; +use lambda_http::{run, service_fn, Body, Error, Request, Response}; use lambdas::core::resource::cities::adaptor::post_cities_submission_adaptor; +use serde_json::json; use tracing::info; async fn function_handler(event: Request) -> Result, Error> { @@ -16,7 +17,8 @@ async fn function_handler(event: Request) -> Result, Error> { // let country = wrapper.country.clone(); match post_cities_submission_adaptor(wrapper).await { - Ok(v) => Ok(v.into_response().await), + Ok(v) => Ok(make_json_created_response(json!(v).to_string()) + .expect("unable to build http::Response")), Err(e) => Ok(APIErrors::from(e).into()), } }