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:
parent
a54ca8f42d
commit
bee94d2a2e
2 changed files with 3 additions and 2 deletions
|
|
@ -20,6 +20,7 @@ pub struct Roast {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct RoastWithRoaster {
|
pub struct RoastWithRoaster {
|
||||||
|
#[serde(flatten)]
|
||||||
pub roast: Roast,
|
pub roast: Roast,
|
||||||
pub roaster_name: String,
|
pub roaster_name: String,
|
||||||
pub roaster_slug: String,
|
pub roaster_slug: String,
|
||||||
|
|
|
||||||
|
|
@ -141,10 +141,10 @@ fn test_list_roasts_shows_added_roast() {
|
||||||
assert!(roasts.is_array());
|
assert!(roasts.is_array());
|
||||||
let roasts_array = roasts.as_array().unwrap();
|
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
|
let found = roasts_array
|
||||||
.iter()
|
.iter()
|
||||||
.any(|item| item["roast"]["id"].as_i64() == Some(roast_id));
|
.any(|item| item["id"].as_i64() == Some(roast_id));
|
||||||
assert!(
|
assert!(
|
||||||
found,
|
found,
|
||||||
"Should find the added roast in the list. Looking for id={}, found {} roasts",
|
"Should find the added roast in the list. Looking for id={}, found {} roasts",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue