From ad738296a0e70289f1fdba56abede7436565597f Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Sat, 4 Jul 2020 09:30:50 +0200 Subject: [PATCH] Remove changes to NewQuery --- server/service/src/main.rs | 59 +++++++++++++---------------- server/ui/src/components/navbar.tsx | 4 +- 2 files changed, 28 insertions(+), 35 deletions(-) diff --git a/server/service/src/main.rs b/server/service/src/main.rs index 4debadc..1767da9 100644 --- a/server/service/src/main.rs +++ b/server/service/src/main.rs @@ -35,7 +35,7 @@ enum SortKey { impl Default for SortKey { fn default() -> Self { - Self::Name + Self::Scraped } } @@ -119,14 +119,10 @@ async fn search( Ok(res) } -// TODO what is NewQuery used for? -// it is not a file search, that is done through SearchQuery #[derive(Deserialize)] struct NewQuery { page: Option, size: Option, - sort_key: Option, - sort_dir: Option, type_: Option, } @@ -134,7 +130,6 @@ async fn new_torrents( db: web::Data>, query: web::Query, ) -> Result { - let res = web::block(move || { let conn = db.get().unwrap(); new_query(query, conn) @@ -148,29 +143,6 @@ async fn new_torrents( Ok(res) } -fn build_order_clause(type_: &str, sort_key: SortKey, sort_dir: SortDirection) -> String { - let dir = match sort_dir { - SortDirection::Asc => "asc", - SortDirection::Desc => "desc", - }; - - let column = match sort_key { - SortKey::Name => { - if type_ == "file" { - "path" - } else { - "name" - } - }, - SortKey::Size => "size_bytes", - SortKey::Seeds => "seeders", - SortKey::Leeches => "leechers", - SortKey::Scraped => "scraped_date", - }; - - format!("{} {}", column, dir) -} - fn search_query( query: web::Query, conn: r2d2::PooledConnection, @@ -211,14 +183,12 @@ fn new_query( let page = query.page.unwrap_or(1); let size = cmp::min(100, query.size.unwrap_or(DEFAULT_SIZE)); - let sort_key = query.sort_key.unwrap_or_default(); - let sort_dir = query.sort_dir.unwrap_or_default(); let type_ = query.type_.as_ref().map_or("torrent", String::deref); let offset = size * (page - 1); println!( - "new, type = {}, page = {}, size = {}, sort_key = {:?}, sort_dir = {:?}", - type_, page, size, sort_key, sort_dir + "new, type = {}, page = {}, size = {}", + type_, page, size ); let res = if type_ == "file" { @@ -405,6 +375,29 @@ fn torrent_file_new( Ok(files) } +fn build_order_clause(type_: &str, sort_key: SortKey, sort_dir: SortDirection) -> String { + let dir = match sort_dir { + SortDirection::Asc => "asc", + SortDirection::Desc => "desc", + }; + + let column = match sort_key { + SortKey::Name => { + if type_ == "file" { + "path" + } else { + "name" + } + }, + SortKey::Size => "size_bytes", + SortKey::Seeds => "seeders", + SortKey::Leeches => "leechers", + SortKey::Scraped => "scraped_date", + }; + + format!("{} {}", column, dir) +} + #[cfg(test)] mod tests { use r2d2_sqlite::SqliteConnectionManager; diff --git a/server/ui/src/components/navbar.tsx b/server/ui/src/components/navbar.tsx index fde4884..95139ba 100644 --- a/server/ui/src/components/navbar.tsx +++ b/server/ui/src/components/navbar.tsx @@ -53,7 +53,7 @@ export class Navbar extends Component { value={this.state.searchParams.q} onInput={linkEvent(this, this.searchChange)}>
-