Skip to content

Commit

Permalink
Create program before retrieving it
Browse files Browse the repository at this point in the history
  • Loading branch information
rnijveld committed Jun 10, 2024
1 parent 1d4ae47 commit b435313
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/cli/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use openadr::wire::program::ProgramContent;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = openadr::Client::new("http://localhost/openadr/".try_into()?);
let client = openadr::Client::new("http://localhost:3000/".try_into()?);
let created_program = client.create_program(ProgramContent::new("name")).await?;
let created_program_1 = client.create_program(ProgramContent::new("name1")).await?;
dbg!(created_program);
dbg!(created_program_1);
let _program = client.get_program_by_name("name").await?;
// let events = program.get_all_events().await?;

Expand Down
2 changes: 2 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct Client {
client_ref: Arc<ClientRef>,
}

#[derive(Debug)]
pub struct ClientRef {
client: reqwest::Client,
base_url: url::Url,
Expand Down Expand Up @@ -192,6 +193,7 @@ impl Client {
}
}

#[derive(Debug)]
pub struct ProgramClient {
client: Arc<ClientRef>,
data: Program,
Expand Down
22 changes: 22 additions & 0 deletions src/wire/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ pub struct ProgramContent {
pub targets: Option<TargetMap>,
}

impl ProgramContent {
pub fn new(name: impl ToString) -> ProgramContent {
ProgramContent {
object_type: Default::default(),
program_name: name.to_string(),
program_long_name: Default::default(),
retailer_name: Default::default(),
retailer_long_name: Default::default(),
program_type: Default::default(),
country: Default::default(),
principal_subdivision: Default::default(),
time_zone_offset: Default::default(),
interval_period: Default::default(),
program_descriptions: Default::default(),
binding_events: Default::default(),
local_price: Default::default(),
payload_descriptors: Default::default(),
targets: Default::default(),
}
}
}

// TODO enforce constraints:
// objectID:
// type: string
Expand Down

0 comments on commit b435313

Please sign in to comment.