Add support for meals (#1)
Reviewed-on: #1 Co-authored-by: Simon Bernier St-Pierre <git.sbstp.ca@gmail.com>
This commit was merged in pull request #1.
This commit is contained in:
+83
-7
@@ -1,7 +1,10 @@
|
||||
use async_trait::async_trait;
|
||||
use sqlx::SqliteConnection;
|
||||
|
||||
use crate::domain::{Category, DomainResult, GroceryList, Item, PresenceUser, SessionUser, User};
|
||||
use crate::domain::{
|
||||
Category, DomainResult, GroceryList, Item, Meal, MealIngredient, PresenceUser, SessionUser,
|
||||
User,
|
||||
};
|
||||
|
||||
/// Repositories take `&mut SqliteConnection` (which a `Transaction` derefs to),
|
||||
/// so several repositories can commit together atomically within a single
|
||||
@@ -60,17 +63,26 @@ pub trait ListRepository: Send + Sync {
|
||||
|
||||
#[async_trait]
|
||||
pub trait CategoryRepository: Send + Sync {
|
||||
async fn categories(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
list_id: i64,
|
||||
) -> DomainResult<Vec<Category>>;
|
||||
async fn categories(&self, txn: &mut SqliteConnection) -> DomainResult<Vec<Category>>;
|
||||
async fn create_category(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
list_id: i64,
|
||||
name: String,
|
||||
) -> DomainResult<i64>;
|
||||
async fn category_by_name(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
name: String,
|
||||
) -> DomainResult<Option<Category>>;
|
||||
}
|
||||
|
||||
/// A single item to insert in bulk, without a per-item revision bump.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct NewItem {
|
||||
pub name: String,
|
||||
pub quantity: String,
|
||||
pub note: String,
|
||||
pub category_id: Option<i64>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -85,6 +97,12 @@ pub trait ItemRepository: Send + Sync {
|
||||
note: String,
|
||||
category_id: Option<i64>,
|
||||
) -> DomainResult<i64>;
|
||||
async fn add_items_bulk(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
list_id: i64,
|
||||
items: Vec<NewItem>,
|
||||
) -> DomainResult<i64>;
|
||||
async fn set_item_checked(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
@@ -126,6 +144,64 @@ pub trait InvitationRepository: Send + Sync {
|
||||
) -> DomainResult<()>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait MealRepository: Send + Sync {
|
||||
async fn create_meal(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
name: String,
|
||||
description: String,
|
||||
) -> DomainResult<Meal>;
|
||||
async fn get_meal(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
meal_id: i64,
|
||||
) -> DomainResult<Option<Meal>>;
|
||||
async fn list_meals(&self, txn: &mut SqliteConnection) -> DomainResult<Vec<Meal>>;
|
||||
async fn update_meal(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
meal_id: i64,
|
||||
name: String,
|
||||
description: String,
|
||||
) -> DomainResult<()>;
|
||||
async fn delete_meal(&self, txn: &mut SqliteConnection, meal_id: i64) -> DomainResult<()>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait MealIngredientRepository: Send + Sync {
|
||||
async fn ingredients_for_meal(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
meal_id: i64,
|
||||
) -> DomainResult<Vec<MealIngredient>>;
|
||||
async fn add_ingredient(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
meal_id: i64,
|
||||
name: String,
|
||||
quantity: String,
|
||||
note: String,
|
||||
category_id: Option<i64>,
|
||||
) -> DomainResult<i64>;
|
||||
async fn update_ingredient(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
meal_id: i64,
|
||||
ingredient_id: i64,
|
||||
name: String,
|
||||
quantity: String,
|
||||
note: String,
|
||||
category_id: Option<i64>,
|
||||
) -> DomainResult<()>;
|
||||
async fn delete_ingredient(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
meal_id: i64,
|
||||
ingredient_id: i64,
|
||||
) -> DomainResult<()>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait PasswordHasher: Send + Sync {
|
||||
fn hash(&self, password: &str) -> DomainResult<String>;
|
||||
|
||||
Reference in New Issue
Block a user