Add API method to easiliy tick a track now

This commit is contained in:
D. Scott Boggs 2023-06-17 13:20:08 -04:00
parent e2efd6fe66
commit c85af82eb7
4 changed files with 72 additions and 10 deletions

View file

@ -1,5 +1,8 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
use std::default::default;
use chrono::{Datelike, Timelike, Utc};
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
@ -37,3 +40,26 @@ impl Related<super::tracks::Entity> for Entity {
}
impl ActiveModelBehavior for ActiveModel {}
impl ActiveModel {
pub(crate) fn now(track_id: i32) -> Self {
use sea_orm::ActiveValue::Set;
let now = Utc::now();
Self {
track_id: Set(Some(track_id)),
year: Set(Some(now.year())),
month: Set(now.month().try_into().ok()),
/* ^^^^^^^^^^^^^^^^^^^^^^^
* I can't imagine a situation where this doesn't fit. This way, at
* least, if it fails, you just get a messed up database entry that
* doesn't do anything bad
*/
day: Set(now.day().try_into().ok()),
hour: Set(now.hour().try_into().ok()),
minute: Set(now.minute().try_into().ok()),
second: Set(now.second().try_into().ok()),
has_time_info: Set(Some(1)),
..default()
}
}
}