Skip to content

Commit

Permalink
Fix TODO comments and set default quote service address
Browse files Browse the repository at this point in the history
  • Loading branch information
julianocosta89 committed Mar 5, 2024
1 parent 97e9c79 commit f78b32c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/shippingservice/src/shipping_service/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ use opentelemetry::{trace::get_active_span, KeyValue};
use reqwest_middleware::ClientBuilder;
use reqwest_tracing::{SpanBackendWithUrl, TracingMiddleware};

use reqwest::Method;

#[derive(Debug, Default)]
pub struct Quote {
pub dollars: i64,
pub cents: i32,
}

// TODO: Check product catalog for price on each item (will likley need item ID)
// TODO: Check product catalog for price on each item (will likely need item ID)
pub async fn create_quote_from_count(count: u32) -> Result<Quote, tonic::Status> {
let f = match request_quote(count).await {
Ok(float) => float,
Expand All @@ -40,10 +39,12 @@ pub async fn create_quote_from_count(count: u32) -> Result<Quote, tonic::Status>
}

async fn request_quote(count: u32) -> Result<f64, Box<dyn std::error::Error>> {
// TODO: better testing here and default quote_service_addr
let quote_service_addr: String = format!(
"{}{}",
env::var("QUOTE_SERVICE_ADDR").expect("$QUOTE_SERVICE_ADDR is not set"),
env::var("QUOTE_SERVICE_ADDR")
.unwrap_or_else(|_| "http://quoteservice:8090".to_string())
.parse::<String>()
.expect("Invalid quote service address"),
"/getquote"
);

Expand All @@ -54,9 +55,8 @@ async fn request_quote(count: u32) -> Result<f64, Box<dyn std::error::Error>> {
.with(TracingMiddleware::<SpanBackendWithUrl>::new())
.build();

let req = client.request(Method::POST, quote_service_addr);

let resp = req
let resp = client
.post(quote_service_addr)
.json(&reqbody)
.send()
.await?
Expand Down

0 comments on commit f78b32c

Please sign in to comment.