DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

90562416860ad2c24476c7b2fffb3924f6249185 — Jonni Liljamo 1 year, 9 months ago ebf6371
feat(shared): enable api calls for creare, all_forming and my_games
6 files changed, 18 insertions(+), 107 deletions(-)

M shared/src/api/game/all_forming.rs
M shared/src/api/game/create.rs
M shared/src/api/game/mod.rs
M shared/src/api/game/mygames.rs
D shared/src/api/game/types.rs
M shared/src/api/mod.rs
M shared/src/api/game/all_forming.rs => shared/src/api/game/all_forming.rs +4 -4
@@ 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<types::Game>;
pub type ResultAllForming = Vec<Game>;

#[derive(Debug, Serialize, Deserialize)]
#[derive(Serialize, Deserialize)]
#[serde(untagged)]
pub enum ResponseAllForming {
    Error(APIErrorWrapper),
    Error(APIError),
    Valid(ResultAllForming),
}


M shared/src/api/game/create.rs => shared/src/api/game/create.rs +3 -3
@@ 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),
}


M shared/src/api/game/mod.rs => shared/src/api/game/mod.rs +6 -10
@@ 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::*;

M shared/src/api/game/mygames.rs => shared/src/api/game/mygames.rs +4 -4
@@ 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<types::Game>;
pub type ResultMyGames = Vec<Game>;

#[derive(Debug, Serialize, Deserialize)]
#[derive(Serialize, Deserialize)]
#[serde(untagged)]
pub enum ResponseMyGames {
    Error(APIErrorWrapper),
    Error(APIError),
    Valid(ResultMyGames),
}


D shared/src/api/game/types.rs => shared/src/api/game/types.rs +0 -67
@@ 1,67 0,0 @@
/*
 * This file is part of laurelin/shared
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * 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<Vec<Action>>,
    pub turn: GameTurn,
    pub host_hand: Option<String>,
    pub host_deck: Option<String>,
    pub guest_hand: Option<String>,
    pub guest_deck: Option<String>,
}

M shared/src/api/mod.rs => shared/src/api/mod.rs +1 -19
@@ 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,