remove dead code
This commit is contained in:
+1
-10
@@ -64,16 +64,7 @@ pub trait ListRepository: Send + Sync {
|
||||
#[async_trait]
|
||||
pub trait CategoryRepository: Send + Sync {
|
||||
async fn categories(&self, txn: &mut SqliteConnection) -> DomainResult<Vec<Category>>;
|
||||
async fn create_category(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
name: String,
|
||||
) -> DomainResult<i64>;
|
||||
async fn category_by_name(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
name: String,
|
||||
) -> DomainResult<Option<Category>>;
|
||||
async fn create_category(&self, txn: &mut SqliteConnection, name: String) -> DomainResult<i64>;
|
||||
}
|
||||
|
||||
/// A single item to insert in bulk, without a per-item revision bump.
|
||||
|
||||
+16
-67
@@ -7,12 +7,11 @@ use sha2::{Digest, Sha256};
|
||||
use sqlx::{Connection, Row, SqliteConnection, SqlitePool, sqlite::SqliteConnectOptions};
|
||||
|
||||
use crate::domain::{
|
||||
Category, DomainError, DomainResult, GroceryList, Item, Meal, MealIngredient, SessionUser,
|
||||
User,
|
||||
Category, DomainError, DomainResult, GroceryList, Item, Meal, MealIngredient, SessionUser, User,
|
||||
};
|
||||
use crate::ports::{
|
||||
CategoryRepository, InvitationRepository, ItemRepository, ListRepository, MealIngredientRepository,
|
||||
MealRepository, NewItem, SessionRepository, UserRepository,
|
||||
CategoryRepository, InvitationRepository, ItemRepository, ListRepository,
|
||||
MealIngredientRepository, MealRepository, NewItem, SessionRepository, UserRepository,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -416,11 +415,7 @@ impl CategoryRepository for SqliteCategoryRepository {
|
||||
.collect())
|
||||
}
|
||||
|
||||
async fn create_category(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
name: String,
|
||||
) -> DomainResult<i64> {
|
||||
async fn create_category(&self, txn: &mut SqliteConnection, name: String) -> DomainResult<i64> {
|
||||
let position: i64 = sqlx::query("SELECT COALESCE(MAX(position), -1) + 1 FROM categories")
|
||||
.fetch_one(&mut *txn)
|
||||
.await
|
||||
@@ -447,26 +442,6 @@ impl CategoryRepository for SqliteCategoryRepository {
|
||||
.get::<i64, _>(0);
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
async fn category_by_name(
|
||||
&self,
|
||||
txn: &mut SqliteConnection,
|
||||
name: String,
|
||||
) -> DomainResult<Option<Category>> {
|
||||
let row = sqlx::query(
|
||||
"SELECT id, name
|
||||
FROM categories
|
||||
WHERE name = ?1 COLLATE NOCASE",
|
||||
)
|
||||
.bind(&name)
|
||||
.fetch_optional(&mut *txn)
|
||||
.await
|
||||
.map_err(db_error)?;
|
||||
Ok(row.map(|row| Category {
|
||||
id: row.get(0),
|
||||
name: row.get(1),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -975,10 +950,7 @@ impl MealIngredientRepository for SqliteMealIngredientRepository {
|
||||
}
|
||||
}
|
||||
|
||||
async fn ensure_category(
|
||||
txn: &mut SqliteConnection,
|
||||
category_id: Option<i64>,
|
||||
) -> DomainResult<()> {
|
||||
async fn ensure_category(txn: &mut SqliteConnection, category_id: Option<i64>) -> DomainResult<()> {
|
||||
let Some(category_id) = category_id else {
|
||||
return Ok(());
|
||||
};
|
||||
@@ -1381,11 +1353,7 @@ mod tests {
|
||||
let id = db
|
||||
.run(move |txn| {
|
||||
let categories = categories.clone();
|
||||
Box::pin(async move {
|
||||
categories
|
||||
.create_category(txn, "Bakery".into())
|
||||
.await
|
||||
})
|
||||
Box::pin(async move { categories.create_category(txn, "Bakery".into()).await })
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -1402,34 +1370,12 @@ mod tests {
|
||||
let result = db
|
||||
.run(move |txn| {
|
||||
let categories = categories.clone();
|
||||
Box::pin(async move {
|
||||
categories
|
||||
.create_category(txn, "Produce".into())
|
||||
.await
|
||||
})
|
||||
Box::pin(async move { categories.create_category(txn, "Produce".into()).await })
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::Conflict)));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn category_by_name_resolves_globally() {
|
||||
let db = setup().await;
|
||||
let categories = SqliteCategoryRepository;
|
||||
let found = db
|
||||
.run(move |txn| {
|
||||
let categories = categories.clone();
|
||||
Box::pin(async move {
|
||||
categories
|
||||
.category_by_name(txn, "produce".into())
|
||||
.await
|
||||
})
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(found.unwrap().name, "Produce");
|
||||
}
|
||||
|
||||
// ---- ItemRepository ----
|
||||
|
||||
#[tokio::test]
|
||||
@@ -1977,7 +1923,14 @@ mod tests {
|
||||
let ingredients = ingredients.clone();
|
||||
Box::pin(async move {
|
||||
ingredients
|
||||
.add_ingredient(txn, meal.id, "X".into(), String::new(), String::new(), Some(9999))
|
||||
.add_ingredient(
|
||||
txn,
|
||||
meal.id,
|
||||
"X".into(),
|
||||
String::new(),
|
||||
String::new(),
|
||||
Some(9999),
|
||||
)
|
||||
.await
|
||||
})
|
||||
})
|
||||
@@ -2054,11 +2007,7 @@ mod tests {
|
||||
let result = db
|
||||
.run(move |txn| {
|
||||
let ingredients = ingredients.clone();
|
||||
Box::pin(async move {
|
||||
ingredients
|
||||
.delete_ingredient(txn, meal.id, 9999)
|
||||
.await
|
||||
})
|
||||
Box::pin(async move { ingredients.delete_ingredient(txn, meal.id, 9999).await })
|
||||
})
|
||||
.await;
|
||||
assert!(matches!(result, Err(DomainError::NotFound)));
|
||||
|
||||
Reference in New Issue
Block a user