api: move lang to another file
This commit is contained in:
parent
63a414a7bb
commit
40c99ea705
|
@ -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<types::Lang>,
|
||||
pub lang: Option<misc_types::Lang>,
|
||||
}
|
||||
|
||||
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() {
|
||||
|
|
|
@ -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<types::Lang>,
|
||||
pub lang: Option<misc_types::Lang>,
|
||||
pub keys: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
|
@ -14,7 +15,7 @@ pub fn execute(repo: &impl IngredientRepo, opts: RequestOpts) -> Vec<types::Ingr
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::domain::ingredient::types::Lang;
|
||||
use crate::domain::misc_types::Lang;
|
||||
|
||||
#[test]
|
||||
fn should_return_all_ingredients() {
|
||||
|
|
|
@ -1,29 +1,4 @@
|
|||
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<Self, Self::Err> {
|
||||
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 {
|
||||
|
|
|
@ -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<Self, Self::Err> {
|
||||
match s {
|
||||
"Rus" | "rus" => Ok(Lang::Rus),
|
||||
"Eng" | "eng" => Ok(Lang::Eng),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1 +1,3 @@
|
|||
pub mod ingredient;
|
||||
pub mod misc_types;
|
||||
pub mod recipe;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
pub mod types;
|
|
@ -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<types::Lang>,
|
||||
pub lang: Option<misc_types::Lang>,
|
||||
}
|
||||
|
||||
impl From<fetch_by_key::RequestOpts> for GetIngredientOpts {
|
||||
|
@ -13,7 +14,7 @@ impl From<fetch_by_key::RequestOpts> for GetIngredientOpts {
|
|||
|
||||
#[derive(Default)]
|
||||
pub struct GetIngredientsOpts {
|
||||
pub lang: Option<types::Lang>,
|
||||
pub lang: Option<misc_types::Lang>,
|
||||
pub keys: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
Loading…
Reference in New Issue