42 lines
992 B
Rust
42 lines
992 B
Rust
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)
|
|
}
|
|
}
|