mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-22 19:40:14 -04:00
api for meal plan deletion
This commit is contained in:
parent
2ffb3be114
commit
ad62c5f31f
@ -258,6 +258,22 @@ async fn api_all_plans(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn api_delete_plan_for_date(
|
||||||
|
Extension(app_store): Extension<Arc<storage::SqliteStore>>,
|
||||||
|
session: storage::UserIdFromSession,
|
||||||
|
Path(date): Path<chrono::NaiveDate>,
|
||||||
|
) -> api::EmptyResponse {
|
||||||
|
use storage::{UserId, UserIdFromSession::FoundUserId};
|
||||||
|
if let FoundUserId(UserId(id)) = session {
|
||||||
|
app_store
|
||||||
|
.delete_meal_plan_for_date(id.as_str(), date)
|
||||||
|
.await
|
||||||
|
.into()
|
||||||
|
} else {
|
||||||
|
api::EmptyResponse::Unauthorized
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn api_save_plan_for_date(
|
async fn api_save_plan_for_date(
|
||||||
Extension(app_store): Extension<Arc<storage::SqliteStore>>,
|
Extension(app_store): Extension<Arc<storage::SqliteStore>>,
|
||||||
session: storage::UserIdFromSession,
|
session: storage::UserIdFromSession,
|
||||||
|
@ -138,6 +138,12 @@ pub trait APIStore {
|
|||||||
user_id: S,
|
user_id: S,
|
||||||
) -> Result<Option<Vec<NaiveDate>>>;
|
) -> Result<Option<Vec<NaiveDate>>>;
|
||||||
|
|
||||||
|
async fn delete_meal_plan_for_date<S: AsRef<str> + Send>(
|
||||||
|
&self,
|
||||||
|
user_id: S,
|
||||||
|
date: NaiveDate,
|
||||||
|
) -> Result<()>;
|
||||||
|
|
||||||
async fn save_meal_plan<S: AsRef<str> + Send>(
|
async fn save_meal_plan<S: AsRef<str> + Send>(
|
||||||
&self,
|
&self,
|
||||||
user_id: S,
|
user_id: S,
|
||||||
@ -615,6 +621,44 @@ impl APIStore for SqliteStore {
|
|||||||
Ok(Some(result))
|
Ok(Some(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn delete_meal_plan_for_date<S: AsRef<str> + Send>(
|
||||||
|
&self,
|
||||||
|
user_id: S,
|
||||||
|
date: NaiveDate,
|
||||||
|
) -> Result<()> {
|
||||||
|
let user_id = user_id.as_ref();
|
||||||
|
let mut transaction = self.pool.as_ref().begin().await?;
|
||||||
|
sqlx::query!(
|
||||||
|
"delete from plan_recipes where user_id = ? and plan_date = ?",
|
||||||
|
user_id,
|
||||||
|
date
|
||||||
|
)
|
||||||
|
.execute(&mut transaction)
|
||||||
|
.await?;
|
||||||
|
sqlx::query!(
|
||||||
|
"delete from filtered_ingredients where user_id = ? and plan_date = ?",
|
||||||
|
user_id,
|
||||||
|
date
|
||||||
|
)
|
||||||
|
.execute(&mut transaction)
|
||||||
|
.await?;
|
||||||
|
sqlx::query!(
|
||||||
|
"delete from modified_amts where user_id = ? and plan_date = ?",
|
||||||
|
user_id,
|
||||||
|
date
|
||||||
|
)
|
||||||
|
.execute(&mut transaction)
|
||||||
|
.await?;
|
||||||
|
sqlx::query!(
|
||||||
|
"delete from extra_items where user_id = ? and plan_date = ?",
|
||||||
|
user_id,
|
||||||
|
date
|
||||||
|
)
|
||||||
|
.execute(&mut transaction)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn fetch_meal_plan_for_date<S: AsRef<str> + Send>(
|
async fn fetch_meal_plan_for_date<S: AsRef<str> + Send>(
|
||||||
&self,
|
&self,
|
||||||
user_id: S,
|
user_id: S,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user