36 lines
909 B
Rust
36 lines
909 B
Rust
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(())
|
|
}
|