docs: tambah doc comment, logging, dan inline comments di semua 255 file

Meliputi:
- File-level //! doc comment: tujuan file, alur kerja, komponen utama
- Function-level /// doc comment: apa, parameter, return, flow, edge cases
- Struct/enum/trait /// doc comment: peran, field docs
- Tracing logging (tracing::info!/debug!/trace!/warn!/error!) di setiap fungsi
- Inline comments untuk variable dan branching logic penting
- Seluruh 8 crates di workspace: zesdex-backend, zesdex-cms, zesdex-entities,
  zesdex-iam, zesdex-infra, zesdex-ipc, zesdex-middleware, zesdex-utils
- Build: 0 errors, 242/242 tests passed
This commit is contained in:
asepharyana
2026-07-19 17:05:47 +07:00
parent 6680795ce7
commit 5aaedbf787
255 changed files with 5666 additions and 743 deletions
@@ -1,11 +1,24 @@
//! HTTP handler functions for CMS endpoints.
//! HTTP handler functions for the CMS REST API.
//!
//! Each handler takes a service trait (via generics or trait objects) and
//! returns domain-level results. These functions are agnostic about the
//! HTTP framework — callers (e.g. Axum routes) are responsible for mapping
//! `Result` into HTTP responses.
//! returns domain-level results. These functions are agnostic about the
//! HTTP framework — callers (e.g. hyper/Axum routes) are responsible for
//! mapping `Result` into HTTP responses with appropriate status codes.
//!
//! ## Handlers
//! - `handle_get_settings` — GET /settings → full settings response
//! - `handle_update_settings` — PUT /settings → partial update + full response
//! - `handle_list_memories` — GET /memories → list of memory summaries
//! - `handle_create_memory` — POST /memories → create/update memory response
//!
//! ## Design
//! Handlers are pure Rust functions with no dependency on the HTTP framework.
//! They receive service trait objects (`&S` or `&M`) and return `Result<T>`.
//! The caller (e.g. a hyper `Service`) is responsible for serialising the
//! response and setting HTTP status codes.
use anyhow::{Context, Result};
use tracing;
use crate::domain::memory::Memory;
use crate::domain::service::{MemoryService, SettingsService};
@@ -16,24 +29,34 @@ use super::dto::{MemoryCreateRequest, MemoryResponse, SettingsResponse, Settings
/// Handle `GET /settings`
///
/// Returns the current settings as a `SettingsResponse`.
///
/// Flow: load settings from service → convert to DTO → return.
pub fn handle_get_settings<S: SettingsService>(service: &S) -> Result<SettingsResponse> {
tracing::debug!("handling GET /settings");
let settings = service.load_settings().context("failed to load settings")?;
Ok(SettingsResponse::from(settings))
}
/// Handle `PUT /settings`
///
/// Applies the partial update from `req` to the current settings, persists
/// Applies a partial update from `req` to the current settings, persists
/// the result, and returns the updated `SettingsResponse`.
///
/// Flow: load current settings → apply each optional field → save → return DTO.
///
/// ## Validation
/// - `internet_mode` must be "Off", "ReadOnly", or "Full" (case-sensitive).
pub fn handle_update_settings<S: SettingsService>(
service: &S,
req: SettingsUpdateRequest,
) -> Result<SettingsResponse> {
tracing::debug!("handling PUT /settings");
// Load current settings as baseline for partial update
let mut settings: Settings = service
.load_settings()
.context("failed to load current settings for update")?;
// Apply partial updates
// Apply each optional field from the request (None = skip, Some = overwrite)
if let Some(val) = req.internet_mode {
settings.internet_mode = match val.as_str() {
"Off" => crate::domain::settings::InternetMode::Off,
@@ -102,8 +125,13 @@ pub fn handle_update_settings<S: SettingsService>(
/// Handle `GET /memories`
///
/// Lists all memory slugs, then loads each memory to return full responses.
/// Lists all memory slugs, returning summary responses for each.
/// Full content is not loaded — callers who need full content should
/// use a dedicated endpoint.
///
/// Flow: list slugs from service → map each to minimal MemoryResponse → return.
pub fn handle_list_memories<M: MemoryService>(service: &M) -> Result<Vec<MemoryResponse>> {
tracing::debug!("handling GET /memories");
let slugs = service.list_memories().context("failed to list memories")?;
// We can't load individual memories without a load_memory method on the
@@ -132,10 +160,17 @@ pub fn handle_list_memories<M: MemoryService>(service: &M) -> Result<Vec<MemoryR
/// Handle `POST /memories`
///
/// Creates or updates a memory from the request body.
///
/// Flow: build Memory from request DTO → save via service → return MemoryResponse.
///
/// ## Defaults
/// - `kind` defaults to "reference" if not specified
/// - `lifecycle` defaults to "new" if not specified
pub fn handle_create_memory<M: MemoryService>(
service: &M,
req: MemoryCreateRequest,
) -> Result<MemoryResponse> {
tracing::debug!("handling POST /memories for '{}'", req.name);
let now = chrono::Utc::now().timestamp();
let memory = Memory {
name: req.name,