Use name "channel_id" in response when pulses are requested via REST API.

This commit is contained in:
Harald Kube 2021-03-01 00:00:00 +01:00
parent ddd231c0eb
commit a2a3e8f98f
3 changed files with 15 additions and 15 deletions

View file

@ -43,7 +43,7 @@ impl rest_api::DataProvider for PulseDataProvider {
for p in pulses {
pulse_list.push(rest_api::PulseInfo {
timestamp_ns: p.timestamp_ns,
pin_id: p.pin_id,
channel_id: p.pin_id,
level: p.level,
})
}

View file

@ -15,7 +15,7 @@ pub trait DataProvider {
#[derive(Serialize, Deserialize, Debug)]
pub struct PulseInfo {
pub timestamp_ns: u64,
pub pin_id: usize,
pub channel_id: usize,
pub level: bool,
}
@ -75,7 +75,7 @@ async fn v1_channel_pulses_get(req: tide::Request<RestApiConfig>) -> tide::Resul
Ok(channel_pulses) => Ok(tide::Response::builder(200)
.content_type(tide::http::mime::JSON)
.body(json!({
"channel": channel_id,
"channel_id": channel_id,
"pulses": channel_pulses,
}))
.build()),

View file

@ -144,7 +144,7 @@ fn rest_api_fetch_channels() {
fn rest_api_fetch_channel() {
#[derive(Debug, Deserialize)]
struct ChannelPulsesList {
channel: usize,
channel_id: usize,
pulses: Vec<PulseInfo>,
}
@ -176,28 +176,28 @@ fn rest_api_fetch_channel() {
print_response("rest_api_fetch_channel", &response);
assert_eq!(response.status_code, tide::http::StatusCode::Ok as i32);
let response_json = &response.json::<ChannelPulsesList>().unwrap();
assert_eq!(response_json.channel, 1);
assert_eq!(response_json.channel_id, 1);
assert_eq!(response_json.pulses.len(), 0);
let pulses = vec![
PulseInfo {
timestamp_ns: 1234u64,
pin_id: 1,
channel_id: 1,
level: true,
},
PulseInfo {
timestamp_ns: 1256u64,
pin_id: 1,
channel_id: 1,
level: false,
},
PulseInfo {
timestamp_ns: 1278u64,
pin_id: 1,
channel_id: 1,
level: true,
},
PulseInfo {
timestamp_ns: 1290u64,
pin_id: 1,
channel_id: 1,
level: false,
},
];
@ -208,19 +208,19 @@ fn rest_api_fetch_channel() {
print_response("rest_api_fetch_channel", &response);
assert_eq!(response.status_code, tide::http::StatusCode::Ok as i32);
let response_json = &response.json::<ChannelPulsesList>().unwrap();
assert_eq!(response_json.channel, 1);
assert_eq!(response_json.channel_id, 1);
assert_eq!(response_json.pulses.len(), 4);
assert_eq!(response_json.pulses.get(0).unwrap().timestamp_ns, 1234u64);
assert_eq!(response_json.pulses.get(0).unwrap().pin_id, 1);
assert_eq!(response_json.pulses.get(0).unwrap().channel_id, 1);
assert_eq!(response_json.pulses.get(0).unwrap().level, true);
assert_eq!(response_json.pulses.get(1).unwrap().timestamp_ns, 1256u64);
assert_eq!(response_json.pulses.get(1).unwrap().pin_id, 1);
assert_eq!(response_json.pulses.get(1).unwrap().channel_id, 1);
assert_eq!(response_json.pulses.get(1).unwrap().level, false);
assert_eq!(response_json.pulses.get(2).unwrap().timestamp_ns, 1278u64);
assert_eq!(response_json.pulses.get(2).unwrap().pin_id, 1);
assert_eq!(response_json.pulses.get(2).unwrap().channel_id, 1);
assert_eq!(response_json.pulses.get(2).unwrap().level, true);
assert_eq!(response_json.pulses.get(3).unwrap().timestamp_ns, 1290u64);
assert_eq!(response_json.pulses.get(3).unwrap().pin_id, 1);
assert_eq!(response_json.pulses.get(3).unwrap().channel_id, 1);
assert_eq!(response_json.pulses.get(3).unwrap().level, false);
let response = minreq::get(format!("http://{}/v1/channel/1/pulses", &IP_AND_PORT)).send();
@ -229,6 +229,6 @@ fn rest_api_fetch_channel() {
print_response("rest_api_fetch_channel", &response);
assert_eq!(response.status_code, tide::http::StatusCode::Ok as i32);
let response_json = &response.json::<ChannelPulsesList>().unwrap();
assert_eq!(response_json.channel, 1);
assert_eq!(response_json.channel_id, 1);
assert_eq!(response_json.pulses.len(), 0);
}