|
| 1 | +use crate::DomainError; |
1 | 2 | use serde::{Deserialize, Serialize};
|
2 | 3 |
|
3 | 4 | #[derive(Debug, Serialize, Deserialize)]
|
@@ -34,26 +35,26 @@ pub struct AnalyticsQuery {
|
34 | 35 | }
|
35 | 36 |
|
36 | 37 | impl AnalyticsQuery {
|
37 |
| - pub fn is_valid(&self) -> Result<(), String> { |
| 38 | + pub fn is_valid(&self) -> Result<(), DomainError> { |
38 | 39 | let valid_event_types = ["IMPRESSION"];
|
39 | 40 | let valid_metric = ["eventPayouts", "eventCounts"];
|
40 | 41 | let valid_timeframe = ["year", "month", "week", "day", "hour"];
|
41 | 42 |
|
42 | 43 | if !valid_event_types.contains(&self.event_type.as_str()) {
|
43 |
| - Err(format!( |
| 44 | + Err(DomainError::InvalidArgument(format!( |
44 | 45 | "invalid event_type, possible values are: {}",
|
45 | 46 | valid_event_types.join(" ,")
|
46 |
| - )) |
| 47 | + ))) |
47 | 48 | } else if !valid_metric.contains(&self.metric.as_str()) {
|
48 |
| - Err(format!( |
| 49 | + Err(DomainError::InvalidArgument(format!( |
49 | 50 | "invalid metric, possible values are: {}",
|
50 | 51 | valid_metric.join(" ,")
|
51 |
| - )) |
| 52 | + ))) |
52 | 53 | } else if !valid_timeframe.contains(&self.timeframe.as_str()) {
|
53 |
| - Err(format!( |
| 54 | + Err(DomainError::InvalidArgument(format!( |
54 | 55 | "invalid timeframe, possible values are: {}",
|
55 | 56 | valid_timeframe.join(" ,")
|
56 |
| - )) |
| 57 | + ))) |
57 | 58 | } else {
|
58 | 59 | Ok(())
|
59 | 60 | }
|
|
0 commit comments