fplanner/src/app/structure.rs

58 lines
1.3 KiB
Rust

use chrono::prelude::*;
use std::collections::{BTreeMap, HashMap};
use uuid::Uuid;
use super::components::Component;
#[derive(serde::Deserialize, serde::Serialize, PartialEq, Debug)]
pub enum License {
MIT,
GPL,
AGPL,
CNPL,
}
#[derive(serde::Deserialize, serde::Serialize, Clone, Debug)]
#[serde(default)]
pub struct Layer {
pub zindex: usize,
pub label: String,
pub visible: bool,
pub components: HashMap<Uuid, Component>,
}
impl Default for Layer {
fn default() -> Self {
Self {
zindex: 0,
visible: true,
label: String::default(),
components: HashMap::new(),
}
}
}
#[derive(serde::Deserialize, serde::Serialize, Debug)]
#[serde(default)] // if we add new fields, give them default values when deserializing old state
pub struct Project {
pub id: Uuid,
pub name: String,
pub created: DateTime<Utc>,
pub modified: Option<DateTime<Utc>>,
pub license: License,
pub layers: BTreeMap<usize, Layer>,
}
impl Default for Project {
fn default() -> Self {
Self {
id: Uuid::new_v4(),
name: "".to_string(),
created: Utc::now(),
modified: None,
license: License::MIT,
layers: BTreeMap::default(),
}
}
}