diff --git a/src/search.rs b/src/search.rs index bb1f3eb..f207a96 100644 --- a/src/search.rs +++ b/src/search.rs @@ -25,30 +25,35 @@ pub enum SearchResult { #[derive(Debug, Default, Clone, Deserialize, PartialEq, Eq)] pub struct SearchQuery { - #[serde(default, deserialize_with = "empty_string_as_none")] - pub search: Option, #[serde(default, deserialize_with = "empty_string_as_none")] pub title: Option, #[serde(default, deserialize_with = "empty_string_as_none")] - pub kind: Option, - #[serde(default, deserialize_with = "empty_string_as_none")] pub year: Option, + #[serde(default, deserialize_with = "empty_string_as_none")] + pub person: Option, } pub async fn get_search_watch( auth: AuthSession, State(pool): State, - search: Query, + Query(search): Query, ) -> impl IntoResponse { let user = auth.user; - let search_query = search.0; + let SearchQuery { + title, + year, + person, + } = &search; - let watches: Vec = if let Some(title) = search_query.title { - sqlx::query_as( + let watches: Vec = match (title, year, person) { + (Some(title), None, None) => sqlx::query_as( "select * from watches where id in (select id from watch_search where title match ? order by rank)").bind( - &title).fetch_all(&pool).await.unwrap_or_default() - } else { - sqlx::query_as("select * from (select * from watches order by random() limit 50) order by release_date asc").fetch_all(&pool).await.unwrap_or_default() + title).fetch_all(&pool).await.unwrap_or_default(), + (Some(title), Some(year), None) => {todo!()}, + (None, Some(year), None) => {todo!()}, + (None, Some(year), Some(person)) => {todo!()}, + (Some(title), Some(year), Some(person)) => {todo!()} + _ => sqlx::query_as("select * from (select * from watches order by random() limit 50) order by release_date asc").fetch_all(&pool).await.unwrap_or_default() }; SearchPage { diff --git a/templates/search_watches_page.html b/templates/search_watches_page.html index f87f31a..17ca328 100644 --- a/templates/search_watches_page.html +++ b/templates/search_watches_page.html @@ -1,11 +1,33 @@ {% extends "base.html" %} {% import "macros.html" as m %} -{% block title %}Welcome to What 2 Watch, Bish{% endblock %} +{% block title %}Welcome to What 2 Watch, Buddy{% endblock %} {% block content %}

Whatcha Watchin?

+ +
+
+

Search

+ + +
+ + +
+ +
+ + +
+ + +
+
+ +
+
@@ -23,39 +45,6 @@ {% endfor %}
-
-
- -

Simple Search

-
-
- -
- -
- -

Fussy Search

-
- -
- - -
- - - - - - - -
{% endblock %}