telemetry ftw

This commit is contained in:
2023-08-29 21:34:01 +02:00
parent 8ed85b6f72
commit 3719dfcef6
22 changed files with 650 additions and 68 deletions

View File

@@ -9,6 +9,7 @@ pub struct Inventory {
}
impl Inventory {
#[tracing::instrument]
pub async fn load(ctx: &Context, pool: &sqlx::Pool<sqlx::Sqlite>) -> Result<Self, Error> {
let user_id = ctx.user.id.to_string();
let mut categories = sqlx::query_as!(
@@ -64,6 +65,7 @@ impl TryFrom<DbCategoryRow> for Category {
}
impl Category {
#[tracing::instrument]
pub async fn _find(
ctx: &Context,
pool: &sqlx::Pool<sqlx::Sqlite>,
@@ -90,6 +92,7 @@ impl Category {
.transpose()
}
#[tracing::instrument]
pub async fn save(
ctx: &Context,
pool: &sqlx::Pool<sqlx::Sqlite>,
@@ -113,16 +116,19 @@ impl Category {
Ok(id)
}
#[tracing::instrument]
pub fn items(&self) -> &Vec<Item> {
self.items
.as_ref()
.expect("you need to call populate_items()")
}
#[tracing::instrument]
pub fn total_weight(&self) -> i64 {
self.items().iter().map(|item| item.weight).sum()
}
#[tracing::instrument]
pub async fn populate_items(
&mut self,
ctx: &Context,
@@ -157,6 +163,7 @@ impl Category {
}
}
#[derive(Debug)]
pub struct Product {
pub id: Uuid,
pub name: String,
@@ -164,6 +171,7 @@ pub struct Product {
pub comment: Option<String>,
}
#[derive(Debug)]
pub struct InventoryItem {
pub id: Uuid,
pub name: String,
@@ -218,6 +226,7 @@ impl TryFrom<DbInventoryItemRow> for InventoryItem {
}
impl InventoryItem {
#[tracing::instrument]
pub async fn find(
ctx: &Context,
pool: &sqlx::Pool<sqlx::Sqlite>,
@@ -257,6 +266,7 @@ impl InventoryItem {
.transpose()
}
#[tracing::instrument]
pub async fn name_exists(
ctx: &Context,
pool: &sqlx::Pool<sqlx::Sqlite>,
@@ -278,6 +288,7 @@ impl InventoryItem {
.is_some())
}
#[tracing::instrument]
pub async fn delete(
ctx: &Context,
pool: &sqlx::Pool<sqlx::Sqlite>,
@@ -299,6 +310,7 @@ impl InventoryItem {
Ok(results.rows_affected() != 0)
}
#[tracing::instrument]
pub async fn update(
ctx: &Context,
pool: &sqlx::Pool<sqlx::Sqlite>,
@@ -330,6 +342,7 @@ impl InventoryItem {
.await??)
}
#[tracing::instrument]
pub async fn save(
ctx: &Context,
pool: &sqlx::Pool<sqlx::Sqlite>,
@@ -360,6 +373,7 @@ impl InventoryItem {
Ok(id)
}
#[tracing::instrument]
pub async fn get_category_max_weight(
ctx: &Context,
pool: &sqlx::Pool<sqlx::Sqlite>,
@@ -424,6 +438,7 @@ impl TryFrom<DbInventoryItemsRow> for Item {
}
impl Item {
#[tracing::instrument]
pub async fn _get_category_total_picked_weight(
ctx: &Context,
pool: &sqlx::Pool<sqlx::Sqlite>,