telemetry ftw
This commit is contained in:
@@ -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>,
|
||||
|
||||
@@ -14,7 +14,7 @@ use serde_variant::to_variant_name;
|
||||
use time;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(sqlx::Type, PartialEq, PartialOrd, Deserialize)]
|
||||
#[derive(sqlx::Type, PartialEq, PartialOrd, Deserialize, Debug)]
|
||||
pub enum TripState {
|
||||
Init,
|
||||
Planning,
|
||||
@@ -118,6 +118,7 @@ pub struct TripCategory {
|
||||
}
|
||||
|
||||
impl TripCategory {
|
||||
#[tracing::instrument]
|
||||
pub fn total_picked_weight(&self) -> i64 {
|
||||
self.items
|
||||
.as_ref()
|
||||
@@ -128,6 +129,7 @@ impl TripCategory {
|
||||
.sum()
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn find(
|
||||
ctx: &Context,
|
||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||
@@ -288,6 +290,7 @@ impl TryFrom<DbTripsItemsRow> for TripItem {
|
||||
}
|
||||
|
||||
impl TripItem {
|
||||
#[tracing::instrument]
|
||||
pub async fn find(
|
||||
ctx: &Context,
|
||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||
@@ -327,6 +330,7 @@ impl TripItem {
|
||||
.transpose()
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn set_state(
|
||||
ctx: &Context,
|
||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||
@@ -391,6 +395,7 @@ impl TryFrom<DbTripRow> for Trip {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Trip {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
@@ -426,6 +431,7 @@ pub(crate) struct DbTripWeightRow {
|
||||
}
|
||||
|
||||
impl Trip {
|
||||
#[tracing::instrument]
|
||||
pub async fn all(ctx: &Context, pool: &sqlx::Pool<sqlx::Sqlite>) -> Result<Vec<Trip>, Error> {
|
||||
let user_id = ctx.user.id.to_string();
|
||||
sqlx::query_as!(
|
||||
@@ -452,6 +458,7 @@ impl Trip {
|
||||
.collect::<Result<Vec<Trip>, Error>>()
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn find(
|
||||
ctx: &Context,
|
||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||
@@ -482,6 +489,7 @@ impl Trip {
|
||||
.transpose()
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn trip_type_remove(
|
||||
ctx: &Context,
|
||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||
@@ -512,6 +520,7 @@ impl Trip {
|
||||
Ok(results.rows_affected() != 0)
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn trip_type_add(
|
||||
ctx: &Context,
|
||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||
@@ -545,6 +554,7 @@ impl Trip {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn set_state(
|
||||
ctx: &Context,
|
||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||
@@ -567,6 +577,7 @@ impl Trip {
|
||||
Ok(result.rows_affected() != 0)
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn set_comment(
|
||||
ctx: &Context,
|
||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||
@@ -589,6 +600,7 @@ impl Trip {
|
||||
Ok(result.rows_affected() != 0)
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn set_attribute(
|
||||
ctx: &Context,
|
||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||
@@ -616,6 +628,7 @@ impl Trip {
|
||||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn save(
|
||||
ctx: &Context,
|
||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||
@@ -649,6 +662,7 @@ impl Trip {
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn find_total_picked_weight(
|
||||
ctx: &Context,
|
||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||
@@ -680,18 +694,21 @@ impl Trip {
|
||||
Ok(weight)
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub fn types(&self) -> &Vec<TripType> {
|
||||
self.types
|
||||
.as_ref()
|
||||
.expect("you need to call load_trips_types()")
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub fn categories(&self) -> &Vec<TripCategory> {
|
||||
self.categories
|
||||
.as_ref()
|
||||
.expect("you need to call load_trips_types()")
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub fn total_picked_weight(&self) -> i64 {
|
||||
self.categories()
|
||||
.iter()
|
||||
@@ -707,6 +724,7 @@ impl Trip {
|
||||
.sum::<i64>()
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn load_trips_types(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
@@ -758,6 +776,7 @@ impl Trip {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn sync_trip_items_with_inventory(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
@@ -838,6 +857,7 @@ impl Trip {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn load_categories(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
@@ -955,6 +975,7 @@ impl Trip {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TripType {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
@@ -962,6 +983,7 @@ pub struct TripType {
|
||||
}
|
||||
|
||||
impl TripsType {
|
||||
#[tracing::instrument]
|
||||
pub async fn all(ctx: &Context, pool: &sqlx::Pool<sqlx::Sqlite>) -> Result<Vec<Self>, Error> {
|
||||
let user_id = ctx.user.id.to_string();
|
||||
sqlx::query_as!(
|
||||
@@ -981,6 +1003,7 @@ impl TripsType {
|
||||
.collect::<Result<Vec<Self>, Error>>()
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn save(
|
||||
ctx: &Context,
|
||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||
@@ -1004,6 +1027,7 @@ impl TripsType {
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn set_name(
|
||||
ctx: &Context,
|
||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||
@@ -1039,6 +1063,7 @@ pub enum TripTypeAttribute {
|
||||
Name,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TripsType {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
|
||||
@@ -8,6 +8,7 @@ pub struct User {
|
||||
pub fullname: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NewUser<'a> {
|
||||
pub username: &'a str,
|
||||
pub fullname: &'a str,
|
||||
@@ -33,6 +34,7 @@ impl TryFrom<DbUserRow> for User {
|
||||
}
|
||||
|
||||
impl User {
|
||||
#[tracing::instrument]
|
||||
pub async fn find_by_name(
|
||||
pool: &sqlx::Pool<sqlx::Sqlite>,
|
||||
name: &str,
|
||||
@@ -49,6 +51,7 @@ impl User {
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn create(pool: &sqlx::Pool<sqlx::Sqlite>, user: NewUser<'_>) -> Result<Uuid, Error> {
|
||||
let id = Uuid::new_v4();
|
||||
let id_param = id.to_string();
|
||||
|
||||
Reference in New Issue
Block a user