From f5ed0ce8ffe051d189ebe2b635380586a56a728b Mon Sep 17 00:00:00 2001 From: AzerothA Date: Sat, 27 Jan 2024 13:48:37 +0330 Subject: [PATCH] Nothing changed --- src/models_filter.rs | 83 ++++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 29 deletions(-) diff --git a/src/models_filter.rs b/src/models_filter.rs index 6dd293f..4fa8058 100644 --- a/src/models_filter.rs +++ b/src/models_filter.rs @@ -223,38 +223,63 @@ impl Filter for Translation { let mut _query = translations_table.into_boxed(); - _query = match filters.sort() { + match filters.sort() { Some(sort_str) => match sort_str.as_str() { - "createTime" => Ok(match filters.order().unwrap_or_default() { - Order::Asc => translations.order(created_at.asc()).internal_into_boxed(), - Order::Desc => translations.order(created_at.desc()).internal_into_boxed(), - }), - - "updateTime" => Ok(match filters.order().unwrap_or_default() { - Order::Asc => translations.order(updated_at.asc()).internal_into_boxed(), - Order::Desc => translations.order(updated_at.desc()).internal_into_boxed(), - }), - - "language" => Ok(match filters.order().unwrap_or_default() { - Order::Asc => translations.order(language.asc()).internal_into_boxed(), - Order::Desc => translations.order(language.desc()).internal_into_boxed(), - }), - - // TODO: This is not working the way we want - // must order the mushaf by mushaf_name - "mushaf" => Ok(match filters.order().unwrap_or_default() { - Order::Asc => translations.order(mushaf_id.asc()).internal_into_boxed(), - Order::Desc => translations.order(mushaf_id.desc()).internal_into_boxed(), - }), - - value => Err(RouterError::BadRequest(format!( - "Sort value {} is not possible!", - value - ))), + "createTime" => match filters.order().unwrap_or_default() { + Order::Asc => { + _query = translations.order(created_at.asc()).internal_into_boxed() + } + Order::Desc => { + _query = translations.order(created_at.desc()).internal_into_boxed() + } + }, + + "updateTime" => match filters.order().unwrap_or_default() { + Order::Asc => { + _query = translations.order(updated_at.asc()).internal_into_boxed() + } + Order::Desc => { + _query = translations.order(updated_at.desc()).internal_into_boxed() + } + }, + + "language" => match filters.order().unwrap_or_default() { + Order::Asc => _query = translations.order(language.asc()).internal_into_boxed(), + Order::Desc => { + _query = translations.order(language.desc()).internal_into_boxed() + } + }, + + //"mushaf" => match filters.order().unwrap_or_default() { + // Order::Asc => { + // is_mushaf_sort = true; + // _query_with_mushaf = translations + // .select(Translation::as_select()) + // .inner_join(mushafs) + // .order(name.asc()) + // .internal_into_boxed() + // } + + // Order::Desc => { + // is_mushaf_sort = true; + // _query_with_mushaf = translations + // .select(Translation::as_select()) + // .inner_join(mushafs) + // .order(name.desc()) + // .internal_into_boxed() + // } + //}, + + value => { + return Err(RouterError::BadRequest(format!( + "Sort value {} is not possible!", + value + ))) + } }, - None => Ok(translations.internal_into_boxed()), - }?; + None => {} + }; _query = match filters.to() { Some(limit) => _query