simplify search, sketch out search-branches.
This commit is contained in:
parent
4e2e8e585f
commit
a45ca8d3a5
2 changed files with 39 additions and 45 deletions
|
@ -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<String>,
|
||||
#[serde(default, deserialize_with = "empty_string_as_none")]
|
||||
pub title: Option<String>,
|
||||
#[serde(default, deserialize_with = "empty_string_as_none")]
|
||||
pub kind: Option<String>,
|
||||
#[serde(default, deserialize_with = "empty_string_as_none")]
|
||||
pub year: Option<String>,
|
||||
#[serde(default, deserialize_with = "empty_string_as_none")]
|
||||
pub person: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn get_search_watch(
|
||||
auth: AuthSession,
|
||||
State(pool): State<SqlitePool>,
|
||||
search: Query<SearchQuery>,
|
||||
Query(search): Query<SearchQuery>,
|
||||
) -> impl IntoResponse {
|
||||
let user = auth.user;
|
||||
let search_query = search.0;
|
||||
let SearchQuery {
|
||||
title,
|
||||
year,
|
||||
person,
|
||||
} = &search;
|
||||
|
||||
let watches: Vec<Watch> = if let Some(title) = search_query.title {
|
||||
sqlx::query_as(
|
||||
let watches: Vec<Watch> = 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 {
|
||||
|
|
|
@ -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 %}
|
||||
|
||||
<h1>Whatcha Watchin?</h1>
|
||||
|
||||
<div class="fullsearch">
|
||||
<form action="/search" enctype="application/x-www-form-urlencoded" method="get">
|
||||
<h2>Search</h2>
|
||||
|
||||
<label for="title">Title</label>
|
||||
<input type="text" name="title" id="title-search"></br>
|
||||
|
||||
<label for="year">Release Year</label>
|
||||
<input type="text" name="year" id="title-year-search"></br>
|
||||
|
||||
<hr>
|
||||
|
||||
<label for="person">Person</label>
|
||||
<input type="text" name="person" id="person-search"></br>
|
||||
|
||||
<input type="submit" value="Let's go!">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
|
||||
<div class="watchlist">
|
||||
<table>
|
||||
<thead>
|
||||
|
@ -23,39 +45,6 @@
|
|||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<hr />
|
||||
</div>
|
||||
|
||||
<h2>Simple Search</h2>
|
||||
<div class="simplesearch">
|
||||
<form action="/search" enctype="application/x-www-form-urlencoded" method="get">
|
||||
<label for="search">Looking for something else to watch?</label>
|
||||
<input type="text" name="search" id="search"></br>
|
||||
<input type="submit" value="Let's go!">
|
||||
</div>
|
||||
|
||||
<h2>Fussy Search</h2>
|
||||
<div class="fullsearch">
|
||||
<label for="title">Title</label>
|
||||
<input type="text" name="title" id="title"></br>
|
||||
|
||||
<label for="year">Release Year</label>
|
||||
<input type="text" name="year" id="year"></br>
|
||||
|
||||
<label for="kind">Type</label>
|
||||
<select id="kind" name="kind">
|
||||
<option value="">Unknown</option>
|
||||
<option value="0">Movie</option>
|
||||
<option value="1">Series</option>
|
||||
<option value="2">Limited Series</option>
|
||||
<option value="3">Short</option>
|
||||
<option value="4">Other</option>
|
||||
</select>
|
||||
|
||||
<input type="submit" value="Let's go!">
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue