From f3a4cc70756d74a4d44459524b82abb974971b18 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Wed, 4 Feb 2026 17:19:26 +0000 Subject: [PATCH] feat(home): limit open bags to 3 most recently updated - Add UpdatedAt variant to BagSortKey - Sort home page bags by updated_at desc instead of roast_date - Limit to 3 bags instead of showing all open bags --- src/application/routes/home.rs | 7 ++++++- src/domain/bags.rs | 3 +++ src/infrastructure/repositories/bags.rs | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/application/routes/home.rs b/src/application/routes/home.rs index 1cda210..df0f851 100644 --- a/src/application/routes/home.rs +++ b/src/application/routes/home.rs @@ -60,7 +60,12 @@ async fn load_home_content(state: &AppState) -> Result { BrewSortKey::CreatedAt, SortDirection::Desc, ); - let open_bags_req = ListRequest::show_all(BagSortKey::RoastDate, SortDirection::Desc); + let open_bags_req = ListRequest::new( + 1, + PageSize::limited(3), + BagSortKey::UpdatedAt, + SortDirection::Desc, + ); let recent_events_req = ListRequest::new( 1, PageSize::limited(5), diff --git a/src/domain/bags.rs b/src/domain/bags.rs index e98ccfe..8b035c4 100644 --- a/src/domain/bags.rs +++ b/src/domain/bags.rs @@ -83,6 +83,7 @@ impl BagFilter { pub enum BagSortKey { RoastDate, CreatedAt, + UpdatedAt, Roaster, Roast, FinishedAt, @@ -97,6 +98,7 @@ impl SortKey for BagSortKey { match value { "roast-date" => Some(BagSortKey::RoastDate), "created-at" => Some(BagSortKey::CreatedAt), + "updated-at" => Some(BagSortKey::UpdatedAt), "roaster" => Some(BagSortKey::Roaster), "roast" => Some(BagSortKey::Roast), "finished-at" => Some(BagSortKey::FinishedAt), @@ -108,6 +110,7 @@ impl SortKey for BagSortKey { match self { BagSortKey::RoastDate => "roast-date", BagSortKey::CreatedAt => "created-at", + BagSortKey::UpdatedAt => "updated-at", BagSortKey::Roaster => "roaster", BagSortKey::Roast => "roast", BagSortKey::FinishedAt => "finished-at", diff --git a/src/infrastructure/repositories/bags.rs b/src/infrastructure/repositories/bags.rs index ee6e545..05a8130 100644 --- a/src/infrastructure/repositories/bags.rs +++ b/src/infrastructure/repositories/bags.rs @@ -39,6 +39,7 @@ impl SqlBagRepository { match request.sort_key() { BagSortKey::RoastDate => format!("b.roast_date {dir_sql}, b.created_at DESC"), BagSortKey::CreatedAt => format!("b.created_at {dir_sql}, b.id DESC"), + BagSortKey::UpdatedAt => format!("b.updated_at {dir_sql}, b.id DESC"), BagSortKey::Roaster => format!("LOWER(rr.name) {dir_sql}, b.created_at DESC"), BagSortKey::Roast => format!("LOWER(r.name) {dir_sql}, b.created_at DESC"), BagSortKey::FinishedAt => format!("b.finished_at {dir_sql}, b.created_at DESC"),