@@ -52,6 +52,7 @@ pub struct NotificationFilter {
52
52
pub active : Option < bool > ,
53
53
pub reference_id : Option < String > ,
54
54
pub notification_type : Option < String > ,
55
+ pub node_ids : Vec < String > ,
55
56
pub limit : Option < i64 > ,
56
57
pub offset : Option < i64 > ,
57
58
}
@@ -69,6 +70,10 @@ impl NotificationFilter {
69
70
parts. push ( "notification_type = $notification_type" ) ;
70
71
}
71
72
73
+ if !self . node_ids . is_empty ( ) {
74
+ parts. push ( "node_id IN $node_ids" ) ;
75
+ }
76
+
72
77
let filters = parts. join ( " AND " ) ;
73
78
if filters. is_empty ( ) {
74
79
filters
@@ -103,6 +108,14 @@ impl NotificationFilter {
103
108
)
104
109
} )
105
110
}
111
+
112
+ pub fn get_node_ids ( & self ) -> Option < ( String , Vec < String > ) > {
113
+ if !self . node_ids . is_empty ( ) {
114
+ Some ( ( "node_ids" . to_string ( ) , self . node_ids . clone ( ) ) )
115
+ } else {
116
+ None
117
+ }
118
+ }
106
119
}
107
120
108
121
#[ cfg( test) ]
@@ -118,16 +131,32 @@ mod tests {
118
131
} ;
119
132
assert_eq ! ( active. filters( ) , "WHERE active = $active" ) ;
120
133
134
+ let node_ids = super :: NotificationFilter {
135
+ node_ids : vec ! [ "123" . to_string( ) , "456" . to_string( ) ] ,
136
+ ..Default :: default ( )
137
+ } ;
138
+
139
+ assert_eq ! ( node_ids. filters( ) , "WHERE node_id IN $node_ids" ) ;
140
+
141
+ assert_eq ! (
142
+ node_ids. get_node_ids( ) ,
143
+ Some ( (
144
+ "node_ids" . to_string( ) ,
145
+ vec![ "123" . to_string( ) , "456" . to_string( ) ]
146
+ ) )
147
+ ) ;
148
+
121
149
let all = super :: NotificationFilter {
122
150
active : Some ( true ) ,
123
151
reference_id : Some ( "123" . to_string ( ) ) ,
124
152
notification_type : Some ( "Bill" . to_string ( ) ) ,
153
+ node_ids : vec ! [ "123" . to_string( ) ] ,
125
154
..Default :: default ( )
126
155
} ;
127
156
128
157
assert_eq ! (
129
158
all. filters( ) ,
130
- "WHERE active = $active AND reference_id = $reference_id AND notification_type = $notification_type"
159
+ "WHERE active = $active AND reference_id = $reference_id AND notification_type = $notification_type AND node_id IN $node_ids "
131
160
) ;
132
161
}
133
162
}
0 commit comments