Compare commits

...

1 Commits

Author SHA1 Message Date
Connor Johnstone
8a1435d9e9 Added the watch and scheduler systems 2026-03-20 16:28:15 -04:00
4 changed files with 88 additions and 0 deletions

View File

@@ -14,6 +14,9 @@ pub struct Model {
pub top_songs: String,
/// JSON-serialized Vec of similar artist info
pub similar_artists: String,
pub monitored: bool,
#[sea_orm(nullable)]
pub last_checked_at: Option<chrono::NaiveDateTime>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View File

@@ -0,0 +1,59 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(Artists::Table)
.add_column(
ColumnDef::new(Artists::Monitored)
.boolean()
.not_null()
.default(false),
)
.to_owned(),
)
.await?;
manager
.alter_table(
Table::alter()
.table(Artists::Table)
.add_column(ColumnDef::new(Artists::LastCheckedAt).timestamp())
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(Artists::Table)
.drop_column(Artists::LastCheckedAt)
.to_owned(),
)
.await?;
manager
.alter_table(
Table::alter()
.table(Artists::Table)
.drop_column(Artists::Monitored)
.to_owned(),
)
.await
}
}
#[derive(DeriveIden)]
enum Artists {
Table,
Monitored,
LastCheckedAt,
}

View File

@@ -11,6 +11,7 @@ mod m20260317_000009_add_wanted_name;
mod m20260317_000010_add_wanted_mbid;
mod m20260319_000011_create_users;
mod m20260319_000012_add_user_id_to_wanted_items;
mod m20260320_000013_add_artist_monitoring;
pub struct Migrator;
@@ -29,6 +30,7 @@ impl MigratorTrait for Migrator {
Box::new(m20260317_000010_add_wanted_mbid::Migration),
Box::new(m20260319_000011_create_users::Migration),
Box::new(m20260319_000012_add_user_id_to_wanted_items::Migration),
Box::new(m20260320_000013_add_artist_monitoring::Migration),
]
}
}

View File

@@ -38,6 +38,8 @@ pub async fn upsert(
added_at: Set(now),
top_songs: Set("[]".to_string()),
similar_artists: Set("[]".to_string()),
monitored: Set(false),
last_checked_at: Set(None),
..Default::default()
};
match active.insert(db).await {
@@ -109,3 +111,25 @@ pub async fn delete(db: &DatabaseConnection, id: i32) -> DbResult<()> {
Artists::delete_by_id(id).exec(db).await?;
Ok(())
}
pub async fn set_monitored(db: &DatabaseConnection, id: i32, monitored: bool) -> DbResult<Artist> {
let existing = get_by_id(db, id).await?;
let mut active: ActiveModel = existing.into();
active.monitored = Set(monitored);
Ok(active.update(db).await?)
}
pub async fn list_monitored(db: &DatabaseConnection) -> DbResult<Vec<Artist>> {
Ok(Artists::find()
.filter(artist::Column::Monitored.eq(true))
.order_by_asc(artist::Column::Name)
.all(db)
.await?)
}
pub async fn update_last_checked(db: &DatabaseConnection, id: i32) -> DbResult<Artist> {
let existing = get_by_id(db, id).await?;
let mut active: ActiveModel = existing.into();
active.last_checked_at = Set(Some(Utc::now().naive_utc()));
Ok(active.update(db).await?)
}