diff options
Diffstat (limited to 'src/models.rs')
-rw-r--r-- | src/models.rs | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/src/models.rs b/src/models.rs index 6af1af6..acd67a6 100644 --- a/src/models.rs +++ b/src/models.rs | |||
@@ -1,26 +1,32 @@ | |||
1 | use super::schema::{members, product}; | 1 | use super::schema::{cart_items, customer, product, rating, transaction}; |
2 | 2 | ||
3 | use diesel::{Insertable, Queryable}; | 3 | use diesel::{Insertable, Queryable}; |
4 | use serde::{Deserialize, Serialize}; | 4 | use serde::{Deserialize, Serialize}; |
5 | 5 | ||
6 | /* Member */ | ||
6 | #[derive(Queryable, Serialize)] | 7 | #[derive(Queryable, Serialize)] |
7 | pub struct Member { | 8 | pub struct Customer { |
8 | pub id: i32, | 9 | pub id: i32, |
9 | pub username: String, | 10 | pub username: String, |
10 | pub password: String, | 11 | pub password: String, |
11 | pub phone_number: String, | 12 | pub phone_number: String, |
12 | pub email_id: String, | 13 | pub email_id: String, |
14 | pub address: Option<String>, | ||
13 | } | 15 | } |
14 | 16 | ||
15 | #[derive(Insertable, Deserialize)] | 17 | #[derive(Insertable, Deserialize)] |
16 | #[table_name = "members"] | 18 | #[table_name = "customer"] |
17 | pub struct NewMember { | 19 | pub struct NewCustomer { |
18 | pub username: String, | 20 | pub username: String, |
19 | pub password: String, | 21 | pub password: String, |
20 | pub phone_number: String, | 22 | pub phone_number: String, |
21 | pub email_id: String, | 23 | pub email_id: String, |
24 | |||
25 | #[serde(skip_serializing_if = "Option::is_none")] | ||
26 | pub address: Option<String>, | ||
22 | } | 27 | } |
23 | 28 | ||
29 | /* Product */ | ||
24 | #[derive(Queryable, Serialize)] | 30 | #[derive(Queryable, Serialize)] |
25 | pub struct Product { | 31 | pub struct Product { |
26 | pub id: i32, | 32 | pub id: i32, |
@@ -42,3 +48,25 @@ pub struct NewProduct { | |||
42 | #[serde(skip_serializing_if = "Option::is_none")] | 48 | #[serde(skip_serializing_if = "Option::is_none")] |
43 | pub description: Option<String>, | 49 | pub description: Option<String>, |
44 | } | 50 | } |
51 | |||
52 | #[derive(Deserialize)] | ||
53 | pub struct UpdateProduct { | ||
54 | pub name: String, | ||
55 | pub kind: Option<String>, | ||
56 | pub price: f32, | ||
57 | pub description: Option<String>, | ||
58 | } | ||
59 | |||
60 | /* Cart Items */ | ||
61 | #[derive(Queryable, Serialize)] | ||
62 | pub struct CartItem { | ||
63 | pub cart_id: i32, | ||
64 | pub product_id: i32, | ||
65 | } | ||
66 | |||
67 | #[derive(Insertable, Deserialize)] | ||
68 | #[table_name = "cart_items"] | ||
69 | pub struct AddCartItem { | ||
70 | pub cart_id: i32, | ||
71 | pub product_id: i32, | ||
72 | } | ||