From 3be1c7f2036a7833f1cc2a71ba8ecf145450bd34 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 8 Jul 2020 18:58:28 +0200 Subject: [PATCH] Can create countdown timers --- src/controllers/posts_controller.rs | 10 ++++++++++ src/helpers/posts_helper.rs | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/controllers/posts_controller.rs b/src/controllers/posts_controller.rs index 83d34d3..bc34eaa 100644 --- a/src/controllers/posts_controller.rs +++ b/src/controllers/posts_controller.rs @@ -184,6 +184,16 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult { PostKind::POST_KIND_PDF(PostFile::new_from_created_file(&file)?) } + "countdown" => { + let time_end = r.post_u64("time-end")?; + + if time_end < time() { + r.bad_request("You can not create countdown timer for past events!".to_string())?; + } + + PostKind::POST_KIND_COUNTDOWN(time_end) + } + // TODO : add support for next types _ => { diff --git a/src/helpers/posts_helper.rs b/src/helpers/posts_helper.rs index da400cc..2011fb4 100644 --- a/src/helpers/posts_helper.rs +++ b/src/helpers/posts_helper.rs @@ -104,9 +104,13 @@ pub fn create(p: &Post) -> ResultBoxError { .add_opt_str("image_page", weblink.image.as_ref()); } + // Countdown timer + POST_KIND_COUNTDOWN(count_down) => { + insert_query = insert_query.add_u64("time_end", *count_down); + } + _ => unimplemented!() /* - POST_KIND_COUNTDOWN(_) => {}, POST_KIND_SURVEY => {}, */ }