Skip to content

Commit

Permalink
Update Table Headers (CLI)
Browse files Browse the repository at this point in the history
  • Loading branch information
isiko committed Jul 10, 2024
1 parent b39c06a commit 8573721
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
20 changes: 14 additions & 6 deletions foodlib/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ pub struct Event {

#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, Tabled)]
pub struct Place {
#[tabled(rename = "ID")]
pub place_id: i32,
#[tabled(rename = "Name")]
pub name: String,
#[tabled(display_with = "crate::util::display_optional")]
#[tabled(rename = "Comment", display_with = "crate::util::display_optional")]
pub comment: Option<String>,
}

Expand All @@ -42,20 +44,29 @@ impl Display for Place {

#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, Tabled)]
pub struct FoodPrep {
#[tabled(rename = "ID")]
pub prep_id: i32,
#[tabled(skip)]
pub event_id: i32,
#[tabled(rename = "Recipe ID")]
pub recipe_id: i32,
#[tabled(rename = "Prep Date")]
pub prep_date: NaiveDateTime,
#[tabled(display_with = "crate::util::display_optional")]
#[tabled(display_with = "crate::util::display_optional", rename = "Prep Date")]
pub use_from: Option<NaiveDateTime>,
#[tabled(rename = "Use Date")]
pub use_until: NaiveDateTime,
}

#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, Tabled)]
pub struct ShoppingTour {
#[tabled(rename = "ID")]
pub tour_id: i32,
#[tabled(skip)]
pub event_id: i32,
#[tabled(rename = "Date")]
pub tour_date: NaiveDateTime,
#[tabled(rename = "Store ID")]
pub store_id: i32,
}

Expand Down Expand Up @@ -258,10 +269,7 @@ impl FoodBase {
pub async fn get_event_cost(&self, event_id: i32) -> eyre::Result<PgMoney> {
let records = sqlx::query!(
r#"
SELECT
SUM(price) as price
FROM shopping_list
WHERE event_id = $1
SELECT SUM(price) as price FROM event_ingredients WHERE event_id = $1
"#,
event_id
)
Expand Down
12 changes: 10 additions & 2 deletions foodlib/src/meals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,34 @@ use crate::FoodBase;

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Tabled)]
pub struct Meal {
#[tabled(rename = "ID")]
pub meal_id: i32,
#[tabled(skip)]
pub event_id: i32,
#[tabled(skip)]
pub recipe_id: i32,
#[tabled(rename = "Recipe")]
pub name: String,
#[tabled(skip)]
pub place_id: i32,
pub place: String,
#[tabled(rename = "Start")]
pub start_time: NaiveDateTime,
#[tabled(rename = "End")]
pub end_time: NaiveDateTime,
#[tabled(rename = "Weight")]
pub weight: BigDecimal,
#[tabled(rename = "Energy")]
pub energy: BigDecimal,
#[serde(
serialize_with = "crate::util::serialize_money",
deserialize_with = "crate::util::deserialize_money"
)]
#[tabled(display_with = "crate::util::format_pg_money")]
#[tabled(rename = "Price", display_with = "crate::util::format_pg_money")]
pub price: PgMoney,
#[tabled(rename = "Servings")]
pub servings: i32,
#[tabled(display_with = "crate::util::display_optional")]
#[tabled(rename = "Comment", display_with = "crate::util::display_optional")]
pub comment: Option<String>,
}

Expand Down

0 comments on commit 8573721

Please sign in to comment.