forked from Roflin/gamenight
Adds renaming games functionality
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use gamenight_api_client_rs::{apis::default_api::rename_game_post, models::RenameGameRequestBody};
|
||||
use inquire::Text;
|
||||
|
||||
use crate::domain::game::Game;
|
||||
|
||||
use super::{Flow, FlowOutcome, FlowResult, GamenightState};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RenameGame {
|
||||
pub game: Game
|
||||
}
|
||||
|
||||
impl RenameGame {
|
||||
pub fn new(game: Game) -> Self {
|
||||
Self{
|
||||
game
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Flow<'a> for RenameGame {
|
||||
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
|
||||
if let Some(name) = Text::new(&format!("Rename {} to:", self.game.name))
|
||||
.with_initial_value(&format!("{}", self.game.name))
|
||||
.prompt_skippable()?
|
||||
{
|
||||
let req = RenameGameRequestBody {
|
||||
id: self.game.id.to_string(),
|
||||
name
|
||||
};
|
||||
rename_game_post(&state.api_configuration, Some(req)).await?;
|
||||
|
||||
return Ok((FlowOutcome::Successful, state))
|
||||
}
|
||||
Ok((FlowOutcome::Cancelled, state))
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for RenameGame {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "Rename")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user