@@ -7,12 +7,12 @@ use chrono::Utc;
77use context_aware_config:: helpers:: validate_change_reason;
88use diesel:: { ExpressionMethods , PgArrayExpressionMethods , QueryDsl , RunQueryDsl } ;
99use service_utils:: {
10- run_query,
10+ run_query, run_tx_query ,
1111 service:: types:: { AppState , WorkspaceContext } ,
1212} ;
1313use superposition_derives:: authorized;
1414use superposition_types:: {
15- PaginatedResponse , User ,
15+ DBConnection , PaginatedResponse , User ,
1616 api:: webhook:: { CreateWebhookRequest , UpdateWebhookRequest , WebhookName } ,
1717 custom_query:: PaginationParams ,
1818 database:: {
@@ -48,7 +48,7 @@ async fn create_handler(
4848 validate_change_reason(
4949 & workspace_context,
5050 & req. change_reason,
51- conn,
51+ & mut conn,
5252 & state. master_encryption_key,
5353 )
5454 ) ?;
@@ -84,7 +84,7 @@ async fn create_handler(
8484 diesel:: insert_into( webhooks:: table)
8585 . values( & webhook_data)
8686 . schema_name( & workspace_context. schema_name)
87- . get_result:: <Webhook >( conn)
87+ . get_result:: <Webhook >( & mut conn)
8888 ) ?;
8989
9090 Ok ( Json ( created) )
@@ -109,7 +109,7 @@ async fn update_handler(
109109 validate_change_reason(
110110 & workspace_context,
111111 & req. change_reason,
112- conn,
112+ & mut conn,
113113 & state. master_encryption_key,
114114 )
115115 ) ?;
@@ -134,7 +134,7 @@ async fn update_handler(
134134 last_modified_by. eq( user. get_email( ) ) ,
135135 ) )
136136 . schema_name( & workspace_context. schema_name)
137- . get_result:: <Webhook >( conn)
137+ . get_result:: <Webhook >( & mut conn)
138138 ) ?;
139139
140140 Ok ( Json ( update) )
@@ -163,11 +163,13 @@ async fn list_handler(
163163 pagination : Query < PaginationParams > ,
164164) -> superposition:: Result < Json < PaginatedResponse < Webhook > > > {
165165 if let Some ( true ) = pagination. all {
166- let result: Vec < Webhook > = run_query ! ( state. db_pool, conn, {
166+ let result: Vec < Webhook > = run_query ! (
167+ state. db_pool,
168+ conn,
167169 webhooks
168170 . schema_name( & workspace_context. schema_name)
169- . get_results( conn)
170- } ) ?;
171+ . get_results( & mut conn)
172+ ) ?;
171173 return Ok ( Json ( PaginatedResponse :: all ( result) ) ) ;
172174 }
173175
@@ -177,7 +179,7 @@ async fn list_handler(
177179 webhooks
178180 . count( )
179181 . schema_name( & workspace_context. schema_name)
180- . get_result( conn)
182+ . get_result( & mut conn)
181183 ) ?;
182184 let limit = pagination. count . unwrap_or ( 10 ) ;
183185 let mut builder = webhooks
@@ -189,7 +191,7 @@ async fn list_handler(
189191 let offset = ( page - 1 ) * limit;
190192 builder = builder. offset ( offset) ;
191193 }
192- let data: Vec < Webhook > = run_query ! ( state. db_pool, conn, builder. load( conn) ) ?;
194+ let data: Vec < Webhook > = run_query ! ( state. db_pool, conn, builder. load( & mut conn) ) ?;
193195 let total_pages = ( total_items as f64 / limit as f64 ) . ceil ( ) as i64 ;
194196
195197 Ok ( Json ( PaginatedResponse {
@@ -209,7 +211,7 @@ async fn delete_handler(
209211) -> superposition:: Result < HttpResponse > {
210212 let w_name: String = params. into_inner ( ) . into ( ) ;
211213
212- run_query ! ( state. db_pool, tx conn, {
214+ run_tx_query ! ( state. db_pool, | conn: & mut DBConnection | {
213215 diesel:: update( webhooks:: table)
214216 . filter( webhooks:: name. eq( & w_name) )
215217 . set( (
@@ -233,11 +235,13 @@ async fn get_by_event_handler(
233235 state : Data < AppState > ,
234236) -> superposition:: Result < Json < Webhook > > {
235237 let event = params. into_inner ( ) ;
236- let webhook_row = run_query ! ( state. db_pool, conn, {
238+ let webhook_row = run_query ! (
239+ state. db_pool,
240+ conn,
237241 webhooks
238242 . filter( webhooks:: events. contains( vec![ event] ) )
239243 . schema_name( & workspace_context. schema_name)
240- . first( conn)
241- } ) ?;
244+ . first( & mut conn)
245+ ) ?;
242246 Ok ( Json ( webhook_row) )
243247}
0 commit comments