Skip to content

Commit

Permalink
Merge pull request #5 from redbadger/notification-service
Browse files Browse the repository at this point in the history
Notification service
  • Loading branch information
StuartHarris authored Jan 3, 2024
2 parents f0e41e2 + 0219938 commit 33d09ae
Show file tree
Hide file tree
Showing 35 changed files with 1,970 additions and 77 deletions.
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,16 @@
"rust-containers-k8s/order-service/Cargo.toml",
"rust-containers-k8s/product-service/Cargo.toml"
],
"sqltools.connections": [
{
"previewLimit": 50,
"server": "localhost",
"port": 5432,
"driver": "PostgreSQL",
"name": "orders",
"database": "order-service",
"username": "order-service",
"password": "commerce"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ spec:
containerPort: 8082
protocol: TCP
env:
- name: PORT
value: "8082"
- name: DATABASE_URL
valueFrom:
secretKeyRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ spec:
containerPort: 8081
protocol: TCP
env:
env:
- name: PORT
value: "8081"
- name: DATABASE_URL
valueFrom:
secretKeyRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ spec:
containerPort: 8080
protocol: TCP
env:
- name: PORT
value: "8080"
- name: GCP_PROJECT_ID
value: {{ .Values.gcp.projectId }}
readinessProbe:
Expand Down
2 changes: 1 addition & 1 deletion rust-containers-k8s/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ services:
- zookeeper
volumes:
kafka-volume:
zookeeper-volume:
zookeeper-volume:
2 changes: 1 addition & 1 deletion rust-containers-k8s/infrastructure/storage/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ resource "google_firestore_database" "datastore_database" {
project = module.shared_vars.project_id
name = "(default)"
location_id = module.shared_vars.region
type = "DATASTORE_MODE"
type = "FIRESTORE_NATIVE"
delete_protection_state = "DELETE_PROTECTION_DISABLED"
deletion_policy = "DELETE"
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ SEQUENCE NAME public.t_inventory_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE
ALTER TABLE ONLY public.t_inventory
ADD CONSTRAINT t_inventory_pkey PRIMARY KEY (id);
--
-- PostgreSQL database dump complete
-- PostgreSQL database dump complete
7 changes: 4 additions & 3 deletions rust-containers-k8s/inventory-service/src/api/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ pub async fn get_inventory(

let mut result = Vec::new();
for sku in query.iter() {
let row: (i32,) =
let row: Option<(i32,)> =
sqlx::query_as("SELECT quantity FROM public.t_inventory WHERE sku_code = $1;")
.bind(sku)
.fetch_one(&state.pool)
.fetch_optional(&state.pool)
.await
.map_err(internal_error)?;
let is_in_stock = row.map(|(quantity,)| quantity > 0).unwrap_or(false);
result.push(GetInventoryResponse {
sku_code: sku.to_string(),
is_in_stock: row.0 > 0,
is_in_stock,
});
}

Expand Down
5 changes: 3 additions & 2 deletions rust-containers-k8s/inventory-service/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use dotenv::dotenv;
use inventory_service::{api::server, config::Config};
use sqlx::postgres::PgPoolOptions;
use tracing::info;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

#[tokio::main]
Expand All @@ -15,9 +16,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.init();

dotenv().ok();
let config = Config::new().expect("Config couldn't be loaded");

tracing::info!("{:?}", config);
let config = Config::new()?;
info!("{:?}", config);

let pool = PgPoolOptions::new()
.max_connections(5)
Expand Down
Loading

0 comments on commit 33d09ae

Please sign in to comment.