Recipe edit (WIP)
This commit is contained in:
parent
fce4eade73
commit
c6dfff065c
24 changed files with 1157 additions and 971 deletions
|
|
@ -1,77 +1,78 @@
|
|||
use chrono::prelude::*;
|
||||
use sqlx::{self, FromRow};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, FromRow)]
|
||||
pub struct User {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
pub email: String,
|
||||
}
|
||||
|
||||
#[derive(FromRow)]
|
||||
pub struct UserLoginInfo {
|
||||
pub last_login_datetime: DateTime<Utc>,
|
||||
pub ip: String,
|
||||
pub user_agent: String,
|
||||
}
|
||||
|
||||
#[derive(FromRow)]
|
||||
pub struct Recipe {
|
||||
pub id: i64,
|
||||
pub user_id: i64,
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub estimate_time: Option<i32>, // [s].
|
||||
pub difficulty: Difficulty,
|
||||
pub lang: String,
|
||||
pub estimated_time: Option<u32>, // [s].
|
||||
pub description: String,
|
||||
|
||||
//ingredients: Vec<Ingredient>, // For four people.
|
||||
pub process: Vec<Group>,
|
||||
}
|
||||
#[sqlx(try_from = "u32")]
|
||||
pub difficulty: Difficulty,
|
||||
|
||||
impl Recipe {
|
||||
pub fn empty(id: i64, user_id: i64) -> Recipe {
|
||||
Self::new(id, user_id, String::new(), String::new())
|
||||
}
|
||||
|
||||
pub fn new(id: i64, user_id: i64, title: String, description: String) -> Recipe {
|
||||
Recipe {
|
||||
id,
|
||||
user_id,
|
||||
title,
|
||||
description,
|
||||
estimate_time: None,
|
||||
difficulty: Difficulty::Unknown,
|
||||
lang: "en".to_string(),
|
||||
process: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Ingredient {
|
||||
pub quantity: Option<Quantity>,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
pub struct Quantity {
|
||||
pub value: f32,
|
||||
pub unit: String,
|
||||
pub servings: u32,
|
||||
pub is_published: bool,
|
||||
// pub tags: Vec<String>,
|
||||
// pub groups: Vec<Group>,
|
||||
}
|
||||
|
||||
pub struct Group {
|
||||
pub name: Option<String>,
|
||||
pub input: Vec<StepInput>,
|
||||
pub name: String,
|
||||
pub comment: String,
|
||||
pub steps: Vec<Step>,
|
||||
}
|
||||
|
||||
pub struct Step {
|
||||
pub action: String,
|
||||
pub ingredients: Vec<Ingredient>,
|
||||
}
|
||||
|
||||
pub enum StepInput {
|
||||
Ingredient(Ingredient),
|
||||
pub struct Ingredient {
|
||||
pub name: String,
|
||||
pub comment: String,
|
||||
pub quantity: i32,
|
||||
pub quantity_unit: String,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum Difficulty {
|
||||
Unknown = 0,
|
||||
Easy = 1,
|
||||
Medium = 2,
|
||||
Hard = 3,
|
||||
}
|
||||
|
||||
impl TryFrom<u32> for Difficulty {
|
||||
type Error = &'static str;
|
||||
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
||||
Ok(match value {
|
||||
1 => Self::Easy,
|
||||
2 => Self::Medium,
|
||||
3 => Self::Hard,
|
||||
_ => Self::Unknown,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Difficulty> for u32 {
|
||||
fn from(value: Difficulty) -> Self {
|
||||
value as u32
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue