use crate::domain::{BranchName, CommitHash, EventType, RepoUrl, TargetRepo};
use chrono::{DateTime, Utc};
use rovo::schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
#[derive(Debug, Serialize, Deserialize, FromRow, JsonSchema)]
pub struct Branch {
pub id: i64,
pub repo_url: RepoUrl,
pub name: BranchName,
pub last_commit_hash: Option<CommitHash>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Serialize, Deserialize, FromRow, JsonSchema, Clone)]
pub struct Subscription {
pub id: i64,
pub branch_id: i64,
pub target_repo: TargetRepo,
pub event_type: EventType,
pub gh_app_installation_id: i64,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Serialize, JsonSchema, Clone)]
pub struct SourceBranchInfo {
pub repo_url: RepoUrl,
pub name: BranchName,
}
#[derive(Serialize, JsonSchema)]
pub struct SubscriptionPageLinks {
pub next: Option<HalLink>,
}
#[derive(Serialize, JsonSchema)]
pub struct SubscriptionPage {
pub data: Vec<SubscriptionHal>,
pub remaining_count: i64,
#[serde(rename = "_links")]
pub links: SubscriptionPageLinks,
}
#[derive(Serialize, JsonSchema)]
pub struct HalLink {
pub href: String,
}
#[derive(Serialize, JsonSchema)]
pub struct SubscriptionLinks {
#[serde(rename = "self")]
pub self_link: HalLink,
pub update: HalLink,
pub delete: HalLink,
}
#[derive(Debug, Serialize, JsonSchema)]
pub struct SubscriptionWithBranch {
#[serde(flatten)]
pub subscription: Subscription,
pub source_branch: SourceBranchInfo,
}
#[derive(Serialize, JsonSchema)]
pub struct SubscriptionHal {
#[serde(flatten)]
pub subscription: Subscription,
pub source_branch: SourceBranchInfo,
#[serde(rename = "_links")]
pub links: SubscriptionLinks,
}
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct CreateSubscription {
pub source_repo_url: RepoUrl,
pub source_branch_name: BranchName,
pub target_repo: TargetRepo,
pub event_type: EventType,
pub gh_app_installation_id: i64,
}
#[derive(Debug, Deserialize, JsonSchema)]
pub struct UpdateSubscription {
pub target_repo: Option<TargetRepo>,
pub event_type: Option<EventType>,
pub gh_app_installation_id: Option<i64>,
}
#[derive(Debug, FromRow)]
pub struct TriggerQueueItem {
pub id: i64,
pub branch_id: i64,
pub new_hash: CommitHash,
pub target_repo: TargetRepo,
pub event_type: EventType,
pub gh_app_installation_id: i64,
pub retry_count: i64,
}