1
1
use serde:: { Deserialize , Serialize } ;
2
2
3
- #[ derive( Debug , Deserialize ) ]
4
- pub struct AnalyticsQuery {
5
- #[ serde( default = "default_limit" ) ]
6
- pub limit : u32 ,
7
- #[ serde( default = "default_event_type" ) ]
8
- pub event_type : String ,
9
- #[ serde( default = "default_metric" ) ]
10
- pub metric : String ,
11
- #[ serde( default = "default_timeframe" ) ]
12
- pub timeframe : String ,
13
- }
14
-
15
3
#[ derive( Debug , Serialize , Deserialize ) ]
16
4
pub struct AnalyticsResponse {
17
5
time : u32 ,
@@ -33,23 +21,35 @@ pub mod postgres {
33
21
}
34
22
}
35
23
24
+ #[ derive( Debug , Deserialize ) ]
25
+ pub struct AnalyticsQuery {
26
+ #[ serde( default = "default_limit" ) ]
27
+ pub limit : u32 ,
28
+ #[ serde( default = "default_event_type" ) ]
29
+ pub event_type : String ,
30
+ #[ serde( default = "default_metric" ) ]
31
+ pub metric : String ,
32
+ #[ serde( default = "default_timeframe" ) ]
33
+ pub timeframe : String ,
34
+ }
35
+
36
36
impl AnalyticsQuery {
37
37
pub fn is_valid ( & self ) -> Result < ( ) , String > {
38
38
let valid_event_types = [ "IMPRESSION" ] ;
39
39
let valid_metric = [ "eventPayouts" , "eventCounts" ] ;
40
40
let valid_timeframe = [ "year" , "month" , "week" , "day" , "hour" ] ;
41
41
42
- if !valid_event_types. iter ( ) . any ( |e| * e == & self . event_type [ .. ] ) {
42
+ if !valid_event_types. contains ( & self . event_type . as_str ( ) ) {
43
43
Err ( format ! (
44
44
"invalid event_type, possible values are: {}" ,
45
45
valid_event_types. join( " ," )
46
46
) )
47
- } else if !valid_metric. iter ( ) . any ( |e| * e == & self . metric [ .. ] ) {
47
+ } else if !valid_metric. contains ( & self . metric . as_str ( ) ) {
48
48
Err ( format ! (
49
49
"invalid metric, possible values are: {}" ,
50
50
valid_metric. join( " ," )
51
51
) )
52
- } else if !valid_timeframe. iter ( ) . any ( |e| * e == & self . timeframe [ .. ] ) {
52
+ } else if !valid_timeframe. contains ( & self . timeframe . as_str ( ) ) {
53
53
Err ( format ! (
54
54
"invalid timeframe, possible values are: {}" ,
55
55
valid_timeframe. join( " ," )
0 commit comments