simplify search more and add more convenience views.

This commit is contained in:
Joe Ardent 2024-04-14 11:00:12 -07:00
parent 0e170c0428
commit 4d8706d6bf
3 changed files with 9 additions and 15 deletions

View File

@ -1,4 +1,5 @@
create view if not exists w as select julid_string(id) id, kind, title, metadata_url, length, release_date, last_updated from watches;
create view if not exists s as select julid_string(id) id, name, born, died from stars;
create view if not exists u as select julid_string(id) id, username, displayname, email, last_seen, last_updated from users;
create view if not exists i as select julid_string(id) id, julid_string(owner) owner, expires_at, remaining, last_updated from invites;
create view if not exists i as select julid_string(invites.id) id, users.username, expires_at, remaining, invites.last_updated from invites inner join users on users.id = owner;
create view if not exists q as select users.username, watches.title from watch_quests inner join users on users.id = user inner join watches on watch = watches.id;

View File

@ -6,6 +6,7 @@ pub async fn handle_slash_redir() -> impl IntoResponse {
Redirect::to("/")
}
#[axum::debug_handler]
pub async fn handle_slash(auth: AuthSession) -> impl IntoResponse {
if let Some(ref user) = auth.user {
let name = &user.username;

View File

@ -29,8 +29,6 @@ pub struct SearchQuery {
pub title: 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(
@ -39,20 +37,14 @@ pub async fn get_search_watch(
Query(search): Query<SearchQuery>,
) -> impl IntoResponse {
let user = auth.user;
let SearchQuery {
title,
year,
person,
} = &search;
let SearchQuery { title, year } = &search;
let watches: Vec<Watch> = match (title, year, person) {
(Some(title), None, None) => sqlx::query_as(
let watches: Vec<Watch> = match (title, year) {
(Some(title), 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(),
(Some(title), Some(year), None) => {todo!()},
(None, Some(year), None) => {todo!()},
(None, Some(year), Some(person)) => {todo!()},
(Some(title), Some(year), Some(person)) => {todo!()}
title.trim()).fetch_all(&pool).await.unwrap_or_default(),
(Some(title), Some(year)) => sqlx::query_as("select * from watches where id in (select id from watch_search where title match ? order by rank) and release_date = ?").bind(title.trim()).bind(year.trim()).fetch_all(&pool).await.unwrap_or_default(),
(None, Some(year)) => sqlx::query_as("select * from watches where release_date = ? order by title").bind(year.trim()).fetch_all(&pool).await.unwrap_or_default(),
_ => 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()
};