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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user