Added the watch and scheduler systems
This commit is contained in:
@@ -14,6 +14,9 @@ pub struct Model {
|
|||||||
pub top_songs: String,
|
pub top_songs: String,
|
||||||
/// JSON-serialized Vec of similar artist info
|
/// JSON-serialized Vec of similar artist info
|
||||||
pub similar_artists: String,
|
pub similar_artists: String,
|
||||||
|
pub monitored: bool,
|
||||||
|
#[sea_orm(nullable)]
|
||||||
|
pub last_checked_at: Option<chrono::NaiveDateTime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
|||||||
59
src/migration/m20260320_000013_add_artist_monitoring.rs
Normal file
59
src/migration/m20260320_000013_add_artist_monitoring.rs
Normal 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,
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ mod m20260317_000009_add_wanted_name;
|
|||||||
mod m20260317_000010_add_wanted_mbid;
|
mod m20260317_000010_add_wanted_mbid;
|
||||||
mod m20260319_000011_create_users;
|
mod m20260319_000011_create_users;
|
||||||
mod m20260319_000012_add_user_id_to_wanted_items;
|
mod m20260319_000012_add_user_id_to_wanted_items;
|
||||||
|
mod m20260320_000013_add_artist_monitoring;
|
||||||
|
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ impl MigratorTrait for Migrator {
|
|||||||
Box::new(m20260317_000010_add_wanted_mbid::Migration),
|
Box::new(m20260317_000010_add_wanted_mbid::Migration),
|
||||||
Box::new(m20260319_000011_create_users::Migration),
|
Box::new(m20260319_000011_create_users::Migration),
|
||||||
Box::new(m20260319_000012_add_user_id_to_wanted_items::Migration),
|
Box::new(m20260319_000012_add_user_id_to_wanted_items::Migration),
|
||||||
|
Box::new(m20260320_000013_add_artist_monitoring::Migration),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ pub async fn upsert(
|
|||||||
added_at: Set(now),
|
added_at: Set(now),
|
||||||
top_songs: Set("[]".to_string()),
|
top_songs: Set("[]".to_string()),
|
||||||
similar_artists: Set("[]".to_string()),
|
similar_artists: Set("[]".to_string()),
|
||||||
|
monitored: Set(false),
|
||||||
|
last_checked_at: Set(None),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
match active.insert(db).await {
|
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?;
|
Artists::delete_by_id(id).exec(db).await?;
|
||||||
Ok(())
|
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?)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user