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

Commit

Permalink
Fix various bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
pohlm01 committed Sep 24, 2024
1 parent 262dcf1 commit 99b9f84
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion migrations/20240826084440_initial_scheme.sql
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ create table resource
primary key,
created_date_time timestamptz not null,
modification_date_time timestamptz not null,
resource_name text not null,
resource_name text not null unique,
ven_id text not null references ven (id), -- TODO is this actually 'NOT NULL'?
attributes jsonb,
targets jsonb
Expand Down
7 changes: 4 additions & 3 deletions openadr-vtn/src/api/ven.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ mod tests {
let resp = request_all(app, &token).await;

assert_eq!(resp.status(), http::StatusCode::OK);
let vens: Vec<Ven> = get_response_json(resp).await;
let mut vens: Vec<Ven> = get_response_json(resp).await;

assert_eq!(vens.len(), 2);
assert_eq!(vens[0].id.as_str(), "ven-2");
assert_eq!(vens[1].id.as_str(), "ven-1");
vens.sort_by(|a, b| a.id.as_str().cmp(b.id.as_str()));
assert_eq!(vens[0].id.as_str(), "ven-1");
assert_eq!(vens[1].id.as_str(), "ven-2");
}

#[sqlx::test(fixtures("users", "vens"))]
Expand Down
12 changes: 10 additions & 2 deletions openadr-vtn/src/data_source/postgres/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl VenScopedCrud for PgResourceStorage {
let pg_filter: PostgresFilter = filter.into();
trace!(?pg_filter);

Ok(sqlx::query_as!(
let res = sqlx::query_as!(
PostgresResource,
r#"
SELECT
Expand Down Expand Up @@ -228,7 +228,15 @@ impl VenScopedCrud for PgResourceStorage {
.await?
.into_iter()
.map(TryInto::try_into)
.collect::<Result<_, _>>()?)
.collect::<Result<Vec<_>, _>>()?;

trace!(
ven_id = ven_id.as_str(),
"retrieved {} resources",
res.len()
);

Ok(res)
}

async fn update(
Expand Down
2 changes: 1 addition & 1 deletion openadr-vtn/src/data_source/postgres/ven.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl Crud for PgVenStorage {
let mut vens: Vec<Ven> = sqlx::query_as!(
PostgresVen,
r#"
SELECT
SELECT DISTINCT
v.id AS "id!",
v.created_date_time AS "created_date_time!",
v.modification_date_time AS "modification_date_time!",
Expand Down
1 change: 1 addition & 0 deletions openadr-wire/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ iso8601-duration.workspace = true
thiserror.workspace = true
http.workspace = true
validator.workspace = true
tracing.workspace = true

[dev-dependencies]
serde_json.workspace = true
Expand Down

0 comments on commit 99b9f84

Please sign in to comment.