Add showing snapshots by ID.
This commit is contained in:
parent
de5d256c96
commit
9ec3b1c07d
|
@ -90,8 +90,12 @@ pub enum SnapshotSubcommands {
|
||||||
/// Show a snapshot.
|
/// Show a snapshot.
|
||||||
Show {
|
Show {
|
||||||
/// The date of the snapshot to show, defaults to today.
|
/// The date of the snapshot to show, defaults to today.
|
||||||
#[clap(short, long)]
|
#[clap(short, long, group = "selection")]
|
||||||
date: Option<NaiveDate>,
|
date: Option<NaiveDate>,
|
||||||
|
|
||||||
|
/// The ID of the snapshot to show.
|
||||||
|
#[clap(long, group = "selection")]
|
||||||
|
id: Option<i64>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,16 +58,24 @@ pub async fn run() -> Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SnapshotSubcommands::Show { date } => {
|
SnapshotSubcommands::Show { date, id } => {
|
||||||
let date = date.unwrap_or_else(today);
|
let date = date.unwrap_or_else(today);
|
||||||
let snapshot = if let Some(snapshot) =
|
|
||||||
SnapshotModel::get_by_date(&db, date).await?
|
let snapshot = match id {
|
||||||
{
|
Some(id) => SnapshotModel::get_by_id(&db, id).await,
|
||||||
info!("Snapshot {snapshot:?}");
|
None => SnapshotModel::get_by_date(&db, date).await,
|
||||||
snapshot
|
}?;
|
||||||
} else {
|
|
||||||
info!("No snapshot exists for {date}");
|
let snapshot = match (snapshot, id) {
|
||||||
|
(None, Some(id)) => {
|
||||||
|
info!("No snapshot exists for id {id}");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
}
|
||||||
|
(None, None) => {
|
||||||
|
info!("No snapshot exists for date {date}");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
(Some(snapshot), _) => snapshot,
|
||||||
};
|
};
|
||||||
|
|
||||||
for group in GroupDataModel::get_all_by_snapshot(&db, &snapshot).await?
|
for group in GroupDataModel::get_all_by_snapshot(&db, &snapshot).await?
|
||||||
|
|
|
@ -27,6 +27,19 @@ impl SnapshotModel {
|
||||||
Ok(existing)
|
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.
|
/// Get all snapshots.
|
||||||
pub async fn get_all(db: &DatabaseConnection) -> Result<Vec<Self>> {
|
pub async fn get_all(db: &DatabaseConnection) -> Result<Vec<Self>> {
|
||||||
let snapshots = SnapshotEntity::find().all(db).await?;
|
let snapshots = SnapshotEntity::find().all(db).await?;
|
||||||
|
|
Loading…
Reference in New Issue