Skip to content

Commit

Permalink
improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
StuartHarris committed Sep 23, 2024
1 parent 5746668 commit fcbf40a
Show file tree
Hide file tree
Showing 20 changed files with 211 additions and 194 deletions.
26 changes: 8 additions & 18 deletions wasm-components/rust/Cargo.lock

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

5 changes: 3 additions & 2 deletions wasm-components/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[workspace]
members = [
"common",
"data-init",
"http-controller",
"inventory-service",
Expand All @@ -11,8 +10,10 @@ members = [
resolver = "2"

[workspace.dependencies]
serde_json = "1.0.117"
anyhow = "1.0.89"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.117"
uuid = { version = "1.10.0" }
wit-bindgen = "0.32"

[profile.release]
Expand Down
7 changes: 0 additions & 7 deletions wasm-components/rust/common/src/inventory.rs

This file was deleted.

6 changes: 0 additions & 6 deletions wasm-components/rust/common/src/lib.rs

This file was deleted.

6 changes: 0 additions & 6 deletions wasm-components/rust/common/src/notification.rs

This file was deleted.

18 changes: 0 additions & 18 deletions wasm-components/rust/common/src/orders.rs

This file was deleted.

11 changes: 0 additions & 11 deletions wasm-components/rust/common/src/products.rs

This file was deleted.

1 change: 0 additions & 1 deletion wasm-components/rust/data-init/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ version = "0.1.0"
crate-type = ["cdylib"]

[dependencies]
common = { path = "../common" }
serde.workspace = true
serde_json.workspace = true
uuid = { version = "1.10.0", features = ["v4"] }
Expand Down
43 changes: 26 additions & 17 deletions wasm-components/rust/data-init/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ wit_bindgen::generate!({
generate_all,
});

use serde::{Deserialize, Serialize};
use uuid::Uuid;

use common::products::Product;
use exports::platform_poc::data_init::init_funcs::Guest;
use wasi::{
keyvalue::store::open,
Expand All @@ -21,6 +21,7 @@ use wasi::{
use wasmcloud::postgres::query::{query, PgValue};

struct Component;
export!(Component);

impl Guest for Component {
fn init_all() -> Result<(), String> {
Expand Down Expand Up @@ -139,100 +140,100 @@ impl Guest for Component {
}
}

fn sample_products() -> Vec<Product> {
fn sample_products() -> Vec<SerializableProduct> {
vec![
Product {
SerializableProduct {
id: Uuid::new_v4().to_string(),
name: String::from("Car Engine"),
description: String::from("V8 engine with 500 horsepower"),
price: 8500,
sku: String::from("ENG-V8-500"),
},
Product {
SerializableProduct {
id: Uuid::new_v4().to_string(),
name: String::from("Brake Pads"),
description: String::from("High performance brake pads"),
price: 150,
sku: String::from("BRK-PD-HP"),
},
Product {
SerializableProduct {
id: Uuid::new_v4().to_string(),
name: String::from("Air Filter"),
description: String::from("Premium air filter for increased airflow"),
price: 30,
sku: String::from("AIR-FLT-PREM"),
},
Product {
SerializableProduct {
id: Uuid::new_v4().to_string(),
name: String::from("Spark Plugs"),
description: String::from("High-efficiency spark plugs"),
price: 60,
sku: String::from("SPK-PLG-HI-EFF"),
},
Product {
SerializableProduct {
id: Uuid::new_v4().to_string(),
name: String::from("Tire Set"),
description: String::from("Set of 4 all-season tires"),
price: 600,
sku: String::from("TIR-SET-AS"),
},
Product {
SerializableProduct {
id: Uuid::new_v4().to_string(),
name: String::from("Battery"),
description: String::from("High-capacity car battery"),
price: 120,
sku: String::from("BAT-HC-12V"),
},
Product {
SerializableProduct {
id: Uuid::new_v4().to_string(),
name: String::from("Windshield Wipers"),
description: String::from("All-weather windshield wipers"),
price: 45,
sku: String::from("WND-WPR-AW"),
},
Product {
SerializableProduct {
id: Uuid::new_v4().to_string(),
name: String::from("Fuel Pump"),
description: String::from("Electric fuel pump for efficient fuel delivery"),
price: 220,
sku: String::from("FL-PMP-ELEC"),
},
Product {
SerializableProduct {
id: Uuid::new_v4().to_string(),
name: String::from("Radiator"),
description: String::from("High-efficiency car radiator"),
price: 320,
sku: String::from("RAD-HI-EFF"),
},
Product {
SerializableProduct {
id: Uuid::new_v4().to_string(),
name: String::from("Headlights"),
description: String::from("LED headlights with long lifespan"),
price: 250,
sku: String::from("HDL-LED-LONG"),
},
Product {
SerializableProduct {
id: Uuid::new_v4().to_string(),
name: String::from("Alternator"),
description: String::from("High output alternator for enhanced performance"),
price: 300,
sku: String::from("ALT-HO-ENH"),
},
Product {
SerializableProduct {
id: Uuid::new_v4().to_string(),
name: String::from("Exhaust System"),
description: String::from("Performance exhaust system"),
price: 750,
sku: String::from("EXH-SYS-PERF"),
},
Product {
SerializableProduct {
id: Uuid::new_v4().to_string(),
name: String::from("Suspension Kit"),
description: String::from("Complete suspension kit for improved handling"),
price: 900,
sku: String::from("SUS-KIT-IMP"),
},
Product {
SerializableProduct {
id: Uuid::new_v4().to_string(),
name: String::from("Turbocharger"),
description: String::from("High-performance turbocharger"),
Expand All @@ -242,4 +243,12 @@ fn sample_products() -> Vec<Product> {
]
}

export!(Component);
#[derive(Serialize, Deserialize)]
pub struct SerializableProduct {
/// UUID
pub id: String,
pub name: String,
pub description: String,
pub price: i32,
pub sku: String,
}
4 changes: 3 additions & 1 deletion wasm-components/rust/http-controller/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ version = "0.1.0"
crate-type = ["cdylib"]

[dependencies]
common = { path = "../common" }
anyhow.workspace = true
form_urlencoded = "1.2.1"
products-service = { version = "0.1.0", path = "../products-service" }
routefinder = "0.5.4"
serde.workspace = true
uuid = { workspace = true, features = ["v4", "serde"] }
waki = { version = "0.3.1", features = ["json"] }
wit-bindgen.workspace = true
Loading

0 comments on commit fcbf40a

Please sign in to comment.