Files
k-tv/crates/presentation/src/handlers/admin.rs
Gabriel Kaszewski e2393be635 collapse 20 pass-through use cases; handlers call ports directly
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.
2026-07-12 07:18:26 +02:00

51 lines
1.6 KiB
Rust

use axum::Json;
use axum::extract::{Query, State};
use std::collections::HashMap;
use api_types::{ActivityEventResponse, ActivityLogParams, SettingsResponse};
use application::admin::UpdateSettingsCommand;
use crate::errors::AppError;
use crate::extractors::AdminUser;
use crate::state::AppState;
const DEFAULT_ACTIVITY_LIMIT: u32 = 50;
pub async fn get_settings(
State(state): State<AppState>,
AdminUser(_user): AdminUser,
) -> Result<Json<SettingsResponse>, AppError> {
let pairs = state.settings_repo.get_all().await?;
let settings: HashMap<String, String> = pairs.into_iter().collect();
Ok(Json(SettingsResponse { settings }))
}
pub async fn update_settings(
State(state): State<AppState>,
AdminUser(_user): AdminUser,
Json(body): Json<HashMap<String, String>>,
) -> Result<Json<SettingsResponse>, AppError> {
let settings_vec: Vec<(String, String)> = body.into_iter().collect();
let cmd = UpdateSettingsCommand {
settings: settings_vec,
};
let pairs = application::admin::update_settings::execute(&state.admin_deps, cmd).await?;
let settings: HashMap<String, String> = pairs.into_iter().collect();
Ok(Json(SettingsResponse { settings }))
}
pub async fn get_activity_log(
State(state): State<AppState>,
AdminUser(_user): AdminUser,
Query(params): Query<ActivityLogParams>,
) -> Result<Json<Vec<ActivityEventResponse>>, AppError> {
let limit = params.limit.unwrap_or(DEFAULT_ACTIVITY_LIMIT);
let events = state.activity_query.recent(limit).await?;
Ok(Json(
events
.into_iter()
.map(ActivityEventResponse::from)
.collect(),
))
}