validator-api: use response type for history and report endpoints (#1711)

This commit is contained in:
Jon Häggblad
2022-10-26 17:26:17 +02:00
committed by GitHub
parent f0aa2feb76
commit 56cf181770
7 changed files with 197 additions and 19 deletions
@@ -21,6 +21,10 @@ use std::convert::TryFrom;
use std::fmt::{self, Display, Formatter};
use std::io::Cursor;
use time::OffsetDateTime;
use validator_api_requests::models::{
GatewayStatusReportResponse, GatewayUptimeHistoryResponse, HistoricalUptimeResponse,
MixnodeStatusReportResponse, MixnodeUptimeHistoryResponse,
};
// todo: put into some error enum
#[derive(Debug)]
@@ -153,6 +157,19 @@ impl MixnodeStatusReport {
}
}
impl From<MixnodeStatusReport> for MixnodeStatusReportResponse {
fn from(status: MixnodeStatusReport) -> Self {
MixnodeStatusReportResponse {
mix_id: status.mix_id,
identity: status.identity,
owner: status.owner,
most_recent: status.most_recent.0,
last_hour: status.last_hour.0,
last_day: status.last_day.0,
}
}
}
#[derive(Clone, Serialize, Deserialize, Debug, JsonSchema)]
pub struct GatewayStatusReport {
pub(crate) identity: String,
@@ -190,6 +207,18 @@ impl GatewayStatusReport {
}
}
impl From<GatewayStatusReport> for GatewayStatusReportResponse {
fn from(status: GatewayStatusReport) -> Self {
GatewayStatusReportResponse {
identity: status.identity,
owner: status.owner,
most_recent: status.most_recent.0,
last_hour: status.last_hour.0,
last_day: status.last_day.0,
}
}
}
#[derive(Clone, Serialize, Deserialize, Debug, JsonSchema)]
pub struct MixnodeUptimeHistory {
pub(crate) mix_id: MixId,
@@ -215,6 +244,17 @@ impl MixnodeUptimeHistory {
}
}
impl From<MixnodeUptimeHistory> for MixnodeUptimeHistoryResponse {
fn from(history: MixnodeUptimeHistory) -> Self {
MixnodeUptimeHistoryResponse {
mix_id: history.mix_id,
identity: history.identity,
owner: history.owner,
history: history.history.into_iter().map(Into::into).collect(),
}
}
}
#[derive(Clone, Serialize, Deserialize, Debug, JsonSchema)]
pub struct GatewayUptimeHistory {
pub(crate) identity: String,
@@ -233,6 +273,16 @@ impl GatewayUptimeHistory {
}
}
impl From<GatewayUptimeHistory> for GatewayUptimeHistoryResponse {
fn from(history: GatewayUptimeHistory) -> Self {
GatewayUptimeHistoryResponse {
identity: history.identity,
owner: history.owner,
history: history.history.into_iter().map(Into::into).collect(),
}
}
}
#[derive(Clone, Serialize, Deserialize, Debug, JsonSchema)]
pub struct HistoricalUptime {
// ISO 8601 date string
@@ -242,6 +292,15 @@ pub struct HistoricalUptime {
pub(crate) uptime: Uptime,
}
impl From<HistoricalUptime> for HistoricalUptimeResponse {
fn from(uptime: HistoricalUptime) -> Self {
HistoricalUptimeResponse {
date: uptime.date,
uptime: uptime.uptime.0,
}
}
}
pub(crate) struct ErrorResponse {
error_message: String,
status: Status,