Add button to add 5 minutes to session start time
This commit is contained in:
@ -47,6 +47,7 @@ fn main() -> io::Result<()> {
|
||||
routes::api::create_category,
|
||||
routes::api::start_session,
|
||||
routes::api::end_session,
|
||||
routes::api::bump_session,
|
||||
routes::api::delete_session,
|
||||
],
|
||||
);
|
||||
|
||||
@ -52,6 +52,36 @@ pub fn end_session(
|
||||
toggle_category_session(category_uuid, false, db)
|
||||
}
|
||||
|
||||
#[post("/category/<category_uuid>/bump_session/minutes/<minutes>")]
|
||||
pub fn bump_session(
|
||||
category_uuid: String,
|
||||
minutes: i64,
|
||||
db: State<'_, sled::Db>,
|
||||
) -> Result<Redirect, StatusJson> {
|
||||
let duration = Duration::minutes(minutes);
|
||||
let category_uuid = Uuid::parse_str(&category_uuid)?;
|
||||
let category_uuid_s = sled::IVec::from(serialize(&category_uuid)?);
|
||||
|
||||
let categories_tree = db.open_tree(categories::NAME)?;
|
||||
|
||||
Ok((&categories_tree).transaction(|tx_categories| {
|
||||
match tx_categories.get(&category_uuid_s)? {
|
||||
None => return Ok(Err(Status::NotFound.into())),
|
||||
Some(data) => {
|
||||
let mut category: categories::V = deserialize(&data).unwrap();
|
||||
match category.started.as_mut() {
|
||||
Some(started) => {
|
||||
*started -= duration;
|
||||
tx_categories.insert(&category_uuid_s, serialize(&category).unwrap())?;
|
||||
Ok(Ok(Redirect::to(uri!(pages::index))))
|
||||
}
|
||||
None => return Ok(Err(StatusJson::new(Status::BadRequest, "No active session"))),
|
||||
}
|
||||
}
|
||||
}
|
||||
})??)
|
||||
}
|
||||
|
||||
pub fn toggle_category_session(
|
||||
category_uuid: String,
|
||||
set_active: bool,
|
||||
|
||||
Reference in New Issue
Block a user