Skip to content

Commit 85e5b22

Browse files
committed
various fixes + move channel_list to primitives::sentry
1 parent 8045b6b commit 85e5b22

File tree

4 files changed

+52
-52
lines changed

4 files changed

+52
-52
lines changed

primitives/src/sentry.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,40 @@ impl fmt::Display for ChannelReport {
215215
}
216216
}
217217

218+
pub mod channel_list {
219+
use crate::ValidatorId;
220+
use chrono::serde::ts_seconds::deserialize as ts_seconds;
221+
use chrono::{DateTime, Utc};
222+
use serde::Deserialize;
223+
224+
#[derive(Debug, Deserialize)]
225+
pub struct ChannelListQuery {
226+
#[serde(default = "default_page")]
227+
pub page: u64,
228+
/// filters the list on `valid_until >= valid_until_ge`
229+
/// It should be the same timestamp format as the `Channel.valid_until`: **seconds**
230+
#[serde(
231+
deserialize_with = "ts_seconds",
232+
default = "Utc::now",
233+
rename = "validUntil"
234+
)]
235+
pub valid_until_ge: DateTime<Utc>,
236+
pub creator: Option<String>,
237+
/// filters the channels containing a specific validator if provided
238+
pub validator: Option<ValidatorId>,
239+
}
240+
241+
#[derive(Debug, Deserialize)]
242+
#[serde(rename_all = "camelCase")]
243+
pub struct LastApprovedQuery {
244+
pub with_heartbeat: Option<String>,
245+
}
246+
247+
fn default_page() -> u64 {
248+
0
249+
}
250+
}
251+
218252
#[cfg(feature = "postgres")]
219253
mod postgres {
220254
use super::{

primitives/src/targeting.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Input {
3636
"advertiserId" => Ok(Value::String(self.global.advertiser_id.clone())),
3737
"country" => Ok(Value::String(self.global.country.clone())),
3838
"eventType" => Ok(Value::String(self.global.event_type.clone())),
39-
"campaignId" => Ok(Value::String(self.global.campiagn_id.clone())),
39+
"campaignId" => Ok(Value::String(self.global.campaign_id.clone())),
4040
"campaignTotalSpent" => Ok(Value::String(self.global.campaign_total_spent.clone())),
4141
"campaignSecondsActive" => {
4242
Ok(Value::Number(self.global.campaign_seconds_active.into()))
@@ -102,7 +102,7 @@ pub struct Global {
102102
pub advertiser_id: String,
103103
pub country: String,
104104
pub event_type: String,
105-
pub campiagn_id: String,
105+
pub campaign_id: String,
106106
pub campaign_total_spent: String,
107107
pub campaign_seconds_active: u64,
108108
pub campaign_seconds_duration: u64,

sentry/src/db/event_aggregate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use primitives::BigNum;
1313
use primitives::{Channel, ChannelId, ValidatorId};
1414
use std::ops::Add;
1515

16-
pub async fn lastest_approve_state(
16+
pub async fn latest_approve_state(
1717
pool: &DbPool,
1818
channel: &Channel,
1919
) -> Result<Option<ApproveStateValidatorMessage>, RunError<bb8_postgres::tokio_postgres::Error>> {
@@ -108,7 +108,7 @@ pub async fn list_event_aggregates(
108108
let statement = format!(
109109
"
110110
WITH aggregates AS (
111-
SELECT
111+
SELECT
112112
channel_id,
113113
created,
114114
event_type,
@@ -124,7 +124,7 @@ pub async fn list_event_aggregates(
124124
jsonb_build_object(
125125
earner, payout
126126
)
127-
)
127+
)
128128
)
129129
as data
130130
FROM event_aggregates WHERE {} GROUP BY channel_id, event_type, created ORDER BY created DESC LIMIT {}

sentry/src/routes/channel.rs

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
use self::channel_list::{ChannelListQuery, LastApprovedQuery};
2-
use crate::db::event_aggregate::{lastest_approve_state, latest_heartbeats, latest_new_state};
1+
use crate::db::event_aggregate::{latest_approve_state, latest_heartbeats, latest_new_state};
32
use crate::db::{get_channel_by_id, insert_channel, insert_validator_messages, list_channels};
4-
use crate::success_response;
5-
use crate::Application;
6-
use crate::ResponseError;
7-
use crate::RouteParams;
8-
use crate::{Auth, Session};
3+
use crate::{success_response, Application, Auth, ResponseError, RouteParams, Session};
94
use bb8::RunError;
105
use bb8_postgres::tokio_postgres::error;
116
use futures::future::try_join_all;
127
use hex::FromHex;
138
use hyper::{Body, Request, Response};
14-
use primitives::adapter::Adapter;
15-
use primitives::sentry::{Event, LastApproved, LastApprovedResponse, SuccessResponse};
16-
use primitives::validator::MessageTypes;
17-
use primitives::{Channel, ChannelId};
9+
use primitives::{
10+
adapter::Adapter,
11+
sentry::{
12+
channel_list::{ChannelListQuery, LastApprovedQuery},
13+
Event, LastApproved, LastApprovedResponse, SuccessResponse,
14+
},
15+
validator::MessageTypes,
16+
Channel, ChannelId,
17+
};
1818
use slog::error;
1919
use std::collections::HashMap;
2020

@@ -130,7 +130,7 @@ pub async fn last_approved<A: Adapter>(
130130
)
131131
.expect("should build response");
132132

133-
let approve_state = match lastest_approve_state(&app.pool, &channel).await? {
133+
let approve_state = match latest_approve_state(&app.pool, &channel).await? {
134134
Some(approve_state) => approve_state,
135135
None => return Ok(default_response),
136136
};
@@ -139,7 +139,7 @@ pub async fn last_approved<A: Adapter>(
139139
MessageTypes::ApproveState(approve_state) => approve_state.state_root,
140140
_ => {
141141
error!(&app.logger, "{}", "failed to retrieve approved"; "module" => "last_approved");
142-
return Err(ResponseError::BadRequest("an error occured".to_string()));
142+
return Err(ResponseError::BadRequest("an error occurred".to_string()));
143143
}
144144
};
145145

@@ -252,37 +252,3 @@ pub async fn create_validator_messages<A: Adapter + 'static>(
252252
}
253253
}
254254
}
255-
256-
mod channel_list {
257-
use chrono::serde::ts_seconds::deserialize as ts_seconds;
258-
use chrono::{DateTime, Utc};
259-
use primitives::ValidatorId;
260-
use serde::Deserialize;
261-
262-
#[derive(Debug, Deserialize)]
263-
pub(super) struct ChannelListQuery {
264-
#[serde(default = "default_page")]
265-
pub page: u64,
266-
/// filters the list on `valid_until >= valid_until_ge`
267-
/// It should be the same timestamp format as the `Channel.valid_until`: **seconds**
268-
#[serde(
269-
deserialize_with = "ts_seconds",
270-
default = "Utc::now",
271-
rename = "validUntil"
272-
)]
273-
pub valid_until_ge: DateTime<Utc>,
274-
pub creator: Option<String>,
275-
/// filters the channels containing a specific validator if provided
276-
pub validator: Option<ValidatorId>,
277-
}
278-
279-
#[derive(Debug, Deserialize)]
280-
#[serde(rename_all = "camelCase")]
281-
pub(super) struct LastApprovedQuery {
282-
pub with_heartbeat: Option<String>,
283-
}
284-
285-
fn default_page() -> u64 {
286-
0
287-
}
288-
}

0 commit comments

Comments
 (0)