From f6638209b31397a7ac4c93d4a08c7d7fbc48b92a Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 16 Nov 2020 19:46:32 +0530 Subject: update models for product apis --- src/models.rs | 22 +++++++++++++++++++++- src/schema.rs | 15 +++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/models.rs b/src/models.rs index ce28ac8..fb6122c 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,4 +1,6 @@ -use super::schema::members; +use super::schema::{members, product}; + +use bigdecimal::BigDecimal; use diesel::{Insertable, Queryable}; use serde::{Deserialize, Serialize}; @@ -19,3 +21,21 @@ pub struct NewMember { pub phone_number: String, pub email_id: String, } + +#[derive(Queryable, Serialize)] +pub struct Product { + pub id: i32, + pub name: String, + pub kind: Option, + pub price: f32, + pub description: Option, +} + +#[derive(Insertable, Deserialize)] +#[table_name = "product"] +pub struct NewProduct { + pub name: String, + pub kind: Option, + pub price: f32, + pub description: Option, +} diff --git a/src/schema.rs b/src/schema.rs index 8ed6e58..b6074f2 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -7,3 +7,18 @@ table! { email_id -> Varchar, } } + +table! { + product (id) { + id -> Integer, + name -> Varchar, + kind -> Nullable, + price -> Float, + description -> Nullable, + } +} + +allow_tables_to_appear_in_same_query!( + members, + product, +); -- cgit v1.2.3