forked from Roflin/gamenight
Rewrite to chatty but functional API.
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
|
||||
use chrono::DateTime;
|
||||
use gamenight_api_client_rs::apis::default_api::get_gamenights;
|
||||
use inquire::Select;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::flows::view_gamenight::ViewGamenight;
|
||||
use crate::{domain::{gamenight::Gamenight}, flows::view_gamenight::ViewGamenight};
|
||||
|
||||
use super::{exit::Exit, *};
|
||||
|
||||
@@ -22,9 +24,18 @@ impl<'a> Flow<'a> for ListGamenights {
|
||||
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
|
||||
let response = get_gamenights(&state.configuration).await?;
|
||||
|
||||
let mut view_flows = response.into_iter().map(|gamenight| -> Box<dyn Flow<'a> + Send> {
|
||||
Box::new(ViewGamenight::new(gamenight.into()))
|
||||
}).collect::<Vec<Box<dyn Flow<'a> + Send>>>();
|
||||
let mut view_flows: Vec<Box<dyn Flow<'_> + Send>> = vec![];
|
||||
|
||||
for response in response.iter() {
|
||||
let gamenight = Gamenight {
|
||||
id: Uuid::parse_str(&response.id)?,
|
||||
name: response.name.clone(),
|
||||
start_time:DateTime::parse_from_rfc3339(&response.datetime)?.into(),
|
||||
owner_id: Uuid::parse_str(&response.owner_id)?
|
||||
};
|
||||
view_flows.push(Box::new(ViewGamenight::new(gamenight)));
|
||||
}
|
||||
|
||||
view_flows.push(Box::new(Exit::new()));
|
||||
|
||||
let choice = Select::new("What gamenight would you like to view?", view_flows)
|
||||
@@ -38,5 +49,4 @@ impl Display for ListGamenights {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "List all gamenights")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user