Added the watch and scheduler systems

This commit is contained in:
Connor Johnstone
2026-03-20 16:28:15 -04:00
parent eaaff5f98f
commit 9d6c0e31c1
16 changed files with 948 additions and 164 deletions

View File

@@ -33,6 +33,7 @@ struct ArtistListItem {
id: i32,
name: String,
musicbrainz_id: Option<String>,
monitored: bool,
total_watched: usize,
total_owned: usize,
total_items: usize,
@@ -72,6 +73,11 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
.route(web::post().to(add_artist)),
)
.service(web::resource("/artists/{id}/full").route(web::get().to(get_artist_full)))
.service(
web::resource("/artists/{id}/monitor")
.route(web::post().to(set_monitored))
.route(web::delete().to(unset_monitored)),
)
.service(
web::resource("/artists/{id}")
.route(web::get().to(get_artist))
@@ -121,6 +127,7 @@ async fn list_artists(
id: a.id,
name: a.name.clone(),
musicbrainz_id: a.musicbrainz_id.clone(),
monitored: a.monitored,
total_watched,
total_owned,
total_items,
@@ -324,6 +331,8 @@ pub async fn enrich_artist(
added_at: chrono::Utc::now().naive_utc(),
top_songs: "[]".to_string(),
similar_artists: "[]".to_string(),
monitored: false,
last_checked_at: None,
};
(synthetic, None, mbid)
}
@@ -603,6 +612,7 @@ pub async fn enrich_artist(
"total_watched_tracks": total_artist_watched,
"total_owned_tracks": total_artist_owned,
"enriched": !skip_track_fetch,
"monitored": artist.monitored,
"artist_info": artist_info,
"artist_photo": artist_photo,
"artist_bio": artist_bio,
@@ -800,3 +810,33 @@ async fn delete_artist(
queries::artists::delete(state.db.conn(), id).await?;
Ok(HttpResponse::NoContent().finish())
}
async fn set_monitored(
state: web::Data<AppState>,
session: Session,
path: web::Path<i32>,
) -> Result<HttpResponse, ApiError> {
auth::require_auth(&session)?;
let id = path.into_inner();
let artist = queries::artists::set_monitored(state.db.conn(), id, true).await?;
Ok(HttpResponse::Ok().json(serde_json::json!({
"id": artist.id,
"name": artist.name,
"monitored": artist.monitored,
})))
}
async fn unset_monitored(
state: web::Data<AppState>,
session: Session,
path: web::Path<i32>,
) -> Result<HttpResponse, ApiError> {
auth::require_auth(&session)?;
let id = path.into_inner();
let artist = queries::artists::set_monitored(state.db.conn(), id, false).await?;
Ok(HttpResponse::Ok().json(serde_json::json!({
"id": artist.id,
"name": artist.name,
"monitored": artist.monitored,
})))
}