ticker-serve: select starting today

This commit is contained in:
Astro 2019-10-26 01:57:31 +02:00
parent a9ed009cad
commit 72349760eb
4 changed files with 6 additions and 0 deletions

1
Cargo.lock generated
View File

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

View File

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

View File

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

View File

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