mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-22 19:40:14 -04:00
Add fetch_all_meal_plans APIStore implmentation
This commit is contained in:
parent
811a04cebb
commit
8d5d044e9a
@ -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": [],
|
||||
|
2
kitchen/src/web/storage/fetch_all_plans.sql
Normal file
2
kitchen/src/web/storage/fetch_all_plans.sql
Normal file
@ -0,0 +1,2 @@
|
||||
select distinct plan_date as "plan_date: NaiveDate" from plan_recipes
|
||||
where user_id = ?
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user