mirror of
https://github.com/supleed2/cch23-8bit.git
synced 2024-12-22 14:05:48 +00:00
Day 7 fixes
This commit is contained in:
parent
5cbb7bd794
commit
dbb73b6bb3
|
@ -25,14 +25,14 @@ async fn decode(
|
||||||
|
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
struct Bake {
|
struct Bake {
|
||||||
recipe: HashMap<String, i32>,
|
recipe: HashMap<String, i64>,
|
||||||
pantry: HashMap<String, i32>,
|
pantry: HashMap<String, i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize)]
|
||||||
struct Cookies {
|
struct Cookies {
|
||||||
cookies: i32,
|
cookies: i64,
|
||||||
pantry: HashMap<String, i32>,
|
pantry: HashMap<String, i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn bake(
|
async fn bake(
|
||||||
|
@ -44,8 +44,12 @@ async fn bake(
|
||||||
let decoded = general_purpose::STANDARD
|
let decoded = general_purpose::STANDARD
|
||||||
.decode(recipe)
|
.decode(recipe)
|
||||||
.map_err(|e| (StatusCode::BAD_REQUEST, format!("{e:?}")))?;
|
.map_err(|e| (StatusCode::BAD_REQUEST, format!("{e:?}")))?;
|
||||||
let Bake { recipe, mut pantry } = serde_json::from_slice(&decoded)
|
let Bake {
|
||||||
|
mut recipe,
|
||||||
|
mut pantry,
|
||||||
|
} = serde_json::from_slice(&decoded)
|
||||||
.map_err(|e| (StatusCode::BAD_REQUEST, format!("{e:?}")))?;
|
.map_err(|e| (StatusCode::BAD_REQUEST, format!("{e:?}")))?;
|
||||||
|
recipe.retain(|_, v| v != &0);
|
||||||
if let Some(cookies) = recipe
|
if let Some(cookies) = recipe
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(i, a)| pantry.get(i).map(|p| p / a))
|
.map(|(i, a)| pantry.get(i).map(|p| p / a))
|
||||||
|
|
Loading…
Reference in a new issue