plm_rs/
models.rs

1use crate::schema::*;
2
3use chrono::NaiveDateTime;
4
5// TODO: Add manufacturer information
6#[derive(Identifiable, Queryable)]
7pub struct Part {
8    pub id: i32,
9    pub created_at: NaiveDateTime,
10    pub updated_at: NaiveDateTime,
11    pub pn: String,
12    pub mpn: String,
13    pub digikeypn: Option<String>,
14    pub descr: String,
15    pub ver: i32,
16    pub val: Option<String>,
17    pub mqty: i32,
18}
19
20#[derive(Eq, PartialEq, Debug, Insertable, AsChangeset)]
21#[table_name = "parts"]
22pub struct NewUpdatePart<'a> {
23    pub pn: &'a str,
24    pub mpn: &'a str,
25    pub descr: &'a str,
26    pub ver: &'a i32,
27    pub mqty: &'a i32,
28}
29
30#[derive(Identifiable, Queryable, Debug)]
31pub struct PartsPart {
32    pub id: i32,
33    pub created_at: NaiveDateTime,
34    pub updated_at: NaiveDateTime,
35    pub quantity: i32,
36    pub bom_ver: i32,
37    pub refdes: String,
38    pub nostuff: i32,
39    pub bom_part_id: i32,
40    pub part_id: i32,
41}
42
43#[derive(Eq, PartialEq, Debug, Insertable, AsChangeset)]
44#[table_name = "parts_parts"]
45pub struct NewPartsParts<'a> {
46    pub quantity: &'a i32,
47    pub bom_ver: &'a i32,
48    pub refdes: &'a str,
49    pub nostuff: &'a i32,
50    pub bom_part_id: &'a i32,
51    pub part_id: &'a i32,
52}
53
54// TODO: use as unit
55#[derive(Identifiable, Queryable)]
56#[table_name = "inventories"]
57pub struct Inventory {
58    pub id: i32,
59    pub created_at: NaiveDateTime,
60    pub updated_at: NaiveDateTime,
61    pub quantity: i32,
62    pub consumed: i32,
63    pub unit_price: Option<f32>,
64    pub notes: Option<String>,
65    pub part_ver: i32,
66    pub part_id: i32,
67}
68
69#[derive(Debug, Insertable, AsChangeset)]
70#[table_name = "inventories"]
71pub struct NewUpdateInventoryEntry<'a> {
72    pub quantity: &'a i32,
73    pub consumed: &'a i32,
74    pub unit_price: Option<&'a f32>,
75    pub notes: Option<&'a str>,
76    pub part_ver: &'a i32,
77    pub part_id: &'a i32,
78}
79
80#[derive(Identifiable, Queryable)]
81#[table_name = "builds"]
82pub struct Build {
83    pub id: i32,
84    pub created_at: NaiveDateTime,
85    pub updated_at: NaiveDateTime,
86    pub estimated_completion: NaiveDateTime,
87    pub quantity: i32,
88    pub cost: Option<f32>,
89    pub complete: i32,
90    pub notes: Option<String>,
91    pub part_ver: i32,
92    pub part_id: i32,
93}
94
95#[derive(Debug, Insertable, AsChangeset)]
96#[table_name = "builds"]
97pub struct NewUpdateBuild<'a> {
98    pub quantity: &'a i32,
99    pub complete: &'a i32,
100    pub notes: Option<&'a str>,
101    pub part_ver: &'a i32,
102    pub part_id: &'a i32,
103}