From 956fd0459d8062c6a282a0f7e5c3feb7c28659ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Tue, 18 Jun 2024 19:55:28 -0700 Subject: [PATCH] Add name attribute to v2::watchlist::Watchlist --- src/api/v2/watchlist.rs | 9 +++++++-- src/api/v2/watchlists.rs | 18 +++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/api/v2/watchlist.rs b/src/api/v2/watchlist.rs index cbad90e3..2e180bda 100644 --- a/src/api/v2/watchlist.rs +++ b/src/api/v2/watchlist.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2021-2023 The apca Developers +// Copyright (C) 2021-2024 The apca Developers // SPDX-License-Identifier: GPL-3.0-or-later use std::ops::Deref; @@ -42,6 +42,9 @@ pub struct Watchlist { /// The watchlist's ID. #[serde(rename = "id")] pub id: Id, + /// The watchlist's user-defined name. + #[serde(rename = "name")] + pub name: String, /// The account's ID. #[serde(rename = "account_id")] pub account_id: account::Id, @@ -171,9 +174,10 @@ mod tests { let api_info = ApiInfo::from_env().unwrap(); let client = Client::new(api_info); let expected_symbols = vec!["AAPL".to_string(), "AMZN".to_string()]; + let id = Uuid::new_v4().to_string(); let created = client .issue::(&CreateReq { - name: Uuid::new_v4().to_string(), + name: id.clone(), symbols: expected_symbols.clone(), }) .await @@ -191,6 +195,7 @@ mod tests { // Also check that the reported account ID matches our account. let account = client.issue::(&()).await.unwrap(); + assert_eq!(watchlist.name, id); assert_eq!(watchlist.account_id, account.id); } diff --git a/src/api/v2/watchlists.rs b/src/api/v2/watchlists.rs index 6ca97d16..df27149c 100644 --- a/src/api/v2/watchlists.rs +++ b/src/api/v2/watchlists.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2021-2023 The apca Developers +// Copyright (C) 2021-2024 The apca Developers // SPDX-License-Identifier: GPL-3.0-or-later use chrono::DateTime; @@ -12,11 +12,14 @@ use crate::Str; /// A watchlist item. -#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq)] +#[derive(Clone, Debug, Deserialize, Eq, PartialEq)] pub struct WatchlistItem { /// The watchlist's ID. #[serde(rename = "id")] pub id: watchlist::Id, + /// The watchlist's user-defined name. + #[serde(rename = "name")] + pub name: String, /// The account's ID. #[serde(rename = "account_id")] pub account_id: account::Id, @@ -63,9 +66,10 @@ mod tests { async fn list_watchlists() { let api_info = ApiInfo::from_env().unwrap(); let client = Client::new(api_info); + let id = Uuid::new_v4().to_string(); let created = client .issue::(&CreateReq { - name: Uuid::new_v4().to_string(), + name: id.clone(), symbols: vec!["AAPL".to_string()], }) .await @@ -78,7 +82,11 @@ mod tests { .unwrap(); let watchlists = result.unwrap(); - let mut ids = watchlists.iter().map(|w| w.id); - assert!(ids.any(|x| x == created.id)) + assert!( + watchlists + .iter() + .any(|l| l.id == created.id && l.name == id), + "{watchlists:#?} : {id}" + ) } }