Skip to content

Commit 708edec

Browse files
committed
🔵 Better names
1 parent 73c663c commit 708edec

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
mod routes;
21
mod health_check;
2+
mod routes;
33
mod tiered_pricing;
44

55
use actix_web::{App, HttpServer};
@@ -14,17 +14,13 @@ fn get_address() -> String {
1414

1515
#[actix_web::main]
1616
async fn main() -> std::io::Result<()> {
17-
let server = HttpServer::new( || {
18-
App::new()
19-
.configure(routes)
20-
})
21-
.bind(get_address());
17+
let server = HttpServer::new(|| App::new().configure(routes)).bind(get_address());
2218

2319
match server {
2420
Ok(server) => {
2521
println!("🚀 Server running at {}", get_address());
2622
server.run().await
2723
}
28-
Err(_) => panic!("🔥 Coul not start the server at {}", get_address())
24+
Err(_) => panic!("🔥 Could not start the server at {}", get_address()),
2925
}
3026
}

exercises/tiered_pricing/solutions/isaac1024_baby-steps/src/routes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ use crate::tiered_pricing::tiered_pricing;
33
use actix_web::web;
44

55
pub fn routes(cfg: &mut web::ServiceConfig) {
6-
cfg.route("/health-check", web::get().to(health_check));
7-
cfg.route("/pricing", web::get().to(tiered_pricing));
6+
cfg.route("/health-check", web::get().to(health_check))
7+
.route("/pricing", web::get().to(tiered_pricing));
88
}

exercises/tiered_pricing/solutions/isaac1024_baby-steps/src/tiered_pricing.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,23 @@ use serde::{Deserialize, Serialize};
33
use std::fmt;
44

55
#[derive(Deserialize)]
6-
pub struct Pricing {
6+
pub struct TieredPricingQuery {
77
subscriptions: u32,
88
}
99

1010
#[derive(Serialize, Deserialize)]
11-
struct Subscriptions {
12-
pricing: u32,
11+
struct TieredPricingResponse {
12+
total_price: u32,
1313
}
1414

1515
#[derive(Serialize, Deserialize)]
1616
struct BadRequestMessage {
1717
error_message: String,
1818
}
1919

20-
pub async fn tiered_pricing(pricing: web::Query<Pricing>) -> impl Responder {
20+
pub async fn tiered_pricing(pricing: web::Query<TieredPricingQuery>) -> impl Responder {
2121
match get_total_subscription_price(pricing.subscriptions) {
22-
Ok(total_price) => HttpResponse::Ok().json(Subscriptions {
23-
pricing: total_price,
24-
}),
22+
Ok(total_price) => HttpResponse::Ok().json(TieredPricingResponse { total_price }),
2523
Err(error) => HttpResponse::BadRequest().json(BadRequestMessage {
2624
error_message: error.to_string(),
2725
}),
@@ -147,9 +145,9 @@ mod tests {
147145
.uri(format!("/pricing?subscriptions={}", number_of_subscriptions).as_str())
148146
.to_request();
149147

150-
let response: Subscriptions = test::call_and_read_body_json(&app, request).await;
148+
let response: TieredPricingResponse = test::call_and_read_body_json(&app, request).await;
151149

152-
assert_eq!(number_of_subscriptions * 149, response.pricing);
150+
assert_eq!(number_of_subscriptions * 149, response.total_price);
153151
}
154152

155153
#[actix_web::test]

0 commit comments

Comments
 (0)