Calendar (WIP)
This commit is contained in:
parent
9d3f9e9c60
commit
79a0aeb1b8
24 changed files with 613 additions and 231 deletions
|
|
@ -5,6 +5,7 @@ use axum::{
|
|||
response::{ErrorResponse, IntoResponse, Result},
|
||||
};
|
||||
use axum_extra::extract::cookie::{Cookie, CookieJar};
|
||||
use chrono::NaiveDate;
|
||||
use serde::Deserialize;
|
||||
// use tracing::{event, Level};
|
||||
|
||||
|
|
@ -183,11 +184,11 @@ async fn check_user_rights_recipe_ingredient(
|
|||
async fn check_user_rights_recipe_ingredients(
|
||||
connection: &db::Connection,
|
||||
user: &Option<model::User>,
|
||||
step_ids: &[i64],
|
||||
ingredient_ids: &[i64],
|
||||
) -> Result<()> {
|
||||
if user.is_none()
|
||||
|| !connection
|
||||
.can_edit_recipe_all_ingredients(user.as_ref().unwrap().id, step_ids)
|
||||
.can_edit_recipe_all_ingredients(user.as_ref().unwrap().id, ingredient_ids)
|
||||
.await?
|
||||
{
|
||||
Err(ErrorResponse::from(ron_error(
|
||||
|
|
@ -599,7 +600,39 @@ pub async fn set_ingredients_order(
|
|||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
||||
///// 404 /////
|
||||
/// Calendar ///
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct DateRange {
|
||||
start_date: NaiveDate,
|
||||
end_date: NaiveDate,
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn get_scheduled_recipes(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
date_range: Query<DateRange>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
if let Some(user) = user {
|
||||
Ok(ron_response(
|
||||
StatusCode::OK,
|
||||
common::ron_api::ScheduledRecipes {
|
||||
recipes: connection
|
||||
.get_scheduled_recipes(user.id, date_range.start_date, date_range.end_date)
|
||||
.await?,
|
||||
},
|
||||
))
|
||||
} 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 {
|
||||
ron_error(StatusCode::NOT_FOUND, "Not found")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue