DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

f2446f1f7c0e80f77b15ee09e1a2fde01a424881 — Jonni Liljamo 1 year, 9 months ago fbac14d
feat(api): impl models action, gamedata, game
M Cargo.lock => Cargo.lock +4 -2
@@ 473,6 473,7 @@ dependencies = [
 "log",
 "pretty_env_logger",
 "serde",
 "serde_json",
 "shared",
 "uuid 1.3.0",
]


@@ 2434,6 2435,7 @@ dependencies = [
 "itoa",
 "pq-sys",
 "r2d2",
 "serde_json",
 "uuid 1.3.0",
]



@@ 5348,9 5350,9 @@ dependencies = [

[[package]]
name = "serde_json"
version = "1.0.91"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea"
dependencies = [
 "itoa",
 "ryu",

M api/Cargo.toml => api/Cargo.toml +6 -1
@@ 25,6 25,11 @@ version = "1.0.152"
default-features = false
features = [ "derive" ]

[dependencies.serde_json]
version = "1.0.94"
default-features = false
features = [ "std" ]

[dependencies.chrono]
version = "0.4.23"
default-features = false


@@ 43,7 48,7 @@ features = [ "redis-actor-session" ]
[dependencies.diesel]
version = "2.0.3"
default-features = false
features = [ "with-deprecated", "32-column-tables", "postgres", "r2d2", "chrono", "uuid" ]
features = [ "with-deprecated", "32-column-tables", "postgres", "r2d2", "chrono", "uuid", "serde_json" ]

[dependencies.uuid]
version = "1.3.0"

A api/src/models/action.rs => api/src/models/action.rs +34 -0
@@ 0,0 1,34 @@
/*
 * This file is part of laurelin/api
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */

use chrono::NaiveDateTime;
use diesel::{Insertable, Queryable};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::schema::actions;

#[derive(Serialize, Queryable)]
pub(crate) struct Action {
    pub id: Uuid,
    pub created_at: NaiveDateTime,
    pub updated_at: NaiveDateTime,
    pub game_data_id: Uuid,
    pub invoker: Uuid,
    pub data: serde_json::Value,
    pub timestamp: NaiveDateTime,
}

#[derive(Deserialize, Insertable)]
#[diesel(table_name=actions)]
pub(crate) struct InsertableAction {
    pub game_data_id: Uuid,
    pub invoker: Uuid,
    pub data: serde_json::Value,
    pub timestamp: NaiveDateTime,
}

A api/src/models/game.rs => api/src/models/game.rs +36 -0
@@ 0,0 1,36 @@
/*
 * This file is part of laurelin/api
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */

use chrono::NaiveDateTime;
use diesel::{Insertable, Queryable};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::schema::games;

#[derive(Serialize, Queryable)]
pub(crate) struct Game {
    pub id: Uuid,
    pub created_at: NaiveDateTime,
    pub updated_at: NaiveDateTime,
    pub host_id: Uuid,
    pub guest_id: Option<Uuid>,
    pub state: i16,
    pub ended_at: Option<NaiveDateTime>,
    pub game_data_id: Uuid,
}

#[derive(Deserialize, Insertable)]
#[diesel(table_name=games)]
pub(crate) struct InsertableGame {
    pub host_id: Uuid,
    pub guest_id: Option<Uuid>,
    pub state: i16,
    pub ended_at: Option<NaiveDateTime>,
    pub game_data_id: Uuid,
}

A api/src/models/gamedata.rs => api/src/models/gamedata.rs +36 -0
@@ 0,0 1,36 @@
/*
 * This file is part of laurelin/api
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */

use chrono::NaiveDateTime;
use diesel::{Insertable, Queryable};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::schema::gamedata;

#[derive(Serialize, Queryable)]
pub(crate) struct GameData {
    pub id: Uuid,
    pub created_at: NaiveDateTime,
    pub updated_at: NaiveDateTime,
    pub turn: i16,
    pub host_hand: Option<serde_json::Value>,
    pub host_deck: Option<serde_json::Value>,
    pub guest_hand: Option<serde_json::Value>,
    pub guest_deck: Option<serde_json::Value>,
}

#[derive(Deserialize, Insertable)]
#[diesel(table_name=gamedata)]
pub(crate) struct InsertableGameData {
    pub turn: i16,
    pub host_hand: Option<serde_json::Value>,
    pub host_deck: Option<serde_json::Value>,
    pub guest_hand: Option<serde_json::Value>,
    pub guest_deck: Option<serde_json::Value>,
}

M api/src/models/mod.rs => api/src/models/mod.rs +9 -0
@@ 8,3 8,12 @@

mod user;
pub(crate) use user::*;

mod action;
pub(crate) use action::*;

mod game;
pub(crate) use game::*;

mod gamedata;
pub(crate) use gamedata::*;