delete get/list/list_by_owner channels, get_settings/activity_log admin, get_item/get_sync_status/list_collections/list_seasons/list_shows/list_genres library, get/list/delete providers, get/list/patch_label config_snapshots, get_active/list_history/delete_after schedule — all single-delegation. remove ChannelQueryDeps, LibraryQueryDeps, deleted query/command structs. add direct port fields to AppState. update MCP crate accordingly.
62 lines
1.8 KiB
Rust
62 lines
1.8 KiB
Rust
use axum::Json;
|
|
use axum::extract::{Path, State};
|
|
|
|
use api_types::{ProviderConfigRequest, ProviderConfigResponse};
|
|
use application::providers::UpsertProviderCommand;
|
|
use domain::DomainError;
|
|
|
|
use crate::errors::AppError;
|
|
use crate::extractors::AdminUser;
|
|
use crate::state::AppState;
|
|
|
|
pub async fn list_providers(
|
|
State(state): State<AppState>,
|
|
AdminUser(_user): AdminUser,
|
|
) -> Result<Json<Vec<ProviderConfigResponse>>, AppError> {
|
|
let providers = state.provider_config_query.get_all().await?;
|
|
Ok(Json(
|
|
providers
|
|
.into_iter()
|
|
.map(ProviderConfigResponse::from)
|
|
.collect(),
|
|
))
|
|
}
|
|
|
|
pub async fn get_provider(
|
|
State(state): State<AppState>,
|
|
AdminUser(_user): AdminUser,
|
|
Path(id): Path<String>,
|
|
) -> Result<Json<ProviderConfigResponse>, AppError> {
|
|
let provider = state
|
|
.provider_config_query
|
|
.get_by_id(&id)
|
|
.await?
|
|
.ok_or_else(|| AppError(DomainError::NotFound(format!("Provider {id} not found"))))?;
|
|
Ok(Json(ProviderConfigResponse::from(provider)))
|
|
}
|
|
|
|
pub async fn upsert_provider(
|
|
State(state): State<AppState>,
|
|
AdminUser(_user): AdminUser,
|
|
Path(id): Path<String>,
|
|
Json(req): Json<ProviderConfigRequest>,
|
|
) -> Result<Json<serde_json::Value>, AppError> {
|
|
let cmd = UpsertProviderCommand {
|
|
id,
|
|
provider_type: req.provider_type,
|
|
config: req.config,
|
|
enabled: req.enabled,
|
|
};
|
|
application::providers::upsert::execute(&state.provider_deps, cmd).await?;
|
|
Ok(Json(serde_json::json!({"status": "ok"})))
|
|
}
|
|
|
|
pub async fn delete_provider(
|
|
State(state): State<AppState>,
|
|
AdminUser(_user): AdminUser,
|
|
Path(id): Path<String>,
|
|
) -> Result<axum::http::StatusCode, AppError> {
|
|
state.provider_config_command.delete(&id).await?;
|
|
Ok(axum::http::StatusCode::NO_CONTENT)
|
|
}
|