Add delete endpoints and clean up filters

This commit is contained in:
2020-07-29 00:02:48 -04:00
parent 17cd3f12d2
commit 79b45551fd
7 changed files with 106 additions and 55 deletions

View File

@@ -55,7 +55,7 @@ impl Model for InteriorRefList {
)
}
#[instrument(level = "debug", skip(db))]
#[instrument(level = "debug", skip(self, db))]
async fn save(self, db: &PgPool) -> Result<Self> {
// TODO:
// * Decide if I'll need to make the same changes to merchandise and transactions
@@ -74,6 +74,15 @@ impl Model for InteriorRefList {
.await?)
}
#[instrument(level = "debug", skip(db))]
async fn delete(db: &PgPool, id: i32) -> Result<u64> {
Ok(
sqlx::query!("DELETE FROM interior_ref_lists WHERE id = $1", id)
.execute(db)
.await?,
)
}
#[instrument(level = "debug", skip(db))]
async fn list(db: &PgPool, list_params: ListParams) -> Result<Vec<Self>> {
let result = if let Some(order_by) = list_params.get_order_by() {

View File

@@ -24,8 +24,6 @@ where
}
async fn get(db: &PgPool, id: i32) -> Result<Self>;
async fn save(self, db: &PgPool) -> Result<Self>;
async fn delete(db: &PgPool, id: i32) -> Result<u64>;
async fn list(db: &PgPool, list_params: ListParams) -> Result<Vec<Self>>;
async fn bulk_save(_db: &PgPool, _models: Vec<Self>) -> Result<()> {
unimplemented!()
}
}

View File

@@ -57,6 +57,13 @@ impl Model for Owner {
.await?)
}
#[instrument(level = "debug", skip(db))]
async fn delete(db: &PgPool, id: i32) -> Result<u64> {
Ok(sqlx::query!("DELETE FROM owners WHERE id = $1", id)
.execute(db)
.await?)
}
#[instrument(level = "debug", skip(db))]
async fn list(db: &PgPool, list_params: ListParams) -> Result<Vec<Self>> {
let result = if let Some(order_by) = list_params.get_order_by() {

View File

@@ -62,6 +62,13 @@ impl Model for Shop {
.await?)
}
#[instrument(level = "debug", skip(db))]
async fn delete(db: &PgPool, id: i32) -> Result<u64> {
Ok(sqlx::query!("DELETE FROM shops WHERE id = $1", id)
.execute(db)
.await?)
}
#[instrument(level = "debug", skip(db))]
async fn list(db: &PgPool, list_params: ListParams) -> Result<Vec<Self>> {
let result = if let Some(order_by) = list_params.get_order_by() {