Add a RON API to search recipes by title + a bit of refactoring
This commit is contained in:
parent
a3f61e3711
commit
084f7ef445
26 changed files with 499 additions and 333 deletions
|
|
@ -20,10 +20,10 @@ use super::rights::*;
|
|||
pub async fn get_scheduled_recipes(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(context): Extension<Context>,
|
||||
date_range: Query<common::ron_api::DateRange>,
|
||||
date_range: Query<common::web_api::DateRange>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
if let Some(user) = context.user {
|
||||
Ok(ron_response_ok(common::ron_api::ScheduledRecipes {
|
||||
Ok(ron_response_ok(common::web_api::ScheduledRecipes {
|
||||
recipes: connection
|
||||
.get_scheduled_recipes(user.id, date_range.start_date, date_range.end_date)
|
||||
.await?,
|
||||
|
|
@ -36,7 +36,7 @@ pub async fn get_scheduled_recipes(
|
|||
}
|
||||
}
|
||||
|
||||
impl From<data::db::recipe::AddScheduledRecipeResult> for common::ron_api::ScheduleRecipeResult {
|
||||
impl From<data::db::recipe::AddScheduledRecipeResult> for common::web_api::ScheduleRecipeResult {
|
||||
fn from(db_res: data::db::recipe::AddScheduledRecipeResult) -> Self {
|
||||
match db_res {
|
||||
db::recipe::AddScheduledRecipeResult::Ok => Self::Ok,
|
||||
|
|
@ -51,7 +51,7 @@ impl From<data::db::recipe::AddScheduledRecipeResult> for common::ron_api::Sched
|
|||
pub async fn add_scheduled_recipe(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::ScheduleRecipe>,
|
||||
ExtractRon(ron): ExtractRon<common::web_api::ScheduleRecipe>,
|
||||
) -> Result<Response> {
|
||||
check_user_rights_recipe(&connection, &context.user, ron.recipe_id).await?;
|
||||
if let Some(user) = context.user {
|
||||
|
|
@ -65,7 +65,7 @@ pub async fn add_scheduled_recipe(
|
|||
)
|
||||
.await
|
||||
.map(|res| {
|
||||
ron_response_ok(common::ron_api::ScheduleRecipeResult::from(res)).into_response()
|
||||
ron_response_ok(common::web_api::ScheduleRecipeResult::from(res)).into_response()
|
||||
})
|
||||
.map_err(ErrorResponse::from)
|
||||
} else {
|
||||
|
|
@ -77,7 +77,7 @@ pub async fn add_scheduled_recipe(
|
|||
pub async fn rm_scheduled_recipe(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(context): Extension<Context>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::RemoveScheduledRecipe>,
|
||||
ExtractRon(ron): ExtractRon<common::web_api::RemoveScheduledRecipe>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
check_user_rights_recipe(&connection, &context.user, ron.recipe_id).await?;
|
||||
if let Some(user) = context.user {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue