Skip to content

Commit

Permalink
fix(pgstac): collection id is optional (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski authored Dec 4, 2024
1 parent 3f94183 commit 69439b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions crates/pgstac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub trait Pgstac: GenericClient {
}

/// Fetches an item.
async fn item(&self, id: &str, collection: &str) -> Result<Option<JsonValue>> {
async fn item(&self, id: &str, collection: Option<&str>) -> Result<Option<JsonValue>> {
self.opt("get_item", &[&id, &collection]).await
}

Expand Down Expand Up @@ -422,7 +422,7 @@ pub(crate) mod tests {
#[pgstac_test]
async fn item(client: &Transaction<'_>) {
assert!(client
.item("an-id", "collection-id")
.item("an-id", Some("collection-id"))
.await
.unwrap()
.is_none());
Expand All @@ -437,7 +437,7 @@ pub(crate) mod tests {
client.add_item(item.clone()).await.unwrap();
assert_eq!(
client
.item("an-id", "collection-id")
.item("an-id", Some("collection-id"))
.await
.unwrap()
.unwrap(),
Expand Down Expand Up @@ -466,7 +466,7 @@ pub(crate) mod tests {
client.update_item(item).await.unwrap();
assert_eq!(
client
.item("an-id", "collection-id")
.item("an-id", Some("collection-id"))
.await
.unwrap()
.unwrap()["properties"]["foo"],
Expand Down Expand Up @@ -496,12 +496,12 @@ pub(crate) mod tests {
other_item.id = "other-id".to_string();
client.add_items(&[item, other_item]).await.unwrap();
assert!(client
.item("an-id", "collection-id")
.item("an-id", Some("collection-id"))
.await
.unwrap()
.is_some());
assert!(client
.item("other-id", "collection-id")
.item("other-id", Some("collection-id"))
.await
.unwrap()
.is_some());
Expand Down
2 changes: 1 addition & 1 deletion crates/server/src/backend/pgstac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ where

async fn item(&self, collection_id: &str, item_id: &str) -> Result<Option<Item>> {
let client = self.pool.get().await?;
let value = client.item(item_id, collection_id).await?;
let value = client.item(item_id, Some(collection_id)).await?;
value
.map(serde_json::from_value)
.transpose()
Expand Down

0 comments on commit 69439b0

Please sign in to comment.