Add latest_interior_ref_list_by_shop_id endpoint

Not sure if this is correct yet, still waiting for rustc to compile...
This commit is contained in:
2020-10-20 01:13:40 -04:00
parent 97a2ac52dc
commit 0dc4247224
6 changed files with 84 additions and 9 deletions

View File

@@ -125,3 +125,21 @@ impl Model for InteriorRefList {
Ok(result)
}
}
impl InteriorRefList {
#[instrument(level = "debug", skip(db))]
pub async fn get_latest_by_shop_id(db: &PgPool, shop_id: i32) -> Result<Self> {
sqlx::query_as_unchecked!(
Self,
"SELECT interior_ref_lists.* FROM interior_ref_lists
INNER JOIN shops ON (interior_ref_lists.shop_id = shops.id)
WHERE shops.id = $1
ORDER BY interior_ref_lists.created_at DESC
LIMIT 1",
shop_id,
)
.fetch_one(db)
.await
.map_err(Error::new)
}
}

View File

@@ -7,6 +7,7 @@ use tracing::instrument;
use super::ListParams;
use super::{Model, UpdateableModel};
use crate::models::InteriorRefList;
use crate::problem::forbidden_permission;
#[derive(Debug, Serialize, Deserialize, Clone)]
@@ -103,7 +104,6 @@ impl Model for Shop {
}
}
#[async_trait]
impl UpdateableModel for Shop {
#[instrument(level = "debug", skip(self, db))]
@@ -132,4 +132,4 @@ impl UpdateableModel for Shop {
return Err(forbidden_permission());
}
}
}
}