Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate interval is present #41

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions openadr-client/tests/event.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use axum::http::StatusCode;
use openadr_client::{Error, Filter, PaginationOptions};
use openadr_wire::{
event::{EventContent, Priority},
event::{EventContent, EventInterval, EventType, EventValuesMap, Priority},
program::{ProgramContent, ProgramId},
target::{TargetEntry, TargetLabel, TargetMap},
values_map::Value,
};
use sqlx::PgPool;

Expand All @@ -17,7 +18,14 @@ fn default_content(program_id: &ProgramId) -> EventContent {
priority: Priority::MAX,
report_descriptors: None,
interval_period: None,
intervals: vec![],
intervals: vec![EventInterval {
id: 0,
interval_period: None,
payloads: vec![EventValuesMap {
value_type: EventType::Price,
values: vec![Value::Number(123.4)],
}],
}],
payload_descriptors: None,
targets: None,
}
Expand Down
14 changes: 11 additions & 3 deletions openadr-vtn/src/api/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ mod test {
};
use http_body_util::BodyExt;
use openadr_wire::{
event::{EventPayloadDescriptor, EventType, Priority},
event::{EventInterval, EventPayloadDescriptor, EventType, EventValuesMap, Priority},
problem::Problem,
target::{TargetEntry, TargetMap},
values_map::Value,
};
use reqwest::Method;
use sqlx::PgPool;
Expand All @@ -145,13 +146,20 @@ mod test {
priority: Priority::MAX,
report_descriptors: None,
interval_period: None,
intervals: vec![],
intervals: vec![EventInterval {
id: 0,
interval_period: None,
payloads: vec![EventValuesMap {
value_type: EventType::Price,
values: vec![Value::Number(123.4)],
}],
}],
payload_descriptors: None,
targets: None,
}
}

fn event_request(method: http::Method, event: Event, token: &str) -> Request<Body> {
fn event_request(method: Method, event: Event, token: &str) -> Request<Body> {
Request::builder()
.method(method)
.uri(format!("/events/{}", event.id))
Expand Down
4 changes: 3 additions & 1 deletion openadr-wire/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub struct EventContent {
/// Defines default start and durations of intervals.
pub interval_period: Option<IntervalPeriod>,
/// A list of interval objects.
#[validate(length(min = 1), nested)]
pub intervals: Vec<EventInterval>,
}

Expand Down Expand Up @@ -235,14 +236,15 @@ pub enum Currency {
/// An object defining a temporal window and a list of valuesMaps. if intervalPeriod present may set
/// temporal aspects of interval or override event.intervalPeriod.
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize, Validate)]
#[serde(rename_all = "camelCase")]
pub struct EventInterval {
/// A client generated number assigned an interval object. Not a sequence number.
pub id: i32,
/// Defines default start and durations of intervals.
pub interval_period: Option<IntervalPeriod>,
/// A list of valuesMap objects.
#[validate(length(min = 1))]
pub payloads: Vec<EventValuesMap>,
}

Expand Down
4 changes: 2 additions & 2 deletions openadr-wire/src/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::{values_map::ValuesMap, Duration};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;

/// An object defining a temporal window and a list of valuesMaps. if intervalPeriod present may set
/// temporal aspects of interval or override event.intervalPeriod.
Expand Down Expand Up @@ -30,17 +31,16 @@ impl Interval {

/// Defines temporal aspects of intervals. A duration of default null indicates infinity. A
/// randomizeStart of default null indicates no randomization.
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IntervalPeriod {
/// The start time of an interval or set of intervals.
#[serde(with = "crate::serde_rfc3339")]
pub start: DateTime<Utc>,
/// The duration of an interval or set of intervals.
#[serde(skip_serializing_if = "Option::is_none")]
pub duration: Option<Duration>,
/// Indicates a randomization time that may be applied to start.
#[serde(skip_serializing_if = "Option::is_none")]
pub randomize_start: Option<Duration>,
}

Expand Down
Loading