use axum::{ Json, extract::{Path, State}, }; use serde::Deserialize; use serde_json::{Value, json}; use crate::{error::ApiError, service::UpstreamPayload, state::AppState}; #[derive(Deserialize)] pub struct WorkspacePath { pub workspace_id: String, } #[derive(Deserialize)] pub struct WorkspaceUpstreamPath { pub workspace_id: String, pub upstream_id: String, } pub async fn list_upstreams( Path(path): Path, State(state): State, ) -> Result, ApiError> { let items = state .service .list_workspace_upstreams(&path.workspace_id.as_str().into()) .await?; Ok(Json(json!({ "items": items }))) } pub async fn create_upstream( Path(path): Path, State(state): State, Json(payload): Json, ) -> Result, ApiError> { let upstream = state .service .save_workspace_upstream(&path.workspace_id.as_str().into(), None, payload) .await?; Ok(Json(json!(upstream))) } pub async fn update_upstream( Path(path): Path, State(state): State, Json(payload): Json, ) -> Result, ApiError> { let upstream = state .service .save_workspace_upstream( &path.workspace_id.as_str().into(), Some(&path.upstream_id.as_str().into()), payload, ) .await?; Ok(Json(json!(upstream))) }