aboutsummaryrefslogtreecommitdiff
path: root/backend/src/models.rs
diff options
context:
space:
mode:
Diffstat (limited to 'backend/src/models.rs')
-rw-r--r--backend/src/models.rs97
1 files changed, 97 insertions, 0 deletions
diff --git a/backend/src/models.rs b/backend/src/models.rs
new file mode 100644
index 0000000..a104209
--- /dev/null
+++ b/backend/src/models.rs
@@ -0,0 +1,97 @@
1use super::schema::{cart_items, customer, product, rating, transaction};
2
3use chrono::naive::{NaiveDate, NaiveDateTime};
4use diesel::{Insertable, Queryable};
5use serde::{Deserialize, Serialize};
6
7/* Member */
8#[derive(Queryable, Serialize)]
9pub struct Customer {
10 pub id: i32,
11 pub username: String,
12 pub password: String,
13 pub phone_number: String,
14 pub email_id: String,
15 pub address: Option<String>,
16}
17
18#[derive(Insertable, Deserialize)]
19#[table_name = "customer"]
20pub struct NewCustomer {
21 pub username: String,
22 pub password: String,
23 pub phone_number: String,
24 pub email_id: String,
25
26 #[serde(skip_serializing_if = "Option::is_none")]
27 pub address: Option<String>,
28}
29
30/* Product */
31#[derive(Queryable, Serialize)]
32pub struct Product {
33 pub id: i32,
34 pub name: String,
35 pub kind: Option<String>,
36 pub price: f32,
37 pub description: Option<String>,
38}
39
40#[derive(Insertable, Deserialize)]
41#[table_name = "product"]
42pub struct NewProduct {
43 pub name: String,
44
45 #[serde(skip_serializing_if = "Option::is_none")]
46 pub kind: Option<String>,
47 pub price: f32,
48
49 #[serde(skip_serializing_if = "Option::is_none")]
50 pub description: Option<String>,
51}
52
53#[derive(Deserialize)]
54pub struct UpdateProduct {
55 pub name: String,
56 pub kind: Option<String>,
57 pub price: f32,
58 pub description: Option<String>,
59}
60
61/* Cart Items */
62#[derive(Queryable, Serialize)]
63pub struct CartItem {
64 pub cart_id: i32,
65 pub product_id: i32,
66}
67
68#[derive(Insertable, Deserialize)]
69#[table_name = "cart_items"]
70pub struct AddCartItem {
71 pub cart_id: i32,
72 pub product_id: i32,
73}
74
75/* Rating */
76#[derive(Queryable, Serialize)]
77pub struct Rating {
78 pub id: i32,
79 pub comment_text: Option<String>,
80 pub comment_date: Option<NaiveDate>,
81 pub product_id: Option<i32>,
82 pub customer_id: Option<i32>,
83 pub stars: Option<i32>,
84}
85
86#[derive(Insertable, Deserialize)]
87#[table_name = "rating"]
88pub struct AddRating {
89 #[serde(skip_serializing_if = "Option::is_none")]
90 pub comment_text: Option<String>,
91
92 #[serde(skip_serializing_if = "Option::is_none")]
93 pub stars: Option<i32>,
94
95 pub product_id: i32,
96 pub customer_id: i32,
97}