|
| 1 | +use crate::{ |
| 2 | + database::DbResult, |
| 3 | + utils::{ |
| 4 | + parsing::player_character::{PlayerCharacterPower, PlayerCharacterWeaponMod, WeaponId}, |
| 5 | + types::PlayerID, |
| 6 | + }, |
| 7 | +}; |
| 8 | +use futures_util::future::BoxFuture; |
| 9 | +use sea_orm::{entity::prelude::*, ActiveValue::Set, FromJsonQueryResult}; |
| 10 | +use serde::{Deserialize, Serialize}; |
| 11 | +use std::collections::HashMap; |
| 12 | + |
| 13 | +pub type GameReportModel = Model; |
| 14 | + |
| 15 | +/// Structure for player data |
| 16 | +#[derive(Serialize, Clone, Debug, PartialEq, Eq, DeriveEntityModel)] |
| 17 | +#[sea_orm(table_name = "game_report")] |
| 18 | +pub struct Model { |
| 19 | + /// Unique Identifier for the player data |
| 20 | + #[sea_orm(primary_key, column_type = "Integer")] |
| 21 | + pub id: i64, |
| 22 | + pub data: GameReportData, |
| 23 | + pub created_at: DateTimeUtc, |
| 24 | + pub finished_at: DateTimeUtc, |
| 25 | +} |
| 26 | + |
| 27 | +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, FromJsonQueryResult)] |
| 28 | +pub struct GameReportData { |
| 29 | + pub attributes: HashMap<String, String>, |
| 30 | + pub players: Vec<GameReportPlayer>, |
| 31 | + /// Randomness seed used by players |
| 32 | + pub seed: u32, |
| 33 | + /// Whether the extraction |
| 34 | + pub extracted: bool, |
| 35 | +} |
| 36 | + |
| 37 | +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] |
| 38 | +pub struct GameReportPlayer { |
| 39 | + /// ID of the player |
| 40 | + pub player_id: PlayerID, |
| 41 | + |
| 42 | + /// Player username |
| 43 | + pub player_name: String, |
| 44 | + |
| 45 | + /// Name of the player character kit the player was using |
| 46 | + pub kit_name: Option<String>, |
| 47 | + |
| 48 | + /// Player weapon list |
| 49 | + pub weapons: Option<Vec<WeaponId>>, |
| 50 | + |
| 51 | + /// Player weapon mods |
| 52 | + pub weapon_mods: Option<Vec<PlayerCharacterWeaponMod>>, |
| 53 | + |
| 54 | + /// Player power choices and levels |
| 55 | + pub powers: Option<Vec<PlayerCharacterPower>>, |
| 56 | +} |
| 57 | + |
| 58 | +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] |
| 59 | +pub enum Relation {} |
| 60 | + |
| 61 | +impl ActiveModelBehavior for ActiveModel {} |
| 62 | + |
| 63 | +impl Model { |
| 64 | + pub fn create( |
| 65 | + db: &DatabaseConnection, |
| 66 | + data: GameReportData, |
| 67 | + created_at: DateTimeUtc, |
| 68 | + finished_at: DateTimeUtc, |
| 69 | + ) -> BoxFuture<'_, DbResult<Self>> { |
| 70 | + ActiveModel { |
| 71 | + data: Set(data), |
| 72 | + created_at: Set(created_at), |
| 73 | + finished_at: Set(finished_at), |
| 74 | + ..Default::default() |
| 75 | + } |
| 76 | + .insert(db) |
| 77 | + } |
| 78 | +} |
0 commit comments