remove dead code

This commit is contained in:
2026-08-01 20:35:14 -04:00
parent 9b32fd23a7
commit 250a18cfbb
2 changed files with 17 additions and 77 deletions
+1 -10
View File
@@ -64,16 +64,7 @@ pub trait ListRepository: Send + Sync {
#[async_trait] #[async_trait]
pub trait CategoryRepository: Send + Sync { pub trait CategoryRepository: Send + Sync {
async fn categories(&self, txn: &mut SqliteConnection) -> DomainResult<Vec<Category>>; async fn categories(&self, txn: &mut SqliteConnection) -> DomainResult<Vec<Category>>;
async fn create_category( async fn create_category(&self, txn: &mut SqliteConnection, name: String) -> DomainResult<i64>;
&self,
txn: &mut SqliteConnection,
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. /// A single item to insert in bulk, without a per-item revision bump.
+16 -67
View File
@@ -7,12 +7,11 @@ use sha2::{Digest, Sha256};
use sqlx::{Connection, Row, SqliteConnection, SqlitePool, sqlite::SqliteConnectOptions}; use sqlx::{Connection, Row, SqliteConnection, SqlitePool, sqlite::SqliteConnectOptions};
use crate::domain::{ use crate::domain::{
Category, DomainError, DomainResult, GroceryList, Item, Meal, MealIngredient, SessionUser, Category, DomainError, DomainResult, GroceryList, Item, Meal, MealIngredient, SessionUser, User,
User,
}; };
use crate::ports::{ use crate::ports::{
CategoryRepository, InvitationRepository, ItemRepository, ListRepository, MealIngredientRepository, CategoryRepository, InvitationRepository, ItemRepository, ListRepository,
MealRepository, NewItem, SessionRepository, UserRepository, MealIngredientRepository, MealRepository, NewItem, SessionRepository, UserRepository,
}; };
#[derive(Clone)] #[derive(Clone)]
@@ -416,11 +415,7 @@ impl CategoryRepository for SqliteCategoryRepository {
.collect()) .collect())
} }
async fn create_category( async fn create_category(&self, txn: &mut SqliteConnection, name: String) -> DomainResult<i64> {
&self,
txn: &mut SqliteConnection,
name: String,
) -> DomainResult<i64> {
let position: i64 = sqlx::query("SELECT COALESCE(MAX(position), -1) + 1 FROM categories") let position: i64 = sqlx::query("SELECT COALESCE(MAX(position), -1) + 1 FROM categories")
.fetch_one(&mut *txn) .fetch_one(&mut *txn)
.await .await
@@ -447,26 +442,6 @@ impl CategoryRepository for SqliteCategoryRepository {
.get::<i64, _>(0); .get::<i64, _>(0);
Ok(id) 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)] #[derive(Clone, Copy)]
@@ -975,10 +950,7 @@ impl MealIngredientRepository for SqliteMealIngredientRepository {
} }
} }
async fn ensure_category( async fn ensure_category(txn: &mut SqliteConnection, category_id: Option<i64>) -> DomainResult<()> {
txn: &mut SqliteConnection,
category_id: Option<i64>,
) -> DomainResult<()> {
let Some(category_id) = category_id else { let Some(category_id) = category_id else {
return Ok(()); return Ok(());
}; };
@@ -1381,11 +1353,7 @@ mod tests {
let id = db let id = db
.run(move |txn| { .run(move |txn| {
let categories = categories.clone(); let categories = categories.clone();
Box::pin(async move { Box::pin(async move { categories.create_category(txn, "Bakery".into()).await })
categories
.create_category(txn, "Bakery".into())
.await
})
}) })
.await .await
.unwrap(); .unwrap();
@@ -1402,34 +1370,12 @@ mod tests {
let result = db let result = db
.run(move |txn| { .run(move |txn| {
let categories = categories.clone(); let categories = categories.clone();
Box::pin(async move { Box::pin(async move { categories.create_category(txn, "Produce".into()).await })
categories
.create_category(txn, "Produce".into())
.await
})
}) })
.await; .await;
assert!(matches!(result, Err(DomainError::Conflict))); 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 ---- // ---- ItemRepository ----
#[tokio::test] #[tokio::test]
@@ -1977,7 +1923,14 @@ mod tests {
let ingredients = ingredients.clone(); let ingredients = ingredients.clone();
Box::pin(async move { Box::pin(async move {
ingredients 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 .await
}) })
}) })
@@ -2054,11 +2007,7 @@ mod tests {
let result = db let result = db
.run(move |txn| { .run(move |txn| {
let ingredients = ingredients.clone(); let ingredients = ingredients.clone();
Box::pin(async move { Box::pin(async move { ingredients.delete_ingredient(txn, meal.id, 9999).await })
ingredients
.delete_ingredient(txn, meal.id, 9999)
.await
})
}) })
.await; .await;
assert!(matches!(result, Err(DomainError::NotFound))); assert!(matches!(result, Err(DomainError::NotFound)));