Added Location and location ownership/rights to gamenight.

This commit is contained in:
2025-12-24 14:48:54 +01:00
parent 8a48119c80
commit ff88029a4b
57 changed files with 3034 additions and 995 deletions

View File

@@ -0,0 +1,65 @@
use std::{ffi::OsStr, fmt::Display};
use async_trait::async_trait;
use gamenight_api_client_rs::{apis::default_api::{location_authorize_post, location_post}, models::{authorize_location_request_body::Op::Grant, AddLocationRequestBody, AuthorizeLocationRequestBody}};
use inquire::{Editor, Text};
use super::*;
#[derive(Clone)]
pub struct AddLocation {
}
impl AddLocation {
pub fn new() -> Self {
Self {}
}
}
#[async_trait]
impl<'a> Flow<'a> for AddLocation {
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
if let Some(name) = Text::new("What is the name of the location you want to add?").prompt_skippable()? {
let address;
let note;
{
address = Text::new("Optional: What is the address?").prompt_skippable()?;
let mut editor_prompt = Editor::new("What is the name of the location you want to add?");
let editor_command;
if let Some(editor) = &state.gamenight_configuration.editor {
editor_command = editor.clone();
editor_prompt = editor_prompt.with_editor_command(OsStr::new(&editor_command))
}
note = editor_prompt.prompt_skippable()?;
}
let add_location_request = AddLocationRequestBody {
name,
address,
note
};
let location_id = location_post(&state.api_configuration, Some(add_location_request)).await?;
let add_authorize_request = AuthorizeLocationRequestBody {
location_id: location_id.location_id.to_string(),
user_id: state.get_user_id()?.to_string(),
op: Grant
};
location_authorize_post(&state.api_configuration, Some(add_authorize_request)).await?;
}
Ok((FlowOutcome::Cancelled, state))
}
}
impl Display for AddLocation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Add Location")
}
}