Skip to content

Commit

Permalink
fix: db formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bennjii committed Dec 17, 2023
1 parent c79ba67 commit 86bd8b9
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 97 deletions.
109 changes: 58 additions & 51 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ sea-orm-migration = { version = "0.12.1", optional = true }
sea-orm = { version = "0.12.1", features = [
"macros",
"runtime-tokio-native-tls",
"sqlx-mysql"
"sqlx-mysql",
"rust_decimal"
], optional = true}

# Traits & Futures
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ COPY ./Rocket.toml ./
ARG RELEASE_TYPE

# build for release or dev depending on what is desired
RUN if [ ${RELEASE_TYPE} = "dev" ]; then cargo build --locked --jobs 1 ; else ROCKET_ENV=prod cargo build --release --locked ; fi
RUN if [ ${RELEASE_TYPE} = "dev" ]; then cargo build --locked --jobs 1 ; else ROCKET_ENV=prod cargo build --release --locked --jobs 8 ; fi

# move that file up the tree
RUN if [ ${RELEASE_TYPE} = "dev" ]; then cp /open-stock/target/debug/open-stock . ; else cp /open-stock/target/release/open-stock . ; fi
Expand Down
2 changes: 1 addition & 1 deletion src/entities/customer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct Model {
pub name: String,
pub contact: Json,
pub customer_notes: Json,
pub balance: u32,
pub balance: i64,
pub special_pricing: Json,
pub accepts_marketing: bool,
pub tenant_id: String,
Expand Down
2 changes: 1 addition & 1 deletion src/entities/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct Model {
pub customer: Json,
pub transaction_type: TransactionType,
pub products: Json,
pub order_total: f32,
pub order_total: i64,
pub payment: Json,
pub order_date: DateTime,
pub order_notes: Json,
Expand Down
4 changes: 2 additions & 2 deletions src/methods/customer/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct Customer {
pub contact: ContactInformation,

pub customer_notes: NoteList,
pub balance: u32,
pub balance: i64,

pub special_pricing: String,
pub accepts_marketing: bool,
Expand Down Expand Up @@ -81,7 +81,7 @@ pub struct CustomerInput {
pub customer_notes: NoteList,

pub special_pricing: String,
pub balance: u32,
pub balance: i64,

pub accepts_marketing: bool,
}
Expand Down
51 changes: 30 additions & 21 deletions src/methods/helpers/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use rocket_okapi::{openapi, openapi_get_routes_spec};
use rocket_okapi::settings::OpenApiSettings;
use schemars::JsonSchema;
use sea_orm::EntityTrait;
use serde_json::json;
use crate::session::ActiveModel;

pub fn documented_routes(_settings: &OpenApiSettings) -> (Vec<rocket::Route>, OpenApi) {
Expand Down Expand Up @@ -69,23 +70,32 @@ pub async fn generate_template(conn: Connection<Db>) -> Result<Json<All>, Error>
tenant_id: tenant_id2.to_string().clone(),
};

let tenant = Tenant::generate(&db, tenant_id).await.unwrap();
let tenant2 = Tenant::generate(&db, tenant_id2).await.unwrap();

let employee = Employee::generate(&db, session.clone()).await.unwrap();
let _employee2 = Employee::generate(&db, session2.clone()).await.unwrap();

let stores = Store::generate(session.clone(), &db).await.unwrap();
let products = Product::generate(session.clone(), &db).await.unwrap();
let customer = Customer::generate(session.clone(), &db).await.unwrap();

let kiosk = Kiosk::generate("adbd48ab-f4ca-4204-9c88-3516f3133621", session.clone(), &db)
.await
.unwrap();

let _kiosk2 = Kiosk::generate("adbd48ab-f4ca-4204-9c88-3516f3133622", session2.clone(), &db)
.await
.unwrap();
// Add Tenants
let tenant = Tenant::generate(&db, tenant_id).await
.map_err(|e| ErrorResponse::db_err(e))?;
let tenant2 = Tenant::generate(&db, tenant_id2).await
.map_err(|e| ErrorResponse::db_err(e))?;

// Add Employees
let employee = Employee::generate(&db, session.clone()).await
.map_err(|e| ErrorResponse::db_err(e))?;
let _employee2 = Employee::generate(&db, session2.clone()).await
.map_err(|e| ErrorResponse::db_err(e))?;

// Add other items (aggregated)
let stores = Store::generate(session.clone(), &db).await
.map_err(|e| ErrorResponse::db_err(e))?;
let products = Product::generate(session.clone(), &db).await
.map_err(|e| ErrorResponse::db_err(e))?;
let customer = Customer::generate(session.clone(), &db).await
.map_err(|e| ErrorResponse::db_err(e))?;

// Add Kiosks
let kiosk = Kiosk::generate("adbd48ab-f4ca-4204-9c88-3516f3133621", session.clone(), &db).await
.map_err(|e| ErrorResponse::db_err(e))?;

let _kiosk2 = Kiosk::generate("adbd48ab-f4ca-4204-9c88-3516f3133622", session2.clone(), &db).await
.map_err(|e| ErrorResponse::db_err(e))?;

let transaction = Transaction::generate(
&db,
Expand All @@ -97,10 +107,9 @@ pub async fn generate_template(conn: Connection<Db>) -> Result<Json<All>, Error>
expiry: Utc::now(),
tenant_id: tenant_id.to_string(),
},
)
.await
.unwrap();
let promotions = Promotion::generate(session, &db).await.unwrap();
).await.map_err(|e| ErrorResponse::db_err(e))?;

let promotions = Promotion::generate(session, &db).await.map_err(|e| ErrorResponse::db_err(e))?;

Ok(Json(All {
employee,
Expand Down
4 changes: 2 additions & 2 deletions src/methods/product/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ impl Product {
name_long: Set(self.name_long),
description_long: Set(self.description_long),
tenant_id: Set(session.tenant_id),
created_at: Default::default(),
updated_at: Default::default(),
created_at: Set(self.created_at.naive_utc()),
updated_at: Set(self.created_at.naive_utc()),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/methods/store/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ impl Store {
contact: Set(json!(self.contact)),
code: Set(self.code),
tenant_id: Set(session.tenant_id),
created_at: Default::default(),
updated_at: Default::default(),
created_at: Set(self.created_at.naive_utc()),
updated_at: Set(self.updated_at.naive_utc()),
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/methods/store/example.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chrono::Utc;
use crate::{Address, ContactInformation, Email, MobileNumber, Store};

pub fn example_stores() -> Vec<Store> {
Expand Down Expand Up @@ -28,8 +29,8 @@ pub fn example_stores() -> Vec<Store> {
},
},
code: "001".to_string(),
created_at: Default::default(),
updated_at: Default::default(),
created_at: Utc::now(),
updated_at: Utc::now(),
},
Store {
id: "c4a1d88b-e8a0-4dcd-ade2-1eea82254816".to_string(),
Expand Down Expand Up @@ -57,8 +58,8 @@ pub fn example_stores() -> Vec<Store> {
},
},
code: "002".to_string(),
created_at: Default::default(),
updated_at: Default::default(),
created_at: Utc::now(),
updated_at: Utc::now(),
},
Store {
id: "a91509fa-2783-43ae-8c3c-5d5bc5cb6c95".to_string(),
Expand Down Expand Up @@ -86,8 +87,8 @@ pub fn example_stores() -> Vec<Store> {
},
},
code: "003".to_string(),
created_at: Default::default(),
updated_at: Default::default(),
created_at: Utc::now(),
updated_at: Utc::now(),
},
]
}
Loading

0 comments on commit 86bd8b9

Please sign in to comment.