From 40c99ea705bc535f248ee739c07e1f943e1c89b9 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sat, 14 May 2022 00:00:42 +0300 Subject: [PATCH] api: move lang to another file --- api/src/domain/ingredient/fetch_by_key.rs | 5 +++-- api/src/domain/ingredient/fetch_list.rs | 5 +++-- api/src/domain/ingredient/types.rs | 27 +---------------------- api/src/domain/misc_types.rs | 26 ++++++++++++++++++++++ api/src/domain/mod.rs | 2 ++ api/src/domain/recipe/mod.rs | 1 + api/src/domain/recipe/types.rs | 0 api/src/repo/ingredient.rs | 5 +++-- api/src/rest/ctrl/ingredient.rs | 2 +- 9 files changed, 40 insertions(+), 33 deletions(-) create mode 100644 api/src/domain/misc_types.rs create mode 100644 api/src/domain/recipe/mod.rs create mode 100644 api/src/domain/recipe/types.rs diff --git a/api/src/domain/ingredient/fetch_by_key.rs b/api/src/domain/ingredient/fetch_by_key.rs index df51f14..2f7eac6 100644 --- a/api/src/domain/ingredient/fetch_by_key.rs +++ b/api/src/domain/ingredient/fetch_by_key.rs @@ -1,9 +1,10 @@ use super::types; +use crate::domain::misc_types; use crate::repo::ingredient::IngredientRepo; #[derive(Default, Debug)] pub struct RequestOpts { - pub lang: Option, + pub lang: Option, } pub enum ResponseError { @@ -24,7 +25,7 @@ pub fn execute( #[cfg(test)] mod tests { use super::*; - use crate::domain::ingredient::types::Lang; + use crate::domain::misc_types::Lang; #[test] fn should_return_ingredient() { diff --git a/api/src/domain/ingredient/fetch_list.rs b/api/src/domain/ingredient/fetch_list.rs index 94e4006..f767208 100644 --- a/api/src/domain/ingredient/fetch_list.rs +++ b/api/src/domain/ingredient/fetch_list.rs @@ -1,9 +1,10 @@ use super::types; +use crate::domain::misc_types; use crate::repo::ingredient::IngredientRepo; #[derive(Default, Debug)] pub struct RequestOpts { - pub lang: Option, + pub lang: Option, pub keys: Option>, } @@ -14,7 +15,7 @@ pub fn execute(repo: &impl IngredientRepo, opts: RequestOpts) -> Vec Self { - Lang::Rus - } -} - -impl FromStr for Lang { - type Err = (); - - fn from_str(s: &str) -> Result { - match s { - "Rus" | "rus" => Ok(Lang::Rus), - "Eng" | "eng" => Ok(Lang::Eng), - _ => Err(()), - } - } -} +use crate::domain::misc_types::Lang; #[derive(Debug, Clone, Serialize)] pub struct Ingredient { diff --git a/api/src/domain/misc_types.rs b/api/src/domain/misc_types.rs new file mode 100644 index 0000000..4197fc9 --- /dev/null +++ b/api/src/domain/misc_types.rs @@ -0,0 +1,26 @@ +use std::str::FromStr; + +#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize)] +pub enum Lang { + Rus, + #[allow(dead_code)] + Eng, +} + +impl Default for Lang { + fn default() -> Self { + Lang::Rus + } +} + +impl FromStr for Lang { + type Err = (); + + fn from_str(s: &str) -> Result { + match s { + "Rus" | "rus" => Ok(Lang::Rus), + "Eng" | "eng" => Ok(Lang::Eng), + _ => Err(()), + } + } +} diff --git a/api/src/domain/mod.rs b/api/src/domain/mod.rs index ac67972..4e45794 100644 --- a/api/src/domain/mod.rs +++ b/api/src/domain/mod.rs @@ -1 +1,3 @@ pub mod ingredient; +pub mod misc_types; +pub mod recipe; diff --git a/api/src/domain/recipe/mod.rs b/api/src/domain/recipe/mod.rs new file mode 100644 index 0000000..cd40856 --- /dev/null +++ b/api/src/domain/recipe/mod.rs @@ -0,0 +1 @@ +pub mod types; diff --git a/api/src/domain/recipe/types.rs b/api/src/domain/recipe/types.rs new file mode 100644 index 0000000..e69de29 diff --git a/api/src/repo/ingredient.rs b/api/src/repo/ingredient.rs index 2684998..7dab51c 100644 --- a/api/src/repo/ingredient.rs +++ b/api/src/repo/ingredient.rs @@ -1,8 +1,9 @@ use crate::domain::ingredient::{fetch_by_key, fetch_list, types}; +use crate::domain::misc_types; #[derive(Default)] pub struct GetIngredientOpts { - pub lang: Option, + pub lang: Option, } impl From for GetIngredientOpts { @@ -13,7 +14,7 @@ impl From for GetIngredientOpts { #[derive(Default)] pub struct GetIngredientsOpts { - pub lang: Option, + pub lang: Option, pub keys: Option>, } diff --git a/api/src/rest/ctrl/ingredient.rs b/api/src/rest/ctrl/ingredient.rs index 8b566e4..6643a7a 100644 --- a/api/src/rest/ctrl/ingredient.rs +++ b/api/src/rest/ctrl/ingredient.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use tiny_http::{Header, Response}; use crate::domain; -use crate::domain::ingredient::types::Lang; +use crate::domain::misc_types::Lang; use crate::repo::ingredient::StaticIngredientRepo; use crate::rest::types::{QueryParams, Url};