diff --git a/src/application/routes/bags.rs b/src/application/routes/bags.rs index 8cad783..06c2251 100644 --- a/src/application/routes/bags.rs +++ b/src/application/routes/bags.rs @@ -178,16 +178,7 @@ pub(crate) async fn list_bags( .list_by_roast(roast_id) .await .map_err(AppError::from)?, - None => { - // For API list all, we might want to implement list_all in repo or reuse list with pagination - // For now, let's just return empty or implement list_all if needed. - // The spec implies we need list endpoints. - // Let's implement list_all in repo later if needed, or just use list with large page size? - // Actually, let's just use list_by_roast for now as that's the main use case for API likely. - // Or better, let's add list_all to repo. - // For now, I'll return an error if no filter is provided, or empty list. - vec![] - } + None => state.bag_repo.list_all().await.map_err(AppError::from)?, }; Ok(Json(bags)) } diff --git a/src/domain/repositories.rs b/src/domain/repositories.rs index f12668f..ff2a3d8 100644 --- a/src/domain/repositories.rs +++ b/src/domain/repositories.rs @@ -136,4 +136,5 @@ pub trait BagRepository: Send + Sync { &self, request: &ListRequest, ) -> Result, RepositoryError>; + async fn list_all(&self) -> Result, RepositoryError>; } diff --git a/src/infrastructure/repositories/bags.rs b/src/infrastructure/repositories/bags.rs index ac59546..ba406e5 100644 --- a/src/infrastructure/repositories/bags.rs +++ b/src/infrastructure/repositories/bags.rs @@ -268,6 +268,20 @@ impl BagRepository for SqlBagRepository { ) .await } + + async fn list_all(&self) -> Result, RepositoryError> { + let query = format!("{} ORDER BY b.roast_date DESC", BASE_SELECT); + + let records = query_as::<_, BagWithRoastRecord>(&query) + .fetch_all(&self.pool) + .await + .map_err(|err| RepositoryError::unexpected(err.to_string()))?; + + Ok(records + .into_iter() + .map(Self::to_domain_with_roast) + .collect()) + } } #[derive(sqlx::FromRow)]