Add a album auto-create command

This commit is contained in:
Marc Plano-Lesay 2024-12-03 16:32:05 +11:00
parent 998bfce68f
commit 0ac02c34c6
Signed by: kernald
GPG key ID: 66A41B08CC62A6CF
14 changed files with 323 additions and 2 deletions

View file

@ -0,0 +1,42 @@
use color_eyre::eyre::Result;
use crate::{
context::Context,
models::{asset::Asset, library::Library},
utils::assets::{fetch_all_assets, AssetQuery},
};
use super::action::Action;
pub struct FetchLibraryAssets {
library: Library,
}
impl Action for FetchLibraryAssets {
type Input = Library;
type Output = Vec<Asset>;
fn new(input: Self::Input) -> Self {
Self { library: input }
}
fn describe(&self) -> String {
// TODO: derive Display for Library and use this here
format!("Fetching all assets for library {}", self.library.name)
}
async fn execute(&self, ctx: &Context) -> Result<Self::Output> {
let query = AssetQuery {
library: Some(self.library.clone()),
..Default::default()
};
let assets: Vec<_> = fetch_all_assets(query, &ctx.client)
.await?
.into_iter()
.map(Asset::from)
.collect();
Ok(assets)
}
}