Add fetch_all_meal_plans APIStore implmentation

This commit is contained in:
Jeremy Wall 2023-01-17 06:39:43 -05:00
parent 811a04cebb
commit 8d5d044e9a
3 changed files with 47 additions and 0 deletions

View File

@ -264,6 +264,24 @@
},
"query": "delete from sessions where id = ?"
},
"7f4abc448b16e8b6b2bb74f8e810e245e81b38e1407085a20d28bfddfc06891f": {
"describe": {
"columns": [
{
"name": "plan_date: NaiveDate",
"ordinal": 0,
"type_info": "Date"
}
],
"nullable": [
false
],
"parameters": {
"Right": 1
}
},
"query": "select distinct plan_date as \"plan_date: NaiveDate\" from plan_recipes\nwhere user_id = ?"
},
"83824ea638cb64c524f5c8984ef6ef28dfe781f0abf168abc4ae9a51e6e0ae88": {
"describe": {
"columns": [],

View File

@ -0,0 +1,2 @@
select distinct plan_date as "plan_date: NaiveDate" from plan_recipes
where user_id = ?

View File

@ -127,6 +127,11 @@ pub trait APIStore {
date: NaiveDate,
) -> Result<Option<BTreeMap<NaiveDate, Vec<(String, i32)>>>>;
async fn fetch_all_meal_plans<S: AsRef<str> + Send>(
&self,
user_id: S,
) -> Result<Option<Vec<NaiveDate>>>;
async fn save_meal_plan<S: AsRef<str> + Send>(
&self,
user_id: S,
@ -519,6 +524,28 @@ impl APIStore for SqliteStore {
Ok(())
}
async fn fetch_all_meal_plans<S: AsRef<str> + Send>(
&self,
user_id: S,
) -> Result<Option<Vec<NaiveDate>>> {
let user_id = user_id.as_ref();
struct Row {
pub plan_date: NaiveDate,
}
let rows = sqlx::query_file_as!(Row, r#"src/web/storage/fetch_all_plans.sql"#, user_id,)
.fetch_all(self.pool.as_ref())
.await?;
if rows.is_empty() {
return Ok(None);
}
let mut result = Vec::new();
for row in rows {
let date: NaiveDate = row.plan_date;
result.push(date);
}
Ok(Some(result))
}
async fn fetch_meal_plans_since<S: AsRef<str> + Send>(
&self,
user_id: S,