Compare commits

..

No commits in common. "a3a4ae8ca4816f0705110204b722c763dcc3e3a4" and "de5d256c9622af173b5c316478112338ec1e8483" have entirely different histories.

3 changed files with 10 additions and 36 deletions

View File

@ -90,12 +90,8 @@ pub enum SnapshotSubcommands {
/// Show a snapshot.
Show {
/// The date of the snapshot to show, defaults to today.
#[clap(short, long, group = "selection")]
#[clap(short, long)]
date: Option<NaiveDate>,
/// The ID of the snapshot to show.
#[clap(long, group = "selection")]
id: Option<i64>,
},
}

View File

@ -58,27 +58,18 @@ pub async fn run() -> Result<()> {
}
}
SnapshotSubcommands::Show { date, id } => {
SnapshotSubcommands::Show { date } => {
let date = date.unwrap_or_else(today);
let snapshot = match id {
Some(id) => SnapshotModel::get_by_id(&db, id).await,
None => SnapshotModel::get_by_date(&db, date).await,
}?;
let snapshot = match (snapshot, id) {
(None, Some(id)) => {
info!("No snapshot exists for id {id}");
let snapshot = if let Some(snapshot) =
SnapshotModel::get_by_date(&db, date).await?
{
info!("Snapshot {snapshot:?}");
snapshot
} else {
info!("No snapshot exists for {date}");
return Ok(());
}
(None, None) => {
info!("No snapshot exists for date {date}");
return Ok(());
}
(Some(snapshot), _) => snapshot,
};
info!("Snapshot {snapshot:?}");
for group in GroupDataModel::get_all_by_snapshot(&db, &snapshot).await?
{
info!(

View File

@ -27,19 +27,6 @@ impl SnapshotModel {
Ok(existing)
}
/// Get a snapshot by a given ID.
pub async fn get_by_id(
db: &DatabaseConnection,
id: i64,
) -> Result<Option<Self>> {
let snapshot = SnapshotEntity::find()
.filter(SnapshotColumn::Id.eq(id))
.one(db)
.await?;
Ok(snapshot)
}
/// Get all snapshots.
pub async fn get_all(db: &DatabaseConnection) -> Result<Vec<Self>> {
let snapshots = SnapshotEntity::find().all(db).await?;