style: format seluruh workspace dengan cargo fmt

Menyeragamkan format kode sesuai rustfmt (126 file). Sebelumnya
lefthook pre-commit 'cargo fmt --check' akan gagal pada commit apa pun.
This commit is contained in:
asepharyana
2026-08-27 22:10:28 +07:00
parent 884b19ccb5
commit 7b0b53671f
127 changed files with 1271 additions and 1156 deletions
+1 -3
View File
@@ -69,9 +69,7 @@ impl IntoResponse for ApiError {
ApiError::Unauthorized(msg) => (StatusCode::UNAUTHORIZED, msg.clone()),
ApiError::NotFound(msg) => (StatusCode::NOT_FOUND, msg.clone()),
ApiError::Conflict(msg) => (StatusCode::CONFLICT, msg.clone()),
ApiError::TooManyRequests(msg) => {
(StatusCode::TOO_MANY_REQUESTS, msg.clone())
}
ApiError::TooManyRequests(msg) => (StatusCode::TOO_MANY_REQUESTS, msg.clone()),
ApiError::Internal(msg) => {
tracing::error!(error = %msg, "Internal server error");
(
+7 -5
View File
@@ -105,7 +105,9 @@ pub async fn login_handler(
serde_json::from_str(&content)
.map_err(|e| ApiError::Internal(format!("Failed to parse users: {e}")))?
} else {
return Err(ApiError::Unauthorized("Invalid username or password".into()));
return Err(ApiError::Unauthorized(
"Invalid username or password".into(),
));
};
// Look up the user
@@ -121,7 +123,9 @@ pub async fn login_handler(
.map_err(|e| ApiError::Internal(format!("Password verification failed: {e}")))?;
if !valid {
return Err(ApiError::Unauthorized("Invalid username or password".into()));
return Err(ApiError::Unauthorized(
"Invalid username or password".into(),
));
}
// Generate tokens
@@ -205,9 +209,7 @@ pub async fn register_handler(
// Check uniqueness
if users.contains_key(&req.username) {
return Err(ApiError::Conflict(
"Username already exists".into(),
));
return Err(ApiError::Conflict("Username already exists".into()));
}
// Persist
+2 -1
View File
@@ -136,7 +136,8 @@ pub async fn chat_completions_handler(
None, // No tool definitions for basic chat
req.max_tokens,
req.temperature,
).await
)
.await
.map_err(|e| ApiError::ChatProxy(format!("LLM request failed: {e}")))?;
let (prompt_tokens, completion_tokens) = usage.unwrap_or((0, 0));
+2 -2
View File
@@ -91,8 +91,8 @@ pub async fn delete_session_handler(
return Err(ApiError::BadRequest("Session ID is required".into()));
}
let session_id =
SessionId::new(&id).map_err(|e| ApiError::BadRequest(format!("Invalid session ID: {e}")))?;
let session_id = SessionId::new(&id)
.map_err(|e| ApiError::BadRequest(format!("Invalid session ID: {e}")))?;
state.session_service.archive_session(session_id)?;
+6 -6
View File
@@ -31,8 +31,8 @@ pub mod state;
pub use error::ApiError;
pub use state::ApiState;
use std::sync::Arc;
use axum::Router;
use std::sync::Arc;
use tower_http::cors::CorsLayer;
/// Build the API router with all routes registered.
@@ -64,10 +64,7 @@ pub fn build_router(state: ApiState) -> Router {
Router::new()
.nest("/api/v1/auth", auth_router())
.nest("/api/v1/health", health_router())
.nest(
"/api/v1",
protected_router().layer(jwt_auth),
)
.nest("/api/v1", protected_router().layer(jwt_auth))
.layer(cors)
.with_state(shared_state)
}
@@ -89,7 +86,10 @@ fn protected_router() -> Router<Arc<ApiState>> {
let sessions_router = Router::new()
.route("/", axum::routing::get(sessions::list_sessions_handler))
.route("/", axum::routing::post(sessions::create_session_handler))
.route("/{id}", axum::routing::delete(sessions::delete_session_handler))
.route(
"/{id}",
axum::routing::delete(sessions::delete_session_handler),
)
// Conversations are sub-resources of sessions
.route(
"/{id}/conversations",
+2 -5
View File
@@ -100,8 +100,7 @@ where
Ok(claims) => {
// Reject refresh tokens on protected routes — only access
// tokens are acceptable here.
if claims.token_type
!= zesdex_infrastructure::auth::jwt::TokenType::Access
if claims.token_type != zesdex_infrastructure::auth::jwt::TokenType::Access
{
let response = (
StatusCode::UNAUTHORIZED,
@@ -115,9 +114,7 @@ where
}
// Inject claims as extension for downstream handlers
let mut req = req;
req.extensions_mut().insert(JwtClaims {
sub: claims.sub,
});
req.extensions_mut().insert(JwtClaims { sub: claims.sub });
let fut = self.inner.call(req);
return Box::pin(fut);
}
+14 -20
View File
@@ -169,37 +169,31 @@ pub struct ApiState {
// -----------------------------------------------------------------------
// Service implementations (application-layer use cases)
// -----------------------------------------------------------------------
/// Session lifecycle management (create, list, archive).
pub session_service:
zesdex_application::auth::SessionServiceImpl<
zesdex_infrastructure::persistence::iam::session_repo::FileSystemSessionRepository,
zesdex_infrastructure::persistence::iam::session_lock_repo::FileSystemSessionLockRepository,
>,
pub session_service: zesdex_application::auth::SessionServiceImpl<
zesdex_infrastructure::persistence::iam::session_repo::FileSystemSessionRepository,
zesdex_infrastructure::persistence::iam::session_lock_repo::FileSystemSessionLockRepository,
>,
/// Conversation message history CRUD.
pub conversation_service:
zesdex_application::cms::ConversationServiceImpl<
zesdex_infrastructure::persistence::cms::conversation_repo::JsonConversationRepository,
>,
pub conversation_service: zesdex_application::cms::ConversationServiceImpl<
zesdex_infrastructure::persistence::cms::conversation_repo::JsonConversationRepository,
>,
/// Settings load/save.
pub settings_service:
zesdex_application::cms::SettingsServiceImpl<
zesdex_infrastructure::persistence::cms::settings_repo::JsonSettingsRepository,
zesdex_infrastructure::persistence::cms::app_config_repo::JsonAppConfigRepository,
>,
pub settings_service: zesdex_application::cms::SettingsServiceImpl<
zesdex_infrastructure::persistence::cms::settings_repo::JsonSettingsRepository,
zesdex_infrastructure::persistence::cms::app_config_repo::JsonAppConfigRepository,
>,
/// Long-term memory CRUD.
pub memory_service:
zesdex_application::cms::MemoryServiceImpl<
zesdex_infrastructure::persistence::cms::memory_repo::MarkdownMemoryRepository,
>,
pub memory_service: zesdex_application::cms::MemoryServiceImpl<
zesdex_infrastructure::persistence::cms::memory_repo::MarkdownMemoryRepository,
>,
// -----------------------------------------------------------------------
// Port trait implementations (infrastructure wrappers)
// -----------------------------------------------------------------------
/// Argon2id password hashing and verification.
pub password_service: Argon2PasswordService,