Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.

Commit

Permalink
feat: schemars
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Jul 12, 2023
1 parent 945829a commit c4a1b9b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ license = "MIT OR Apache-2.0"
keywords = ["geospatial", "stac", "metadata", "raster", "database"]
categories = ["database", "data-structures", "science"]

[features]
schemars = ["dep:schemars", "stac/schemars", "stac-api/schemars"]

[dependencies]
geojson = "0.24"
schemars = {version = "0.8", optional = true }
serde = "1"
serde_json = "1"
stac = { version = "0.5", git = "https://github.com/gadomski/stac-rs" }
Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ See the [documentation](https://docs.rs/pgstac) for more.

**pgstac-rs** needs a blank **pgstac** database for testing.
The repo comes with a [docker-compose](./docker-compose.yml) to run one.
To start the database:

```shell
docker-compose up
```

Then you can test as normal:
To test:

```shell
docker-compose up -d
cargo test
docker-compose down
```

Each test is run in its own transaction, which is rolled back after the test.
Expand Down
50 changes: 34 additions & 16 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,14 @@ mod tests {
use stac_api::{Fields, Filter, Search, Sortby};
use tokio_postgres::Transaction;

fn longmont() -> Geometry {
Geometry::new(Value::Point(vec![-105.1019, 40.1672]))
fn longmont() -> stac::Geometry {
serde_json::from_value(
serde_json::to_value(geojson::Geometry::new(geojson::Value::Point(vec![
-105.1019, 40.1672,
])))
.unwrap(),
)
.unwrap()
}

#[pgstac_test]
Expand Down Expand Up @@ -514,24 +520,36 @@ mod tests {
item.geometry = Some(longmont());
client.add_item(item.clone()).await.unwrap();
let search = Search {
intersects: Some(Geometry::new(Value::Polygon(vec![vec![
vec![-106., 40.],
vec![-106., 41.],
vec![-105., 41.],
vec![-105., 40.],
vec![-106., 40.],
]]))),
intersects: Some(
serde_json::from_value(
serde_json::to_value(Geometry::new(Value::Polygon(vec![vec![
vec![-106., 40.],
vec![-106., 41.],
vec![-105., 41.],
vec![-105., 40.],
vec![-106., 40.],
]])))
.unwrap(),
)
.unwrap(),
),
..Default::default()
};
assert_eq!(client.search(search).await.unwrap().features.len(), 1);
let search = Search {
intersects: Some(Geometry::new(Value::Polygon(vec![vec![
vec![-104., 40.],
vec![-104., 41.],
vec![-103., 41.],
vec![-103., 40.],
vec![-104., 40.],
]]))),
intersects: Some(
serde_json::from_value(
serde_json::to_value(Geometry::new(Value::Polygon(vec![vec![
vec![-104., 40.],
vec![-104., 41.],
vec![-103., 41.],
vec![-103., 40.],
vec![-104., 40.],
]])))
.unwrap(),
)
.unwrap(),
),
..Default::default()
};
assert!(client.search(search).await.unwrap().features.is_empty());
Expand Down
1 change: 1 addition & 0 deletions src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use stac_api::Context;

/// A page of search results.
#[derive(Debug, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Page {
/// This should always be "FeatureCollection".
pub r#type: String,
Expand Down

0 comments on commit c4a1b9b

Please sign in to comment.