1use kellnr_common::webhook::{Webhook, WebhookEvent};
2use serde::{Deserialize, Serialize};
3use thiserror::Error;
4use utoipa::ToSchema;
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
7pub struct RegisterWebhookRequest {
8 #[serde(alias = "type")]
10 pub event: WebhookEvent,
11 pub callback_url: String,
12 pub name: Option<String>,
13 #[serde(default)]
17 #[schema(write_only, example = "whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw")]
18 pub secret: Option<String>,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
22pub struct RegisterWebhookResponse {
23 pub id: String,
24}
25
26#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
27pub struct GetWebhookResponse {
28 pub id: String,
29 pub event: WebhookEvent,
30 pub callback_url: String,
31 pub name: Option<String>,
32 #[serde(default)]
34 pub has_secret: bool,
35}
36
37impl From<Webhook> for GetWebhookResponse {
38 fn from(w: Webhook) -> Self {
39 Self {
40 id: w.id.unwrap_or_default(),
41 event: w.event,
42 callback_url: w.callback_url,
43 name: w.name,
44 has_secret: w.secret.is_some(),
45 }
46 }
47}
48
49#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
50pub struct GetAllWebhooksResponse(pub Vec<GetWebhookResponse>);
51
52#[derive(Error, Debug)]
53pub enum WebhookError {
54 #[error("Database error: {0}")]
55 DatabaseError(#[from] kellnr_db::error::DbError),
56}