Add a album auto-create command
This commit is contained in:
parent
998bfce68f
commit
0ac02c34c6
14 changed files with 323 additions and 2 deletions
68
src/actions/create_album.rs
Normal file
68
src/actions/create_album.rs
Normal file
|
@ -0,0 +1,68 @@
|
|||
use chrono::Utc;
|
||||
use color_eyre::eyre::Result;
|
||||
use log::info;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
context::Context,
|
||||
models::{album::Album, asset::Asset},
|
||||
types::CreateAlbumDto,
|
||||
};
|
||||
|
||||
use super::action::Action;
|
||||
|
||||
pub struct CreateAlbum {
|
||||
name: String,
|
||||
assets: Vec<Asset>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct CreateAlbumArgs {
|
||||
pub name: String,
|
||||
pub assets: Vec<Asset>,
|
||||
}
|
||||
|
||||
impl Action for CreateAlbum {
|
||||
type Input = CreateAlbumArgs;
|
||||
type Output = Album;
|
||||
|
||||
fn new(input: Self::Input) -> Self {
|
||||
Self {
|
||||
name: input.name,
|
||||
assets: input.assets,
|
||||
}
|
||||
}
|
||||
|
||||
fn describe(&self) -> String {
|
||||
format!(
|
||||
"Creating album {} with {} assets",
|
||||
self.name,
|
||||
self.assets.len()
|
||||
)
|
||||
}
|
||||
|
||||
async fn execute(&self, ctx: &Context) -> Result<Self::Output> {
|
||||
info!("{}", self.describe());
|
||||
|
||||
if !ctx.dry_run {
|
||||
Ok(ctx
|
||||
.client
|
||||
.create_album(&CreateAlbumDto {
|
||||
album_name: self.name.clone(),
|
||||
asset_ids: self.assets.iter().map(|asset| asset.id).collect(),
|
||||
album_users: vec![],
|
||||
description: None,
|
||||
})
|
||||
.await?
|
||||
.clone()
|
||||
.into())
|
||||
} else {
|
||||
Ok(Album {
|
||||
id: Uuid::new_v4(),
|
||||
name: self.name.clone(),
|
||||
assets_count: self.assets.len() as u32,
|
||||
updated_at: Utc::now(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue