1
1
use std:: error:: Error ;
2
2
use std:: fmt;
3
+ use std:: ops:: Deref ;
3
4
4
5
use chrono:: serde:: { ts_milliseconds, ts_milliseconds_option, ts_seconds} ;
5
6
use chrono:: { DateTime , Utc } ;
6
7
use serde:: { Deserialize , Deserializer , Serialize } ;
7
8
use serde_hex:: { SerHex , StrictPfx } ;
8
9
9
- use crate :: big_num:: BigNum ;
10
- use crate :: { AdUnit , EventSubmission , TargetingTag , ValidatorDesc , ValidatorId } ;
10
+ use crate :: {
11
+ targeting:: Rule , AdUnit , BigNum , EventSubmission , TargetingTag , ValidatorDesc , ValidatorId ,
12
+ } ;
11
13
use hex:: { FromHex , FromHexError } ;
12
- use std:: ops:: Deref ;
13
14
14
15
#[ derive( Serialize , Deserialize , PartialEq , Eq , Copy , Clone , Hash ) ]
15
16
#[ serde( transparent) ]
@@ -84,6 +85,8 @@ pub struct Channel {
84
85
pub deposit_amount : BigNum ,
85
86
#[ serde( with = "ts_seconds" ) ]
86
87
pub valid_until : DateTime < Utc > ,
88
+ #[ serde( default ) ]
89
+ pub targeting_rules : Vec < Rule > ,
87
90
pub spec : ChannelSpec ,
88
91
}
89
92
@@ -171,6 +174,8 @@ pub struct ChannelSpec {
171
174
/// An array of AdUnit (optional)
172
175
#[ serde( default , skip_serializing_if = "Vec::is_empty" ) ]
173
176
pub ad_units : Vec < AdUnit > ,
177
+ #[ serde( default ) ]
178
+ pub targeting_rules : Vec < Rule > ,
174
179
#[ serde( default , skip_serializing_if = "Vec::is_empty" ) ]
175
180
pub price_multiplication_rules : Vec < PriceMultiplicationRules > ,
176
181
#[ serde( default ) ]
@@ -339,6 +344,7 @@ impl Error for ChannelError {
339
344
pub mod postgres {
340
345
use super :: ChannelId ;
341
346
use super :: { Channel , ChannelSpec } ;
347
+ use crate :: targeting:: Rule ;
342
348
use bytes:: BytesMut ;
343
349
use hex:: FromHex ;
344
350
use postgres_types:: { accepts, to_sql_checked, FromSql , IsNull , Json , ToSql , Type } ;
@@ -354,6 +360,7 @@ pub mod postgres {
354
360
deposit_amount : row. get ( "deposit_amount" ) ,
355
361
valid_until : row. get ( "valid_until" ) ,
356
362
spec : row. get :: < _ , Json < ChannelSpec > > ( "spec" ) . 0 ,
363
+ targeting_rules : row. get :: < _ , Json < Vec < Rule > > > ( "targeting_rules" ) . 0 ,
357
364
}
358
365
}
359
366
}
0 commit comments