use axum::{ extract::State, http::StatusCode, response::{Html, IntoResponse, Json}, }; use serde_json::json; use crate::{models::AdminEmoteResponse, AppState}; /// GET /manage /// Serves the emote management HTML page. pub async fn manage_root() -> impl IntoResponse { Html(include_str!("../templates/manage.html")) } /// GET /manage/emotes /// Returns all emotes with full admin data (uuid, alias included). pub async fn list_admin_emotes(State(state): State) -> impl IntoResponse { match state.db.list_emotes().await { Ok(rows) => { let emotes: Vec = rows .into_iter() .map(|row| AdminEmoteResponse { uuid: row.uuid.clone(), name: row.name.clone(), alias: row.alias.clone(), url: state.storage.public_url(&row.image_key), created: row.created_dt(), modified: row.modified_dt(), }) .collect(); (StatusCode::OK, Json(json!({"emotes": emotes}))).into_response() } Err(e) => { tracing::error!("Failed to list emotes: {e}"); ( StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": "Failed to list emotes"})), ) .into_response() } } }