From c44c89005c03e5f503700156ceafe550e3d5db27 Mon Sep 17 00:00:00 2001
From: Joe Ardent
+Hello, {{ usr.username }}! It's nice to see you.
+ Here are your things to watch:
+
Date: Thu, 8 Jun 2023 15:45:34 -0700
Subject: [PATCH] add working endpoints for getting your watches
---
src/lib.rs | 8 +++-
src/watches/handlers.rs | 29 +++++++++++++--
src/watches/mod.rs | 6 +++
src/watches/templates.rs | 10 +++++
...get_watches.rs => get_search_watches.html} | 0
templates/get_watches.html | 37 +++++++++++++++++++
templates/index.html | 2 +-
templates/macros.html | 10 +++++
8 files changed, 97 insertions(+), 5 deletions(-)
rename templates/{get_watches.rs => get_search_watches.html} (100%)
create mode 100644 templates/get_watches.html
create mode 100644 templates/macros.html
diff --git a/src/lib.rs b/src/lib.rs
index 87f46a3..ccba9a6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -20,7 +20,10 @@ pub(crate) mod util;
pub mod watches;
pub use templates::*;
pub use watches::templates::*;
-use watches::{ShowKind, Watch};
+use watches::{
+ handlers::{get_search_watch, get_watches, post_search_watch, put_add_watch},
+ ShowKind, Watch,
+};
#[cfg(test)]
pub mod test_utils;
@@ -37,6 +40,9 @@ pub async fn app(db_pool: SqlitePool, secret: &[u8]) -> Router {
.route("/signup_success/:id", get(handle_signup_success))
.route("/login", get(get_login).post(post_login))
.route("/logout", get(get_logout).post(post_logout))
+ .route("/watches", get(get_watches))
+ .route("/search", get(get_search_watch).post(post_search_watch))
+ .route("/add", get(get_search_watch).put(put_add_watch))
.fallback(handle_slash_redir)
.layer(middleware::from_fn_with_state(
db_pool.clone(),
diff --git a/src/watches/handlers.rs b/src/watches/handlers.rs
index 2676320..bc103ad 100644
--- a/src/watches/handlers.rs
+++ b/src/watches/handlers.rs
@@ -6,7 +6,14 @@ use axum::{
use sqlx::{query_as, SqlitePool};
use uuid::Uuid;
-use crate::{ShowKind, User, Watch};
+use crate::{AuthContext, GetWatches, ShowKind, User, Watch};
+
+//-************************************************************************
+// Constants
+//-************************************************************************
+
+const GET_WATCHES_QUERY: &str =
+ "select * from watches left join witch_watch on $1 = witch_watch.witch and watches.id = witch_watch.watch";
//-************************************************************************
// Error types for Watch creation
@@ -32,13 +39,29 @@ impl IntoResponse for WatchAddError {
}
/// Add a Watch to the whole system
-pub async fn post_add_watch() {}
+pub async fn put_add_watch() {}
/// A single Watch
pub async fn get_watch() {}
/// everything the user has saved
-pub async fn get_watches() {}
+pub async fn get_watches(auth: AuthContext, State(pool): State
Whatcha Watchin?
+
+{% match user %}
+ {% when Some with (usr) %}
+
+ {% for watch in watches %}
+
+
+ Heya, why don't you log in or sign up? +
+{% endmatch %} + +{% endblock %} diff --git a/templates/index.html b/templates/index.html index e7c47f2..92c44f3 100644 --- a/templates/index.html +++ b/templates/index.html @@ -9,7 +9,7 @@ {% match user %} {% when Some with (usr) %}-Hello, {{ usr.username }}! It's nice to see you. + Hello, {{ usr.username }}! It's nice to see you. Let's get watchin'!
diff --git a/templates/macros.html b/templates/macros.html new file mode 100644 index 0000000..78ce461 --- /dev/null +++ b/templates/macros.html @@ -0,0 +1,10 @@ +{% macro get_or_default(val, def) %} + +{% match val %} +{% when Some with (v) %} +{{v}} +{% else %} +{{def}} +{% endmatch %} + +{% endmacro %}