diff options
author | tom barrett <spalf0@gmail.com> | 2019-03-28 10:18:53 -0500 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2019-03-29 07:42:22 -0500 |
commit | 50d92d677d6d53a83df15188c1b820b2b163e720 (patch) | |
tree | 4aa31171a8a00e8967c17b5eaf99afdf49e66724 /src/mass.rs | |
parent | f8c446ce74329fc5844e0fc1fd82e618242196f4 (diff) |
unified entires, now use main serde lib, added another postgres test assert, simplified
Diffstat (limited to 'src/mass.rs')
-rw-r--r-- | src/mass.rs | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/mass.rs b/src/mass.rs index ed859a4..cbac721 100644 --- a/src/mass.rs +++ b/src/mass.rs @@ -26,9 +26,10 @@ pub struct Mass { pub effects: Effects, } -#[derive(Queryable)] +#[derive(Queryable, Insertable)] +#[table_name = "db_masses"] pub struct MassEntry { - pub id: i32, + pub id: Option<i32>, pub name: String, pub pos_x: f64, pub pos_y: f64, @@ -39,17 +40,16 @@ pub struct MassEntry { pub type_data: serde_json::Value, } -#[derive(Insertable)] -#[table_name = "db_masses"] -pub struct NewMassEntry { - pub name: String, - pub pos_x: f64, - pub pos_y: f64, - pub pos_z: f64, - pub vel_x: f64, - pub vel_y: f64, - pub vel_z: f64, - pub type_data: serde_json::Value, +impl MassEntry { + pub fn to_mass(&self) -> Mass { + Mass { + position: Vector::new(self.pos_x, self.pos_y, self.pos_z), + velocity: Vector::new(self.vel_x, self.vel_y, self.vel_z), + mass_type: serde_json::from_str(&serde_json::to_string(&self.type_data).unwrap()) + .unwrap(), + effects: Effects::new(), + } + } } #[derive(Serialize, Deserialize, Debug, Clone, Default)] @@ -327,8 +327,9 @@ impl Mass { } } - pub fn to_new_mass_entry(&self, name: String) -> NewMassEntry { - NewMassEntry { + pub fn to_mass_entry(&self, name: String) -> MassEntry { + MassEntry { + id: None, name, pos_x: self.position.x, pos_y: self.position.y, |