From 90562416860ad2c24476c7b2fffb3924f6249185 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Thu, 16 Mar 2023 16:49:23 +0200 Subject: [PATCH] feat(shared): enable api calls for creare, all_forming and my_games --- shared/src/api/game/all_forming.rs | 8 ++-- shared/src/api/game/create.rs | 6 +-- shared/src/api/game/mod.rs | 16 +++---- shared/src/api/game/mygames.rs | 8 ++-- shared/src/api/game/types.rs | 67 ------------------------------ shared/src/api/mod.rs | 20 +-------- 6 files changed, 18 insertions(+), 107 deletions(-) delete mode 100644 shared/src/api/game/types.rs diff --git a/shared/src/api/game/all_forming.rs b/shared/src/api/game/all_forming.rs index 2669571..eb9fc76 100644 --- a/shared/src/api/game/all_forming.rs +++ b/shared/src/api/game/all_forming.rs @@ -9,14 +9,14 @@ use reqwest; use serde::{Deserialize, Serialize}; -use super::{types, APIErrorWrapper}; +use crate::{error::api::APIError, types::game::Game}; -pub type ResultAllForming = Vec; +pub type ResultAllForming = Vec; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Serialize, Deserialize)] #[serde(untagged)] pub enum ResponseAllForming { - Error(APIErrorWrapper), + Error(APIError), Valid(ResultAllForming), } diff --git a/shared/src/api/game/create.rs b/shared/src/api/game/create.rs index 5866f7b..4542cdb 100644 --- a/shared/src/api/game/create.rs +++ b/shared/src/api/game/create.rs @@ -9,12 +9,12 @@ use reqwest; use serde::{Deserialize, Serialize}; -use super::{types::Game, APIErrorWrapper}; +use crate::{error::api::APIError, types::game::Game}; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Serialize, Deserialize)] #[serde(untagged)] pub enum ResponseCreateGame { - Error(APIErrorWrapper), + Error(APIError), Valid(Game), } diff --git a/shared/src/api/game/mod.rs b/shared/src/api/game/mod.rs index 62027a1..d090697 100644 --- a/shared/src/api/game/mod.rs +++ b/shared/src/api/game/mod.rs @@ -6,24 +6,20 @@ * See LICENSE for licensing information. */ -use super::APIErrorWrapper; - -pub mod types; - mod create; pub use create::*; mod all_forming; pub use all_forming::*; -mod info; -pub use info::*; +//mod info; +//pub use info::*; -mod join; -pub use join::*; +//mod join; +//pub use join::*; mod mygames; pub use mygames::*; -mod patchstate; -pub use patchstate::*; +//mod patchstate; +//pub use patchstate::*; diff --git a/shared/src/api/game/mygames.rs b/shared/src/api/game/mygames.rs index 6ef540c..bcd0c5f 100644 --- a/shared/src/api/game/mygames.rs +++ b/shared/src/api/game/mygames.rs @@ -9,14 +9,14 @@ use reqwest; use serde::{Deserialize, Serialize}; -use super::{types, APIErrorWrapper}; +use crate::{error::api::APIError, types::game::Game}; -pub type ResultMyGames = Vec; +pub type ResultMyGames = Vec; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Serialize, Deserialize)] #[serde(untagged)] pub enum ResponseMyGames { - Error(APIErrorWrapper), + Error(APIError), Valid(ResultMyGames), } diff --git a/shared/src/api/game/types.rs b/shared/src/api/game/types.rs deleted file mode 100644 index 80891ae..0000000 --- a/shared/src/api/game/types.rs +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This file is part of laurelin/shared - * Copyright (C) 2023 Jonni Liljamo - * - * Licensed under GPL-3.0-only. - * See LICENSE for licensing information. - */ - -use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; - -use crate::api::user::types::UserPub; - -#[derive(Debug, Serialize_repr, Deserialize_repr, Clone, PartialEq)] -#[repr(u8)] -pub enum GameState { - Forming = 0, - InProgress = 1, - Finished = 2, - Cancelled = 3, -} - -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct Game { - pub id: String, - pub created_at: String, - pub updated_at: String, - pub host_id: String, - pub host: UserPub, - pub guest_id: String, - pub guest: UserPub, - pub state: GameState, - pub ended_at: String, - pub game_data_id: String, - pub game_data: GameData, -} - -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct Action { - pub id: String, - pub created_at: String, - pub updated_at: String, - pub game_data_id: String, - pub invoker: String, - pub data: String, - pub timestamp: String, -} - -#[derive(Debug, Serialize_repr, Deserialize_repr, Clone, PartialEq)] -#[repr(u8)] -pub enum GameTurn { - Host = 0, - Guest = 1, -} - -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct GameData { - pub id: String, - pub created_at: String, - pub updated_at: String, - pub actions: Option>, - pub turn: GameTurn, - pub host_hand: Option, - pub host_deck: Option, - pub guest_hand: Option, - pub guest_deck: Option, -} diff --git a/shared/src/api/mod.rs b/shared/src/api/mod.rs index bd02a7b..8f68620 100644 --- a/shared/src/api/mod.rs +++ b/shared/src/api/mod.rs @@ -9,29 +9,11 @@ use reqwest; use serde::{Deserialize, Serialize}; -//pub mod game; +pub mod game; pub mod user; mod macros; -#[derive(Debug, Deserialize, Serialize)] -pub struct APIError { - pub id: u16, - pub name: String, - pub description: String, -} - -#[derive(Debug, Deserialize, Serialize)] -pub struct APIErrorWrapper { - pub error: APIError, -} - -impl std::fmt::Display for APIErrorWrapper { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{} {}", self.error.id, self.error.description) - } -} - #[derive(Serialize, Deserialize)] pub struct APIInfo { pub info: String, -- 2.44.1