Shopping list (WIP)

This commit is contained in:
Greg Burri 2025-02-11 19:39:13 +01:00
parent ce3821b94e
commit 084be9fb00
16 changed files with 296 additions and 90 deletions

View file

@ -618,7 +618,7 @@ pub async fn set_ingredients_order(
Ok(StatusCode::OK)
}
/// Calendar ///
/*** Calendar ***/
#[debug_handler]
pub async fn get_scheduled_recipes(
@ -692,7 +692,46 @@ pub async fn rm_scheduled_recipe(
Ok(StatusCode::OK)
}
/// 404 ///
/*** Shopping list ***/
impl From<model::ShoppingListItem> for common::ron_api::ShoppingListItem {
fn from(item: model::ShoppingListItem) -> Self {
Self {
id: item.id,
name: item.name,
quantity_value: item.quantity_value,
quantity_unit: item.quantity_unit,
recipe_id: item.recipe_id,
recipe_title: item.recipe_title,
date: item.date,
is_checked: item.is_checked,
}
}
}
#[debug_handler]
pub async fn get_shopping_list(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
) -> Result<impl IntoResponse> {
if let Some(user) = user {
Ok(ron_response_ok(
connection
.get_shopping_list(user.id)
.await?
.into_iter()
.map(common::ron_api::ShoppingListItem::from)
.collect::<Vec<_>>(),
))
} else {
Err(ErrorResponse::from(ron_error(
StatusCode::UNAUTHORIZED,
NOT_AUTHORIZED_MESSAGE,
)))
}
}
/*** 404 ***/
#[debug_handler]
pub async fn not_found(Extension(_user): Extension<Option<model::User>>) -> impl IntoResponse {