Refactor code structure for improved readability and maintainability

This commit is contained in:
2026-04-14 16:20:02 -04:00
parent caa578a280
commit 44facf7f4a
10 changed files with 369 additions and 128 deletions
+14 -6
View File
@@ -88,11 +88,19 @@ where
type Rejection = (StatusCode, &'static str);
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
let org_context = parts.extensions.get::<OrgContext>().ok_or((
StatusCode::INTERNAL_SERVER_ERROR,
"Contexto de organización no encontrado. ¿El middleware está configurado?",
))?;
Ok(Org(org_context.clone()))
// Intentar obtener OrgContext del middleware
if let Some(org_context) = parts.extensions.get::<OrgContext>() {
return Ok(Org(org_context.clone()));
}
// Fallback: usar org por defecto (single-tenant architecture)
// Este fallback es necesario si el middleware no ejecutó correctamente
let default_org_id = Uuid::parse_str("00000000-0000-0000-0000-000000000001")
.map_err(|_| (
StatusCode::INTERNAL_SERVER_ERROR,
"Invalid default organization ID",
))?;
Ok(Org(OrgContext { id: default_org_id }))
}
}