feat(presentation): add initial structure with dtos, errors, extractors, handlers, and routes modules
This commit is contained in:
0
crates/presentation/src/dtos.rs
Normal file
0
crates/presentation/src/dtos.rs
Normal file
32
crates/presentation/src/errors.rs
Normal file
32
crates/presentation/src/errors.rs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
use axum::{
|
||||||
|
http::StatusCode,
|
||||||
|
response::{IntoResponse, Response},
|
||||||
|
};
|
||||||
|
use domain::errors::DomainError;
|
||||||
|
|
||||||
|
pub struct ApiError(DomainError);
|
||||||
|
|
||||||
|
impl From<DomainError> for ApiError {
|
||||||
|
fn from(err: DomainError) -> Self {
|
||||||
|
Self(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoResponse for ApiError {
|
||||||
|
fn into_response(self) -> Response {
|
||||||
|
let (status, error_message) = match self.0 {
|
||||||
|
DomainError::InvalidRating { .. } => (StatusCode::BAD_REQUEST, self.0.to_string()),
|
||||||
|
DomainError::ValidationError(msg) => (StatusCode::BAD_REQUEST, msg),
|
||||||
|
DomainError::NotFound(msg) => (StatusCode::NOT_FOUND, msg),
|
||||||
|
DomainError::InfrastructureError(_) => {
|
||||||
|
tracing::error!("Internal Infrastructure Error: {:?}", self.0);
|
||||||
|
(
|
||||||
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
"Internal server error".to_string(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
(status, error_message).into_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
0
crates/presentation/src/extractors.rs
Normal file
0
crates/presentation/src/extractors.rs
Normal file
0
crates/presentation/src/handlers.rs
Normal file
0
crates/presentation/src/handlers.rs
Normal file
@@ -1 +1,6 @@
|
|||||||
|
pub mod dtos;
|
||||||
|
pub mod errors;
|
||||||
|
pub mod extractors;
|
||||||
|
pub mod handlers;
|
||||||
pub mod ports;
|
pub mod ports;
|
||||||
|
pub mod routes;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
fn main() {
|
#[tokio::main]
|
||||||
println!("Hello, world!");
|
async fn main() -> anyhow::Result<()> {
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
1
crates/presentation/src/routes.rs
Normal file
1
crates/presentation/src/routes.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
Reference in New Issue
Block a user