Add a toggle between dark and light theme
This commit is contained in:
parent
d22617538e
commit
559ed139aa
34 changed files with 640 additions and 469 deletions
|
|
@ -8,7 +8,7 @@ use axum_extra::extract::Query;
|
|||
use common::ron_api;
|
||||
// use tracing::{event, Level};
|
||||
|
||||
use crate::{data::db, model, ron_extractor::ExtractRon, ron_utils::ron_response_ok};
|
||||
use crate::{Context, data::db, model, ron_extractor::ExtractRon, ron_utils::ron_response_ok};
|
||||
|
||||
use super::rights::*;
|
||||
|
||||
|
|
@ -27,10 +27,10 @@ pub async fn get_titles(
|
|||
#[debug_handler]
|
||||
pub async fn set_title(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::SetRecipeTitle>,
|
||||
) -> Result<StatusCode> {
|
||||
check_user_rights_recipe(&connection, &user, ron.recipe_id).await?;
|
||||
check_user_rights_recipe(&connection, &context.user, ron.recipe_id).await?;
|
||||
connection
|
||||
.set_recipe_title(ron.recipe_id, &ron.title)
|
||||
.await?;
|
||||
|
|
@ -40,10 +40,10 @@ pub async fn set_title(
|
|||
#[debug_handler]
|
||||
pub async fn set_description(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::SetRecipeDescription>,
|
||||
) -> Result<StatusCode> {
|
||||
check_user_rights_recipe(&connection, &user, ron.recipe_id).await?;
|
||||
check_user_rights_recipe(&connection, &context.user, ron.recipe_id).await?;
|
||||
connection
|
||||
.set_recipe_description(ron.recipe_id, &ron.description)
|
||||
.await?;
|
||||
|
|
@ -53,10 +53,10 @@ pub async fn set_description(
|
|||
#[debug_handler]
|
||||
pub async fn set_servings(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::SetRecipeServings>,
|
||||
) -> Result<StatusCode> {
|
||||
check_user_rights_recipe(&connection, &user, ron.recipe_id).await?;
|
||||
check_user_rights_recipe(&connection, &context.user, ron.recipe_id).await?;
|
||||
connection
|
||||
.set_recipe_servings(ron.recipe_id, ron.servings)
|
||||
.await?;
|
||||
|
|
@ -66,10 +66,10 @@ pub async fn set_servings(
|
|||
#[debug_handler]
|
||||
pub async fn set_estimated_time(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::SetRecipeEstimatedTime>,
|
||||
) -> Result<StatusCode> {
|
||||
check_user_rights_recipe(&connection, &user, ron.recipe_id).await?;
|
||||
check_user_rights_recipe(&connection, &context.user, ron.recipe_id).await?;
|
||||
connection
|
||||
.set_recipe_estimated_time(ron.recipe_id, ron.estimated_time)
|
||||
.await?;
|
||||
|
|
@ -90,10 +90,10 @@ pub async fn get_tags(
|
|||
#[debug_handler]
|
||||
pub async fn add_tags(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::Tags>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe(&connection, &user, ron.recipe_id).await?;
|
||||
check_user_rights_recipe(&connection, &context.user, ron.recipe_id).await?;
|
||||
connection
|
||||
.add_recipe_tags(
|
||||
ron.recipe_id,
|
||||
|
|
@ -109,10 +109,10 @@ pub async fn add_tags(
|
|||
#[debug_handler]
|
||||
pub async fn rm_tags(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::Tags>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe(&connection, &user, ron.recipe_id).await?;
|
||||
check_user_rights_recipe(&connection, &context.user, ron.recipe_id).await?;
|
||||
connection.rm_recipe_tags(ron.recipe_id, &ron.tags).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
|
@ -120,10 +120,10 @@ pub async fn rm_tags(
|
|||
#[debug_handler]
|
||||
pub async fn set_difficulty(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::SetRecipeDifficulty>,
|
||||
) -> Result<StatusCode> {
|
||||
check_user_rights_recipe(&connection, &user, ron.recipe_id).await?;
|
||||
check_user_rights_recipe(&connection, &context.user, ron.recipe_id).await?;
|
||||
connection
|
||||
.set_recipe_difficulty(ron.recipe_id, ron.difficulty)
|
||||
.await?;
|
||||
|
|
@ -133,7 +133,7 @@ pub async fn set_difficulty(
|
|||
#[debug_handler]
|
||||
pub async fn set_language(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::SetRecipeLanguage>,
|
||||
) -> Result<StatusCode> {
|
||||
if !crate::translation::available_codes()
|
||||
|
|
@ -144,7 +144,7 @@ pub async fn set_language(
|
|||
return Ok(StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
check_user_rights_recipe(&connection, &user, ron.recipe_id).await?;
|
||||
check_user_rights_recipe(&connection, &context.user, ron.recipe_id).await?;
|
||||
connection
|
||||
.set_recipe_language(ron.recipe_id, &ron.lang)
|
||||
.await?;
|
||||
|
|
@ -154,10 +154,10 @@ pub async fn set_language(
|
|||
#[debug_handler]
|
||||
pub async fn set_is_published(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::SetIsPublished>,
|
||||
) -> Result<StatusCode> {
|
||||
check_user_rights_recipe(&connection, &user, ron.recipe_id).await?;
|
||||
check_user_rights_recipe(&connection, &context.user, ron.recipe_id).await?;
|
||||
connection
|
||||
.set_recipe_is_published(ron.recipe_id, ron.is_published)
|
||||
.await?;
|
||||
|
|
@ -167,10 +167,10 @@ pub async fn set_is_published(
|
|||
#[debug_handler]
|
||||
pub async fn rm(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::Id>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe(&connection, &user, ron.id).await?;
|
||||
check_user_rights_recipe(&connection, &context.user, ron.id).await?;
|
||||
connection.rm_recipe(ron.id).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
|
@ -231,10 +231,10 @@ pub async fn get_groups(
|
|||
#[debug_handler]
|
||||
pub async fn add_group(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::Id>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe(&connection, &user, ron.id).await?;
|
||||
check_user_rights_recipe(&connection, &context.user, ron.id).await?;
|
||||
let id = connection.add_recipe_group(ron.id).await?;
|
||||
|
||||
Ok(ron_response_ok(ron_api::Id { id }))
|
||||
|
|
@ -243,10 +243,10 @@ pub async fn add_group(
|
|||
#[debug_handler]
|
||||
pub async fn rm_group(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::Id>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_group(&connection, &user, ron.id).await?;
|
||||
check_user_rights_recipe_group(&connection, &context.user, ron.id).await?;
|
||||
connection.rm_recipe_group(ron.id).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
|
@ -254,10 +254,10 @@ pub async fn rm_group(
|
|||
#[debug_handler]
|
||||
pub async fn set_group_name(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::SetGroupName>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_group(&connection, &user, ron.group_id).await?;
|
||||
check_user_rights_recipe_group(&connection, &context.user, ron.group_id).await?;
|
||||
connection.set_group_name(ron.group_id, &ron.name).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
|
@ -265,10 +265,10 @@ pub async fn set_group_name(
|
|||
#[debug_handler]
|
||||
pub async fn set_group_comment(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::SetGroupComment>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_group(&connection, &user, ron.group_id).await?;
|
||||
check_user_rights_recipe_group(&connection, &context.user, ron.group_id).await?;
|
||||
connection
|
||||
.set_group_comment(ron.group_id, &ron.comment)
|
||||
.await?;
|
||||
|
|
@ -278,10 +278,10 @@ pub async fn set_group_comment(
|
|||
#[debug_handler]
|
||||
pub async fn set_groups_order(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::Ids>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_groups(&connection, &user, &ron.ids).await?;
|
||||
check_user_rights_recipe_groups(&connection, &context.user, &ron.ids).await?;
|
||||
connection.set_groups_order(&ron.ids).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
|
@ -289,10 +289,10 @@ pub async fn set_groups_order(
|
|||
#[debug_handler]
|
||||
pub async fn add_step(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::Id>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_group(&connection, &user, ron.id).await?;
|
||||
check_user_rights_recipe_group(&connection, &context.user, ron.id).await?;
|
||||
let id = connection.add_recipe_step(ron.id).await?;
|
||||
|
||||
Ok(ron_response_ok(ron_api::Id { id }))
|
||||
|
|
@ -301,10 +301,10 @@ pub async fn add_step(
|
|||
#[debug_handler]
|
||||
pub async fn rm_step(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::Id>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_step(&connection, &user, ron.id).await?;
|
||||
check_user_rights_recipe_step(&connection, &context.user, ron.id).await?;
|
||||
connection.rm_recipe_step(ron.id).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
|
@ -312,10 +312,10 @@ pub async fn rm_step(
|
|||
#[debug_handler]
|
||||
pub async fn set_step_action(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::SetStepAction>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_step(&connection, &user, ron.step_id).await?;
|
||||
check_user_rights_recipe_step(&connection, &context.user, ron.step_id).await?;
|
||||
connection.set_step_action(ron.step_id, &ron.action).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
|
@ -323,10 +323,10 @@ pub async fn set_step_action(
|
|||
#[debug_handler]
|
||||
pub async fn set_steps_order(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::Ids>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_steps(&connection, &user, &ron.ids).await?;
|
||||
check_user_rights_recipe_steps(&connection, &context.user, &ron.ids).await?;
|
||||
connection.set_steps_order(&ron.ids).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
|
@ -334,10 +334,10 @@ pub async fn set_steps_order(
|
|||
#[debug_handler]
|
||||
pub async fn add_ingredient(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::Id>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_step(&connection, &user, ron.id).await?;
|
||||
check_user_rights_recipe_step(&connection, &context.user, ron.id).await?;
|
||||
let id = connection.add_recipe_ingredient(ron.id).await?;
|
||||
Ok(ron_response_ok(ron_api::Id { id }))
|
||||
}
|
||||
|
|
@ -345,10 +345,10 @@ pub async fn add_ingredient(
|
|||
#[debug_handler]
|
||||
pub async fn rm_ingredient(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::Id>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_ingredient(&connection, &user, ron.id).await?;
|
||||
check_user_rights_recipe_ingredient(&connection, &context.user, ron.id).await?;
|
||||
connection.rm_recipe_ingredient(ron.id).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
|
@ -356,10 +356,10 @@ pub async fn rm_ingredient(
|
|||
#[debug_handler]
|
||||
pub async fn set_ingredient_name(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::SetIngredientName>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_ingredient(&connection, &user, ron.ingredient_id).await?;
|
||||
check_user_rights_recipe_ingredient(&connection, &context.user, ron.ingredient_id).await?;
|
||||
connection
|
||||
.set_ingredient_name(ron.ingredient_id, &ron.name)
|
||||
.await?;
|
||||
|
|
@ -369,10 +369,10 @@ pub async fn set_ingredient_name(
|
|||
#[debug_handler]
|
||||
pub async fn set_ingredient_comment(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::SetIngredientComment>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_ingredient(&connection, &user, ron.ingredient_id).await?;
|
||||
check_user_rights_recipe_ingredient(&connection, &context.user, ron.ingredient_id).await?;
|
||||
connection
|
||||
.set_ingredient_comment(ron.ingredient_id, &ron.comment)
|
||||
.await?;
|
||||
|
|
@ -382,10 +382,10 @@ pub async fn set_ingredient_comment(
|
|||
#[debug_handler]
|
||||
pub async fn set_ingredient_quantity(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::SetIngredientQuantity>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_ingredient(&connection, &user, ron.ingredient_id).await?;
|
||||
check_user_rights_recipe_ingredient(&connection, &context.user, ron.ingredient_id).await?;
|
||||
connection
|
||||
.set_ingredient_quantity(ron.ingredient_id, ron.quantity)
|
||||
.await?;
|
||||
|
|
@ -395,10 +395,10 @@ pub async fn set_ingredient_quantity(
|
|||
#[debug_handler]
|
||||
pub async fn set_ingredient_unit(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::SetIngredientUnit>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_ingredient(&connection, &user, ron.ingredient_id).await?;
|
||||
check_user_rights_recipe_ingredient(&connection, &context.user, ron.ingredient_id).await?;
|
||||
connection
|
||||
.set_ingredient_unit(ron.ingredient_id, &ron.unit)
|
||||
.await?;
|
||||
|
|
@ -408,10 +408,10 @@ pub async fn set_ingredient_unit(
|
|||
#[debug_handler]
|
||||
pub async fn set_ingredients_order(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<ron_api::Ids>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe_ingredients(&connection, &user, &ron.ids).await?;
|
||||
check_user_rights_recipe_ingredients(&connection, &context.user, &ron.ids).await?;
|
||||
connection.set_ingredients_order(&ron.ids).await?;
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue