use axum::{Json, extract::State}; use serde::Serialize; use crate::{error::ApiError, state::AppState}; #[derive(Debug, Serialize, utoipa::ToSchema)] pub struct WebhookInfo { pub url: String, pub events: Vec, } #[utoipa::path( get, path = "/api/v1/webhooks", tag = "webhooks", responses( (status = 200, description = "List of configured webhooks", body = Vec), (status = 401, description = "Unauthorized"), (status = 403, description = "Forbidden"), ), security(("bearer_auth" = [])) )] pub async fn list_webhooks( State(state): State, ) -> Result>, ApiError> { let config = state.config.read().await; let hooks: Vec = config .webhooks .iter() .map(|h| { WebhookInfo { url: h.url.clone(), events: h.events.clone(), } }) .collect(); Ok(Json(hooks)) } #[utoipa::path( post, path = "/api/v1/webhooks/test", tag = "webhooks", responses( (status = 200, description = "Test webhook sent"), (status = 401, description = "Unauthorized"), (status = 403, description = "Forbidden"), ), security(("bearer_auth" = [])) )] pub async fn test_webhook( State(state): State, ) -> Result, ApiError> { let config = state.config.read().await; let count = config.webhooks.len(); drop(config); if let Some(ref dispatcher) = state.webhook_dispatcher { dispatcher.dispatch(pinakes_core::webhooks::WebhookEvent::Test); Ok(Json(serde_json::json!({ "webhooks_configured": count, "test_sent": true }))) } else { Ok(Json(serde_json::json!({ "webhooks_configured": 0, "test_sent": false, "message": "no webhooks configured" }))) } }