This commit is contained in:
nym21
2025-11-14 12:09:58 +01:00
parent 1d2c927d94
commit e8f77ab2e5
46 changed files with 1400 additions and 1394 deletions
+6 -5
View File
@@ -3,6 +3,7 @@ use axum::{
http::{Response, StatusCode},
response::IntoResponse,
};
use serde::Serialize;
use super::header_map::HeaderMapExtended;
@@ -13,10 +14,10 @@ where
fn new_not_modified() -> Self;
fn new_json<T>(value: T, etag: &str) -> Self
where
T: sonic_rs::Serialize;
T: Serialize;
fn new_json_with<T>(status: StatusCode, value: T, etag: &str) -> Self
where
T: sonic_rs::Serialize;
T: Serialize;
}
impl ResponseExtended for Response<Body> {
@@ -29,16 +30,16 @@ impl ResponseExtended for Response<Body> {
fn new_json<T>(value: T, etag: &str) -> Self
where
T: sonic_rs::Serialize,
T: Serialize,
{
Self::new_json_with(StatusCode::default(), value, etag)
}
fn new_json_with<T>(status: StatusCode, value: T, etag: &str) -> Self
where
T: sonic_rs::Serialize,
T: Serialize,
{
let bytes = sonic_rs::to_vec(&value).unwrap();
let bytes = serde_json::to_vec(&value).unwrap();
let mut response = Response::builder().body(bytes.into()).unwrap();
*response.status_mut() = status;
let headers = response.headers_mut();
+3 -2
View File
@@ -1,5 +1,6 @@
use axum::{http::StatusCode, response::Response};
use brk_error::{Error, Result};
use serde::Serialize;
use crate::extended::ResponseExtended;
@@ -7,7 +8,7 @@ pub trait ResultExtended<T> {
fn with_status(self) -> Result<T, (StatusCode, String)>;
fn to_json_response(self, etag: &str) -> Response
where
T: sonic_rs::Serialize;
T: Serialize;
}
impl<T> ResultExtended<T> for Result<T> {
@@ -29,7 +30,7 @@ impl<T> ResultExtended<T> for Result<T> {
fn to_json_response(self, etag: &str) -> Response
where
T: sonic_rs::Serialize,
T: Serialize,
{
match self.with_status() {
Ok(value) => Response::new_json(&value, etag),