Skip to content

Commit

Permalink
Add Update Methods for Shopping Tours
Browse files Browse the repository at this point in the history
  • Loading branch information
isiko committed May 29, 2024
1 parent fb93e25 commit 261606f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
30 changes: 28 additions & 2 deletions foodlib/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,41 @@ impl FoodBase {
tour_id: i32,
date: NaiveDateTime,
) -> eyre::Result<ShoppingTour> {
todo!()
let result = sqlx::query_as!(
ShoppingTour,
r#"
UPDATE shopping_tours
SET tour_date = $2
WHERE tour_id = $1
RETURNING *
"#,
tour_id,
date,
)
.fetch_one(&*self.pg_pool)
.await?;
Ok(result)
}

pub async fn update_event_shopping_tour_store(
&self,
tour_id: i32,
store_id: i32,
) -> eyre::Result<ShoppingTour> {
todo!()
let result = sqlx::query_as!(
ShoppingTour,
r#"
UPDATE shopping_tours
SET store_id = $2
WHERE tour_id = $1
RETURNING *
"#,
tour_id,
store_id
)
.fetch_one(&*self.pg_pool)
.await?;
Ok(result)
}

pub async fn get_event_food_prep(&self, event_id: i32) -> eyre::Result<Vec<FoodPrep>> {
Expand Down
28 changes: 28 additions & 0 deletions foodlib/src/ingredients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,34 @@ impl FoodBase {
.await
.map_err(Into::into)
}

pub async fn get_store_by_ref(&self, store_ref: String) -> eyre::Result<Store> {
if let Ok(store_id) = store_ref.parse::<i32>() {
let result = sqlx::query_as!(
Store,
r#"
SELECT * FROM stores
WHERE store_id = $1
"#,
store_id
)
.fetch_one(&*self.pg_pool)
.await;
Ok(result?)
} else {
let result = sqlx::query_as!(
Store,
r#"
SELECT * FROM stores
WHERE name = $1
"#,
store_ref
)
.fetch_one(&*self.pg_pool)
.await;
Ok(result?)
}
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Store {
Expand Down

0 comments on commit 261606f

Please sign in to comment.