diff --git a/Cargo.lock b/Cargo.lock index ea16e9d..e32fa8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -239,6 +239,21 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "atoi" version = "2.0.0" @@ -336,6 +351,12 @@ dependencies = [ "alloc-stdlib", ] +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + [[package]] name = "byteorder" version = "1.5.0" @@ -373,6 +394,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets", +] + [[package]] name = "const-oid" version = "0.9.5" @@ -396,6 +431,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + [[package]] name = "cpufeatures" version = "0.2.11" @@ -816,6 +857,29 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "iana-time-zone" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" version = "0.5.0" @@ -860,6 +924,15 @@ dependencies = [ "libc", ] +[[package]] +name = "js-sys" +version = "0.3.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "language-tags" version = "0.3.2" @@ -1248,6 +1321,7 @@ name = "proje" version = "0.0.1" dependencies = [ "actix-web", + "chrono", "maud", "serde", "sqlx", @@ -2015,12 +2089,75 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.39", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" + [[package]] name = "whoami" version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22fc3756b8a9133049b26c7f61ab35416c130e8c09b660f5b3958b446f52cc50" +[[package]] +name = "windows-core" +version = "0.51.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index 121d18f..856f119 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" [dependencies] actix-web = "4.4.0" +chrono = "0.4.31" maud = { version = "0.25.0", features = [ "actix-web" ] } serde = { version = "1.0.192", features = [ "derive" ] } sqlx = { version = "0.7.3", features = ["sqlite", "runtime-tokio"] } diff --git a/src/main.rs b/src/main.rs index 45d7b86..857344d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,8 +19,8 @@ async fn main() -> io::Result<()> { sqlx::query( r" CREATE TABLE IF NOT EXISTS reminders ( - date TEXT, - message TEXT + date INTEGET NOT NULL, + message TEXT NOT NULL ) ", ) @@ -34,7 +34,7 @@ async fn main() -> io::Result<()> { .service(index::index) .service(submit::submit) .service(submit::submit_form) - .service(view::view); + .service(view::view) }) .bind(("127.0.0.1", 80))? .run() diff --git a/src/submit.rs b/src/submit.rs index 6a830a9..39ac863 100644 --- a/src/submit.rs +++ b/src/submit.rs @@ -3,6 +3,7 @@ use actix_web::web::{ Data, Query, }; +use chrono::NaiveDateTime; use maud::{ html, Markup, @@ -10,7 +11,6 @@ use maud::{ DOCTYPE, }; use sqlx::SqlitePool; - #[derive(Debug, serde::Deserialize)] pub struct Reminder { date: String, @@ -32,7 +32,11 @@ async fn submit_form( (?, ?) ", ) - .bind(reminder.date) + .bind( + NaiveDateTime::parse_from_str(&reminder.date, "%Y-%m-%dT%H:%M") + .unwrap() + .timestamp() as i64, + ) .bind(reminder.message) .execute(&**data) .await @@ -53,19 +57,13 @@ async fn submit() -> web::Result { Ok(html! { (DOCTYPE) form action="/submit-form" { - ul { - li class="li-button" { - button type="submit" { "Kaydet" } - } - li { - label for="date" { "Tarih:" } - input type="datetime-local" id="date" name="date"; - } - li { - label for="message" { "Mesaj:" } - input id="message" name="message"; - } - } + button type="submit" { "Kaydet" } + br; + label for="date" { "Tarih:" } + input type="datetime-local" id="date" name="date"; + br; + label for="message" { "Mesaj:" } + input id="message" name="message"; } }) } diff --git a/src/view.rs b/src/view.rs index f8cd24d..ad0be63 100644 --- a/src/view.rs +++ b/src/view.rs @@ -3,6 +3,7 @@ use actix_web::web::{ Data, Query, }; +use chrono::Local; use maud::{ html, Markup, @@ -10,16 +11,33 @@ use maud::{ }; use sqlx::SqlitePool; -#[web::get("/")] -async fn index(data: Data) -> web::Result { - sqlx::query_as::<(String, String)>( +#[web::get("/view")] +async fn view(data: Data) -> web::Result { + let reminders = sqlx::query_as::<_, (i64, String)>( r" - TODO + SELECT + * + FROM + reminders + WHERE + date > ? ", - ); + ) + .bind(Local::now().timestamp() as i64) + .fetch_all(&**data) + .await + .expect("Failed to fetch reminder."); + println!("{reminders:?}"); Ok(html! { (DOCTYPE) - h1 { "Hello, World!" } + ul { + @for reminder in reminders { + li { + h3 { (reminder.0) } + p { (reminder.1) } + } + } + } }) }