aboutsummaryrefslogtreecommitdiff
path: root/src/response/success.rs
blob: c2ec4e57ef84eedbabb90707cd43814b717f56a2 (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
28
29
30
31
32
33
use axum::{
    http::StatusCode,
    response::{IntoResponse, Response},
};
use serde::Serialize;
use utoipa::ToSchema;

#[derive(Serialize, ToSchema)]
enum SuccessStatus {
    #[serde(rename = "success")]
    Success,
}

#[derive(Serialize, ToSchema)]
pub struct SuccessResponse<T> {
    status: SuccessStatus,
    data: T,
}

impl<T> SuccessResponse<T> {
    pub fn ok(data: T) -> Self {
        Self {
            status: SuccessStatus::Success,
            data,
        }
    }
}

impl<T: Serialize> IntoResponse for SuccessResponse<T> {
    fn into_response(self) -> Response {
        (StatusCode::OK, axum::Json(self)).into_response()
    }
}