Files
k-tv/crates/presentation/src/handlers/providers.rs
Gabriel Kaszewski 33b440d297 fix(presentation): extract 12 handler violations to use cases
- TokenService port + JwtTokenService adapter; login/refresh return LoginResult
- delete get_token (dup of login); create_tokens helper removed
- type UpdateChannelRequest schedule_config/recycle_policy (no serde_json::Value)
- update_settings returns updated Vec; handler calls one use case
- config use case in application::config; handler maps DTO only
- SyncStatusEntry moved to api-types w/ From<LibrarySyncLogEntry>
- trigger_sync: Conflict error, drop sync_trigger.send from handler
- UpsertProviderCommand.config accepts Value; serialization in use case
- get_current_broadcast returns BroadcastWithChannel; one call
- get_stream_url resolves broadcast internally; handler single call
2026-07-12 05:28:49 +02:00

65 lines
2.0 KiB
Rust

use axum::Json;
use axum::extract::{Path, State};
use api_types::{ProviderConfigRequest, ProviderConfigResponse};
use application::providers::{
DeleteProviderCommand, GetProviderQuery, ListProvidersQuery, 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 =
application::providers::list::execute(&state.provider_deps, ListProvidersQuery).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 query = GetProviderQuery { id: id.clone() };
let provider = application::providers::get::execute(&state.provider_deps, query)
.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> {
let cmd = DeleteProviderCommand { id };
application::providers::delete::execute(&state.provider_deps, cmd).await?;
Ok(axum::http::StatusCode::NO_CONTENT)
}