Implemented deleting games as admin.

This commit is contained in:
2026-01-02 15:24:38 +01:00
parent 0c256846f6
commit 5c928b30f3
26 changed files with 344 additions and 133 deletions

View File

@@ -1,19 +1,27 @@
use std::fmt::Display;
use std::fmt::{Display, Formatter};
use chrono::{DateTime, Local};
use uuid::Uuid;
use crate::domain::owned_games::OwnedGames;
use crate::domain::participants::Participants;
use crate::domain::user::User;
#[derive(Clone)]
pub struct Gamenight {
pub id: Uuid,
pub name: String,
pub start_time: DateTime<Local>,
pub owner_id: Uuid,
pub organizer: User,
pub participants: Participants,
pub owned_games: OwnedGames,
}
impl Display for Gamenight {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, r#"Name: {}
When: {}"#, self.name, self.start_time.format("%d-%m-%Y %H:%M"))
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
writeln!(f, "Name: {}", self.name)?;
writeln!(f, "Organizer: {}", self.organizer)?;
writeln!(f, "Start: {}", self.start_time.to_rfc3339())?;
writeln!(f, "Participants: {}", self.participants)?;
write!(f, "Owned games:\n{}", self.owned_games)?;
Ok(())
}
}

View File

@@ -0,0 +1,19 @@
use std::fmt::Display;
use chrono::{DateTime, Local};
use uuid::Uuid;
#[derive(Clone)]
pub struct GamenightSelectData {
pub id: Uuid,
pub name: String,
pub start_time: DateTime<Local>,
pub owner_id: Uuid,
}
impl Display for GamenightSelectData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, r#"Name: {}
When: {}"#, self.name, self.start_time.format("%d-%m-%Y %H:%M"))
}
}

View File

@@ -0,0 +1,25 @@
use std::fmt::{Display, Formatter};
use gamenight_api_client_rs::models::Location;
use uuid::Uuid;
use crate::flows::FlowError;
pub struct LocationSelectData {
pub id: Uuid,
pub name: String,
}
impl Display for LocationSelectData {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }
}
impl TryFrom<&Location> for LocationSelectData {
type Error = FlowError;
fn try_from(value: &Location) -> Result<Self, Self::Error> {
let uuid = Uuid::parse_str(&value.id)?;
Ok(LocationSelectData {
id: uuid,
name: value.name.clone(),
})
}
}

View File

@@ -1,7 +1,9 @@
pub mod gamenight;
pub mod gamenight_select_data;
pub mod user;
pub mod config;
pub mod participants;
pub mod game;
pub mod owned_games;
pub mod location;
pub mod location;
pub mod location_select_data;
pub mod gamenight;

View File

@@ -2,12 +2,12 @@ use std::{collections::HashMap, fmt::Display};
use crate::domain::game::Game;
#[derive(Clone)]
pub struct OwnedGames(pub HashMap<String, Vec<Game>>);
pub struct OwnedGames<'a>(pub &'a HashMap<String, Vec<Game>>);
impl<'a> Display for OwnedGames<'a> {
impl Display for OwnedGames {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
for (k,v) in self.0 {
for (k,v) in &self.0 {
write!(f, "{k}:\n")?;
for g in v {
write!(f, "\t{}\n", g.name)?;

View File

@@ -2,9 +2,10 @@ use std::fmt::Display;
use crate::domain::user::User;
pub struct Participants<'a>(pub &'a Vec<User>);
#[derive(Clone)]
pub struct Participants(pub Vec<User>);
impl<'a> Display for Participants<'a> {
impl<'a> Display for Participants {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let string_list: Vec<String> = self.0.iter().map(|x| {format!("{x}")}).collect();
write!(f, "{}", string_list.join(", "))

View File

@@ -1,6 +1,7 @@
use std::fmt::Display;
use gamenight_api_client_rs::models;
use uuid::Uuid;
use crate::flows::FlowError;
#[derive(Clone)]
pub struct User {
@@ -13,4 +14,15 @@ impl Display for User {
write!(f, "{}", self.username)
}
}
impl TryFrom<models::User> for User {
type Error = FlowError;
fn try_from(user: models::User) -> Result<Self, Self::Error> {
Ok(Self {
username: user.username,
id: Uuid::parse_str(&user.id)?
})
}
}