chore: cleanups and refactorings for cleaner code

This commit is contained in:
2026-07-18 21:39:16 +02:00
parent b438a99999
commit e5080b7282
63 changed files with 3454 additions and 4093 deletions

View File

@@ -2,7 +2,20 @@ use serde::{Deserialize, Serialize};
/// Tracks content hashes of generated files to skip unchanged writes.
/// Matches the `generated_file_hashes` table.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(
Debug,
Clone,
Serialize,
Deserialize,
diesel::Queryable,
diesel::Selectable,
diesel::Insertable,
diesel::AsChangeset,
)]
#[diesel(
table_name = crate::db::schema::generated_file_hashes,
check_for_backend(diesel::sqlite::Sqlite)
)]
pub struct GeneratedFileHash {
pub project_id: String,
pub relative_path: String,
@@ -10,7 +23,10 @@ pub struct GeneratedFileHash {
pub updated_at: i64,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, diesel::AsExpression, diesel::FromSqlRow,
)]
#[diesel(sql_type = diesel::sql_types::Text)]
#[serde(rename_all = "lowercase")]
pub enum NotificationEntity {
Post,
@@ -19,7 +35,10 @@ pub enum NotificationEntity {
Template,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, diesel::AsExpression, diesel::FromSqlRow,
)]
#[diesel(sql_type = diesel::sql_types::Text)]
#[serde(rename_all = "lowercase")]
pub enum NotificationAction {
Created,
@@ -27,14 +46,68 @@ pub enum NotificationAction {
Deleted,
}
impl std::str::FromStr for NotificationEntity {
type Err = String;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"post" => Ok(Self::Post),
"media" => Ok(Self::Media),
"script" => Ok(Self::Script),
"template" => Ok(Self::Template),
_ => Err(format!("invalid NotificationEntity: {value}")),
}
}
}
impl NotificationEntity {
pub const fn as_str(&self) -> &'static str {
match self {
Self::Post => "post",
Self::Media => "media",
Self::Script => "script",
Self::Template => "template",
}
}
}
impl std::str::FromStr for NotificationAction {
type Err = String;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"created" => Ok(Self::Created),
"updated" => Ok(Self::Updated),
"deleted" => Ok(Self::Deleted),
_ => Err(format!("invalid NotificationAction: {value}")),
}
}
}
impl NotificationAction {
pub const fn as_str(&self) -> &'static str {
match self {
Self::Created => "created",
Self::Updated => "updated",
Self::Deleted => "deleted",
}
}
}
/// Notification for CLI-to-app synchronization.
/// Matches the `db_notifications` table.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, diesel::Queryable, diesel::Selectable)]
#[diesel(
table_name = crate::db::schema::db_notifications,
check_for_backend(diesel::sqlite::Sqlite)
)]
pub struct DbNotification {
#[diesel(deserialize_as = i32)]
pub id: i64,
pub entity_type: NotificationEntity,
pub entity_id: String,
pub action: NotificationAction,
#[diesel(deserialize_as = crate::db::types::DbBool)]
pub from_cli: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub seen_at: Option<i64>,