File tree Expand file tree Collapse file tree 4 files changed +16
-16
lines changed Expand file tree Collapse file tree 4 files changed +16
-16
lines changed Original file line number Diff line number Diff line change @@ -93,11 +93,10 @@ pub async fn update_user(
9393 . parse :: < Address > ( )
9494 . map_err ( |_| bad_request ( "invalid email address" ) ) ?;
9595
96- let new_email = NewEmail {
97- user_id : user. id ,
98- email : user_email,
99- verified : false ,
100- } ;
96+ let new_email = NewEmail :: builder ( )
97+ . user_id ( user. id )
98+ . email ( user_email)
99+ . build ( ) ;
101100
102101 let token = new_email. insert_or_update ( & mut conn) . await ;
103102 let token = token. map_err ( |_| server_error ( "Error in creating token" ) ) ?;
Original file line number Diff line number Diff line change 1+ use bon:: Builder ;
12use chrono:: NaiveDateTime ;
23use diesel:: { OptionalExtension , QueryResult } ;
34use diesel_async:: { AsyncPgConnection , RunQueryDsl } ;
@@ -18,11 +19,12 @@ pub struct Email {
1819 pub token_generated_at : Option < NaiveDateTime > ,
1920}
2021
21- #[ derive( Debug , Insertable , AsChangeset ) ]
22+ #[ derive( Debug , Insertable , AsChangeset , Builder ) ]
2223#[ diesel( table_name = emails, check_for_backend( diesel:: pg:: Pg ) ) ]
2324pub struct NewEmail < ' a > {
2425 pub user_id : i32 ,
2526 pub email : & ' a str ,
27+ #[ builder( default = false ) ]
2628 pub verified : bool ,
2729}
2830
Original file line number Diff line number Diff line change @@ -170,11 +170,10 @@ impl<'a> NewUser<'a> {
170170
171171 // To send the user an account verification email
172172 if let Some ( user_email) = email {
173- let new_email = NewEmail {
174- user_id : user. id ,
175- email : user_email,
176- verified : false ,
177- } ;
173+ let new_email = NewEmail :: builder ( )
174+ . user_id ( user. id )
175+ . email ( user_email)
176+ . build ( ) ;
178177
179178 if let Some ( token) = new_email. insert_if_missing ( conn) . await ? {
180179 // Swallows any error. Some users might insert an invalid email address here.
Original file line number Diff line number Diff line change @@ -132,11 +132,11 @@ impl TestApp {
132132 . await
133133 . unwrap ( ) ;
134134
135- let new_email = NewEmail {
136- user_id : user. id ,
137- email : & email,
138- verified : true ,
139- } ;
135+ let new_email = NewEmail :: builder ( )
136+ . user_id ( user. id )
137+ . email ( & email)
138+ . verified ( true )
139+ . build ( ) ;
140140
141141 new_email. insert ( & mut conn) . await . unwrap ( ) ;
142142
You can’t perform that action at this time.
0 commit comments