chore: re-map project structure to using multi workspace paradigm
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
use axum::http::StatusCode;
|
||||
use validator::Validate;
|
||||
|
||||
pub fn validate_request<T: Validate>(
|
||||
payload: &T,
|
||||
) -> Result<(), (StatusCode, String)> {
|
||||
if let Err(validation_errors) = payload.validate() {
|
||||
let error_messages: Vec<String> = validation_errors
|
||||
.field_errors()
|
||||
.iter()
|
||||
.flat_map(|(_, errors)| {
|
||||
errors.iter().map(move |error| {
|
||||
format!(
|
||||
"{}",
|
||||
error
|
||||
.message
|
||||
.clone()
|
||||
.unwrap_or_else(|| "Invalid value".into())
|
||||
)
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
return Err((StatusCode::BAD_REQUEST, error_messages.join(", ")));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user