ticker-serve: select starting today
This commit is contained in:
parent
a9ed009cad
commit
72349760eb
|
@ -1706,6 +1706,7 @@ dependencies = [
|
||||||
name = "ticker-serve"
|
name = "ticker-serve"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
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)",
|
"diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libticker 0.1.0",
|
"libticker 0.1.0",
|
||||||
"rocket 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rocket 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -22,3 +22,4 @@ CREATE TABLE events (
|
||||||
location TEXT,
|
location TEXT,
|
||||||
url TEXT
|
url TEXT
|
||||||
);
|
);
|
||||||
|
CREATE index events_dtstart_dtend ON events (dtstart, dtend);
|
||||||
|
|
|
@ -8,4 +8,5 @@ edition = "2018"
|
||||||
rocket = "0.4"
|
rocket = "0.4"
|
||||||
typed-html = "0.2"
|
typed-html = "0.2"
|
||||||
diesel = { version = "~1", features = ["postgres", "chrono"] }
|
diesel = { version = "~1", features = ["postgres", "chrono"] }
|
||||||
|
chrono = "~0.4"
|
||||||
libticker = { path = "../libticker" }
|
libticker = { path = "../libticker" }
|
||||||
|
|
|
@ -7,6 +7,7 @@ use std::sync::Mutex;
|
||||||
use rocket::{State, response::content};
|
use rocket::{State, response::content};
|
||||||
use typed_html::{html, text, dom::DOMTree};
|
use typed_html::{html, text, dom::DOMTree};
|
||||||
use diesel::{Connection, pg::PgConnection, prelude::*};
|
use diesel::{Connection, pg::PgConnection, prelude::*};
|
||||||
|
use chrono::offset::Local;
|
||||||
|
|
||||||
use libticker::{
|
use libticker::{
|
||||||
config::{Config, CalendarOptions},
|
config::{Config, CalendarOptions},
|
||||||
|
@ -26,7 +27,9 @@ fn fix_url(s: &str) -> std::borrow::Cow<str> {
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index(db: State<Mutex<PgConnection>>) -> content::Html<String> {
|
fn index(db: State<Mutex<PgConnection>>) -> content::Html<String> {
|
||||||
let db = db.lock().unwrap();
|
let db = db.lock().unwrap();
|
||||||
|
let today = Local::today().naive_local().and_hms(0, 0, 0);
|
||||||
let es = events
|
let es = events
|
||||||
|
.filter(schema::events::dtstart.ge(&today))
|
||||||
.order_by(schema::events::dtstart.asc())
|
.order_by(schema::events::dtstart.asc())
|
||||||
.then_order_by(schema::events::dtend.desc())
|
.then_order_by(schema::events::dtend.desc())
|
||||||
.load::<Event>(&*db)
|
.load::<Event>(&*db)
|
||||||
|
|
Loading…
Reference in New Issue