decision_cockpit 0.1.0

Layer — product decision memory with MCP tools and an embedded review dashboard
Documentation
use axum::extract::{Path, Query, State};
use axum::Json;
use serde::Deserialize;
use uuid::Uuid;

use crate::domain::memos::Memo;
use crate::error::AppResult;
use crate::services::memos as svc;
use crate::state::AppState;

#[derive(Debug, Deserialize)]
pub struct ListQuery {
    pub limit: Option<i64>,
}

#[derive(Debug, Deserialize)]
pub struct CreateMemoBody {
    pub memo_type: String,
    pub title: String,
    pub body_markdown: String,
    pub status: Option<String>,
}

#[derive(Debug, Deserialize)]
pub struct UpdateMemoBody {
    pub title: Option<String>,
    pub memo_type: Option<String>,
    pub body_markdown: Option<String>,
    pub status: Option<String>,
}

pub async fn list(
    State(state): State<AppState>,
    Query(q): Query<ListQuery>,
) -> AppResult<Json<Vec<Memo>>> {
    let memos = svc::list_memos(&state.pool, q.limit).await?;
    Ok(Json(memos))
}

pub async fn get_one(
    State(state): State<AppState>,
    Path(id): Path<Uuid>,
) -> AppResult<Json<Memo>> {
    let memo = svc::get_memo(&state.pool, id).await?;
    Ok(Json(memo))
}

pub async fn create(
    State(state): State<AppState>,
    Json(body): Json<CreateMemoBody>,
) -> AppResult<Json<Memo>> {
    let memo = svc::create_memo(
        &state.pool,
        &body.memo_type,
        &body.title,
        &body.body_markdown,
        body.status.as_deref(),
    )
    .await?;
    Ok(Json(memo))
}

pub async fn update(
    State(state): State<AppState>,
    Path(id): Path<Uuid>,
    Json(body): Json<UpdateMemoBody>,
) -> AppResult<Json<Memo>> {
    let memo = svc::update_memo(
        &state.pool,
        id,
        body.title.as_deref(),
        body.memo_type.as_deref(),
        body.body_markdown.as_deref(),
        body.status.as_deref(),
    )
    .await?;
    Ok(Json(memo))
}

pub async fn from_drift(
    State(state): State<AppState>,
    Path(drift_signal_id): Path<Uuid>,
) -> AppResult<Json<Memo>> {
    let memo = svc::create_memo_from_drift(&state.pool, drift_signal_id).await?;
    Ok(Json(memo))
}