diff options
Diffstat (limited to 'src/models.rs')
-rw-r--r-- | src/models.rs | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/src/models.rs b/src/models.rs deleted file mode 100644 index a104209..0000000 --- a/src/models.rs +++ /dev/null | |||
@@ -1,97 +0,0 @@ | |||
1 | use super::schema::{cart_items, customer, product, rating, transaction}; | ||
2 | |||
3 | use chrono::naive::{NaiveDate, NaiveDateTime}; | ||
4 | use diesel::{Insertable, Queryable}; | ||
5 | use serde::{Deserialize, Serialize}; | ||
6 | |||
7 | /* Member */ | ||
8 | #[derive(Queryable, Serialize)] | ||
9 | pub 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"] | ||
20 | pub 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)] | ||
32 | pub 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"] | ||
42 | pub 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)] | ||
54 | pub 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)] | ||
63 | pub struct CartItem { | ||
64 | pub cart_id: i32, | ||
65 | pub product_id: i32, | ||
66 | } | ||
67 | |||
68 | #[derive(Insertable, Deserialize)] | ||
69 | #[table_name = "cart_items"] | ||
70 | pub struct AddCartItem { | ||
71 | pub cart_id: i32, | ||
72 | pub product_id: i32, | ||
73 | } | ||
74 | |||
75 | /* Rating */ | ||
76 | #[derive(Queryable, Serialize)] | ||
77 | pub 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"] | ||
88 | pub 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 | } | ||