From bba1d9ca198c2129c8fd0d819aca0f377dce06ac Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Tue, 17 Jan 2023 13:02:47 -0500 Subject: [PATCH] Wire up the http endpoint for fetch all plans --- kitchen/src/web/mod.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/kitchen/src/web/mod.rs b/kitchen/src/web/mod.rs index 2e78fe1..ab4a4ec 100644 --- a/kitchen/src/web/mod.rs +++ b/kitchen/src/web/mod.rs @@ -23,6 +23,7 @@ use axum::{ response::{IntoResponse, Redirect, Response}, routing::{get, Router}, }; +use chrono::NaiveDate; use mime_guess; use recipes::{IngredientKey, RecipeEntry}; use rust_embed::RustEmbed; @@ -232,6 +233,18 @@ async fn api_plan_since( } } +async fn api_all_plans( + Extension(app_store): Extension>, + session: storage::UserIdFromSession, +) -> api::Response> { + use storage::{UserId, UserIdFromSession::FoundUserId}; + if let FoundUserId(UserId(id)) = session { + app_store.fetch_all_meal_plans(&id).await.into() + } else { + api::Response::Unauthorized + } +} + async fn api_save_plan( Extension(app_store): Extension>, session: storage::UserIdFromSession, @@ -408,7 +421,8 @@ fn mk_v2_routes() -> Router { ) // mealplan api path routes .route("/plan", get(api_plan).post(api_save_plan)) - .route("/plan/:date", get(api_plan_since)) + .route("/plan/since/:date", get(api_plan_since)) + .route("/plan/all", get(api_all_plans)) .route( "/inventory", get(api_inventory_v2).post(api_save_inventory_v2),