From 3c8b004d6ecb6764cd5bc935aaeaf884040320ab Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 20 Aug 2024 17:50:24 +0200 Subject: Init --- src/routes.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/routes.rs (limited to 'src/routes.rs') diff --git a/src/routes.rs b/src/routes.rs new file mode 100644 index 0000000..a269bc4 --- /dev/null +++ b/src/routes.rs @@ -0,0 +1,23 @@ +use crate::errors::AppError; +use axum::{ + http::StatusCode, + response::{IntoResponse, Response}, + Json, +}; +use serde::Serialize; + +pub async fn page_404() -> impl IntoResponse { + AppError::NotFound("Route not found".to_string()) +} + +/// Extension of `Json` which returns the CREATED status code +pub struct JsonCreate(pub T); + +impl IntoResponse for JsonCreate +where + T: Serialize, +{ + fn into_response(self) -> Response { + (StatusCode::CREATED, Json(self.0)).into_response() + } +} -- cgit v1.2.3-18-g5258