summaryrefslogtreecommitdiffstats
path: root/src/routes/mod.rs
blob: c69f18ef2e0dd10fe276b15059d7090a98322c79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
pub mod auth;
pub mod model;
pub mod user;

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<T>(pub T);

impl<T> IntoResponse for JsonCreate<T>
where
    T: Serialize,
{
    fn into_response(self) -> Response {
        (StatusCode::CREATED, Json(self.0)).into_response()
    }
}