68 lines
1.6 KiB
Rust
68 lines
1.6 KiB
Rust
use crate::{
|
|
domain,
|
|
rest::{Ingredient, Lang},
|
|
};
|
|
|
|
#[derive(Debug, Serialize)]
|
|
pub struct Recipe {
|
|
pub key: String,
|
|
pub lang: Lang,
|
|
pub name: String,
|
|
pub instructions: Vec<String>,
|
|
pub ingredients: Vec<RecipeIngredient>,
|
|
}
|
|
|
|
impl From<domain::Recipe> for Recipe {
|
|
fn from(app: domain::Recipe) -> Self {
|
|
Self {
|
|
key: app.key,
|
|
lang: app.lang.into(),
|
|
name: app.name,
|
|
ingredients: app.ingredients.into_iter().map(From::from).collect(),
|
|
instructions: app.instructions,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Serialize)]
|
|
pub struct RecipeIngredient {
|
|
#[serde(flatten)]
|
|
pub ingredient: Ingredient,
|
|
#[serde(flatten)]
|
|
pub measure: Measure,
|
|
}
|
|
|
|
impl From<domain::RecipeIngredient> for RecipeIngredient {
|
|
fn from(app: domain::RecipeIngredient) -> Self {
|
|
Self {
|
|
ingredient: app.ingredient.into(),
|
|
measure: app.measure.into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Serialize)]
|
|
#[serde(tag = "measure", content = "amount")]
|
|
pub enum Measure {
|
|
#[serde(rename = "g")]
|
|
Gram(u32),
|
|
#[serde(rename = "kg")]
|
|
KiloGram(u32),
|
|
#[serde(rename = "ml")]
|
|
MilliLiter(u32),
|
|
#[serde(rename = "l")]
|
|
Liter(u32),
|
|
}
|
|
|
|
impl From<domain::Measure> for Measure {
|
|
fn from(app: domain::Measure) -> Self {
|
|
use domain::Measure as M;
|
|
match app {
|
|
M::Gram(v) => Measure::Gram(v),
|
|
M::KiloGram(v) => Measure::KiloGram(v),
|
|
M::MilliLiter(v) => Measure::MilliLiter(v),
|
|
M::Liter(v) => Measure::Liter(v),
|
|
}
|
|
}
|
|
}
|