Skip to content

Commit d581864

Browse files
committed
🟢 Implement controller
1 parent 57ff935 commit d581864

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
use actix_web::{HttpResponse, Responder};
1+
use actix_web::{web, HttpResponse, Responder};
22
use serde::{Deserialize, Serialize};
33
use std::fmt;
44

5+
#[derive(Deserialize)]
6+
pub struct Pricing {
7+
subscriptions: u32,
8+
}
9+
510
#[derive(Serialize, Deserialize)]
611
struct Subscriptions {
712
pricing: u32,
813
}
914

10-
pub async fn tiered_pricing() -> impl Responder {
11-
HttpResponse::Ok().json(Subscriptions { pricing: 0 })
15+
pub async fn tiered_pricing(pricing: web::Query<Pricing>) -> impl Responder {
16+
let total_price = get_total_subscription_price(pricing.subscriptions).unwrap();
17+
HttpResponse::Ok().json(Subscriptions {
18+
pricing: total_price,
19+
})
1220
}
1321

1422
type SubscriptionResult<T> = Result<T, NumberSubscriptionsError>;

0 commit comments

Comments
 (0)