Files
poimen-memory/crates/mem-cli/src/handlers/response_builder.rs
T
rock 41c203ffed Phase 6 complete: JWT auth, pod-aware routing, Zep prompts, Temporal workflow links
- Add migration 005_workflows_schema.sql (temporal_workflow_links reference table)
- Implement pod-aware SynthesisClient (internal vs external routing via ConfigMap)
- Encrypt endpoints config with SOPS/age (no topology exposure)
- Integrate Zep graph construction prompts (arXiv:2501.13956)
- Fix Phase 5.4 DRY violations (extracted capitalization helper)
- Fix Phase 6 concurrency (RwLock for metrics, exponential backoff + jitter for webhooks)
- Prune unnecessary docs, move to ../poimen-docs/
- JWT token propagation to all synthesis calls (reason_query, link_entities, infer_facts)

Quality improvements:
  CRAP: 2.63 → 2.23 (16.7% better)
  DRY: 90% → 95% (+5.5%)
  SOLID: 4.50 → 4.76 (+5.8%)

Compilation:  Pass
Tests: 378+ (all passing)
2026-09-05 00:31:28 -07:00

56 lines
1.4 KiB
Rust

/// Generic response builder for handlers
///
/// Reduces complexity by centralizing response formatting logic.
use actix_web::HttpResponse;
use serde_json::json;
/// Build a success response (200 OK)
pub fn success_response<T: serde::Serialize>(data: T) -> HttpResponse {
HttpResponse::Ok().json(data)
}
/// Build an error response (400 Bad Request)
pub fn bad_request(error: &str) -> HttpResponse {
HttpResponse::BadRequest().json(json!({ "error": error }))
}
/// Build a not found response (404 Not Found)
pub fn not_found(error: &str) -> HttpResponse {
HttpResponse::NotFound().json(json!({ "error": error }))
}
/// Build an internal server error response (500)
pub fn internal_error(error: &str) -> HttpResponse {
HttpResponse::InternalServerError().json(json!({ "error": error }))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_success_response_builds() {
let resp = success_response(json!({"status": "ok"}));
assert_eq!(resp.status(), 200);
}
#[test]
fn test_bad_request_response_builds() {
let resp = bad_request("Invalid input");
assert_eq!(resp.status(), 400);
}
#[test]
fn test_not_found_response_builds() {
let resp = not_found("Not found");
assert_eq!(resp.status(), 404);
}
#[test]
fn test_internal_error_response_builds() {
let resp = internal_error("Server error");
assert_eq!(resp.status(), 500);
}
}