Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
Derive appropriate macros on models
Browse files Browse the repository at this point in the history
  • Loading branch information
Muirrum committed Mar 4, 2021
1 parent 2955a09 commit 720cab4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
Cargo.lock
.env
/config/content.json
*.swp
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ derive_more = "0.99"
dotenv = "0.15"
reqwest = { version = "0.11.1", features = ["json"] }
tokio = "1.0"
time = {version="0.2", features=["serde", "std"]}

tokio-postgres = {version = "0.7", features = ["with-uuid-0_8"]}
sqlx = {version = "0.5.1", features=["postgres", "macros", "uuid", "time", "runtime-tokio-rustls"]}

[[bin]]
name = "yank_config"
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Config {
}

// I should _really_ use a different version of this for PlantArchetypes and PossessionArchetypes ...
pub type ArchetypeHandle = usize;
pub type ArchetypeHandle = u32;

lazy_static::lazy_static! {
pub static ref CONFIG: Config = {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![recursion_limit = "256"]
#![feature(try_trait)]
#![feature(trivial_bounds)]
#![warn(missing_docs)]

use humantime::{format_rfc3339, parse_rfc3339};
Expand Down
39 changes: 14 additions & 25 deletions src/models.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::config::{ArchetypeHandle, PlantArchetype};
use crate::*;
use serde::Serialize;
use std::time::SystemTime;
use tokio_postgres::Client as PgClient;
use tokio_postgres::error::Error as SqlError;
use time::PrimitiveDateTime;
use sqlx::types::Type;
use sqlx::FromRow;


#[derive(Clone, Debug, Serialize)]
#[derive(Clone, Debug, Serialize, FromRow)]
pub struct Hacksteader {
pub user_id: String,
pub profile: Profile,
Expand All @@ -15,53 +15,42 @@ pub struct Hacksteader {
pub gotchis: Vec<Possessed<possess::Gotchi>>,
}

#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Type)]
pub struct Tile {
pub acquired: SystemTime,
pub acquired: PrimitiveDateTime,
pub plant: Option<Plant>,
pub id: uuid::Uuid,
pub steader: String,
}

#[derive(Clone, Debug, Serialize)]
#[derive(Clone, Debug, Serialize, Type)]
pub struct Profile {
/// Indicates when this Hacksteader first joined the elite community.
pub joined: SystemTime,
pub last_active: SystemTime,
pub last_farm: SystemTime,
pub joined: PrimitiveDateTime,
pub last_active: PrimitiveDateTime,
pub last_farm: PrimitiveDateTime,
/// This is not an uuid::Uuid because it's actually the steader id of the person who owns this Profile
pub id: String,
pub xp: u64,
pub xp: u32,
}

#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Type)]
pub struct Plant {
pub xp: u64,
pub xp: u32,
pub until_yield: f32,
pub craft: Option<Craft>,
pub pedigree: Vec<possess::seed::SeedGrower>,
pub archetype_handle: ArchetypeHandle,
}

#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Type)]
pub struct Craft {
pub until_finish: f32,
pub total_cycles: f32,
pub destroys_plant: bool,
pub makes: ArchetypeHandle,
}

impl Hacksteader {
pub async fn insert_to_sql(&self, client: &PgClient) -> Result<(), SqlError> {

Ok(())
}

pub async fn update_in_sql(&self, client: &PgClient) -> Result<(), SqlError> {
Ok(())
}
}

impl std::ops::Deref for Plant {
type Target = PlantArchetype;

Expand Down
5 changes: 3 additions & 2 deletions src/possess/seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{config, AttributeParseError, Item, CONFIG};
use config::{ArchetypeHandle, ArchetypeKind};
use rusoto_dynamodb::AttributeValue;
use serde::{Deserialize, Serialize};
use sqlx::types::Type as PgType;

#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq)]
pub struct Seed {
Expand All @@ -17,10 +18,10 @@ impl Possessable for Seed {
PossessionKind::Seed(self)
}
}
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq)]
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, PgType)]
pub struct SeedGrower {
pub id: String,
pub generations: u64,
pub generations: u32,
}
impl SeedGrower {
pub fn new(id: String, generations: u64) -> Self {
Expand Down

0 comments on commit 720cab4

Please sign in to comment.