fix(api): flatten RoastWithRoaster JSON response for consistency

The list-roasts API was returning nested objects with a "roast" field,
which was inconsistent with other list APIs in the codebase. Added
serde's #[serde(flatten)] attribute to make the response flat while
maintaining the internal struct composition.
This commit is contained in:
Jon Seager 2026-02-02 16:32:56 +00:00
parent a54ca8f42d
commit bee94d2a2e
No known key found for this signature in database
2 changed files with 3 additions and 2 deletions

View file

@ -20,6 +20,7 @@ pub struct Roast {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RoastWithRoaster {
#[serde(flatten)]
pub roast: Roast,
pub roaster_name: String,
pub roaster_slug: String,

View file

@ -141,10 +141,10 @@ fn test_list_roasts_shows_added_roast() {
assert!(roasts.is_array());
let roasts_array = roasts.as_array().unwrap();
// Find our roast in the list (note: list returns RoastWithRoaster which has nested structure)
// Find our roast in the list
let found = roasts_array
.iter()
.any(|item| item["roast"]["id"].as_i64() == Some(roast_id));
.any(|item| item["id"].as_i64() == Some(roast_id));
assert!(
found,
"Should find the added roast in the list. Looking for id={}, found {} roasts",