Minor refactoring
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use super::schema::recipes;
|
||||
use super::schema::ingredients;
|
||||
use super::diesel::prelude::*;
|
||||
|
||||
#[derive(Queryable)]
|
||||
pub struct Recipe {
|
||||
@@ -15,10 +16,29 @@ pub struct Recipe {
|
||||
pub struct NewRecipe<'a> {
|
||||
pub title: &'a str,
|
||||
pub category: i32,
|
||||
pub ingredients: String,
|
||||
pub ingredients: &'a str,
|
||||
pub preparation: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> NewRecipe<'a> {
|
||||
pub fn new(title: &'a str, category: i32, ingredients: &'a str, preparation: &'a str) -> Self {
|
||||
NewRecipe{
|
||||
title,
|
||||
category,
|
||||
ingredients,
|
||||
preparation,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert(self, conn: &SqliteConnection) -> Result<Self, String> {
|
||||
diesel::insert_into(recipes::table)
|
||||
.values(&self)
|
||||
.execute(conn)
|
||||
.expect("Error inserting recipe");
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Queryable)]
|
||||
pub struct Ingredient {
|
||||
pub id: i32,
|
||||
|
||||
Reference in New Issue
Block a user