Browse Source

ticker-serve: select starting today

master
Astro 1 year ago
parent
commit
72349760eb
4 changed files with 6 additions and 0 deletions
  1. 1
    0
      Cargo.lock
  2. 1
    0
      schema.sql
  3. 1
    0
      ticker-serve/Cargo.toml
  4. 3
    0
      ticker-serve/src/main.rs

+ 1
- 0
Cargo.lock View File

@@ -1706,6 +1706,7 @@ dependencies = [
1706 1706
 name = "ticker-serve"
1707 1707
 version = "0.1.0"
1708 1708
 dependencies = [
1709
+ "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
1709 1710
  "diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
1710 1711
  "libticker 0.1.0",
1711 1712
  "rocket 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",

+ 1
- 0
schema.sql View File

@@ -22,3 +22,4 @@ CREATE TABLE events (
22 22
        location TEXT,
23 23
        url TEXT
24 24
 );
25
+CREATE index events_dtstart_dtend ON events (dtstart, dtend);

+ 1
- 0
ticker-serve/Cargo.toml View File

@@ -8,4 +8,5 @@ edition = "2018"
8 8
 rocket = "0.4"
9 9
 typed-html = "0.2"
10 10
 diesel = { version = "~1", features = ["postgres", "chrono"] }
11
+chrono = "~0.4"
11 12
 libticker = { path = "../libticker" }

+ 3
- 0
ticker-serve/src/main.rs View File

@@ -7,6 +7,7 @@ use std::sync::Mutex;
7 7
 use rocket::{State, response::content};
8 8
 use typed_html::{html, text, dom::DOMTree};
9 9
 use diesel::{Connection, pg::PgConnection, prelude::*};
10
+use chrono::offset::Local;
10 11
 
11 12
 use libticker::{
12 13
     config::{Config, CalendarOptions},
@@ -26,7 +27,9 @@ fn fix_url(s: &str) -> std::borrow::Cow<str> {
26 27
 #[get("/")]
27 28
 fn index(db: State<Mutex<PgConnection>>) -> content::Html<String> {
28 29
     let db = db.lock().unwrap();
30
+    let today = Local::today().naive_local().and_hms(0, 0, 0);
29 31
     let es = events
32
+        .filter(schema::events::dtstart.ge(&today))
30 33
         .order_by(schema::events::dtstart.asc())
31 34
         .then_order_by(schema::events::dtend.desc())
32 35
         .load::<Event>(&*db)

Loading…
Cancel
Save