Browse Source

ticker-serve: select starting today

master
Astro 2 years ago
parent
commit
72349760eb
  1. 1
      Cargo.lock
  2. 1
      schema.sql
  3. 1
      ticker-serve/Cargo.toml
  4. 3
      ticker-serve/src/main.rs

1
Cargo.lock

@ -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)",

1
schema.sql

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

1
ticker-serve/Cargo.toml

@ -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" }

3
ticker-serve/src/main.rs

@ -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)

Loading…
Cancel
Save