Add a command to list albums

This commit is contained in:
Marc Plano-Lesay 2024-11-24 01:32:17 +01:00
parent af1af8dce1
commit fb78298166
Signed by: kernald
GPG key ID: 66A41B08CC62A6CF
5 changed files with 61 additions and 1 deletions

View file

@ -0,0 +1,35 @@
use crate::{
actions::{action::Action, fetch_all_albums::FetchAllAlbums},
context::Context,
};
use chrono::{DateTime, Utc};
use color_eyre::eyre::Result;
use tabled::{settings::Style, Table, Tabled};
#[derive(Tabled)]
struct Album {
#[tabled(rename = "Name")]
name: String,
#[tabled(rename = "Assets count")]
assets_count: u32,
#[tabled(rename = "Updated at")]
updated_at: DateTime<Utc>,
}
pub async fn list_albums(ctx: Context) -> Result<()> {
let mut albums: Vec<_> = FetchAllAlbums::new(())
.execute(&ctx)
.await?
.into_iter()
.map(|album| Album {
name: album.name,
updated_at: album.updated_at,
assets_count: album.assets_count,
})
.collect();
albums.sort_by_key(|album| album.name.to_lowercase());
println!("{}", Table::new(albums).with(Style::rounded()),);
Ok(())
}