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(
93
93
. parse :: < Address > ( )
94
94
. map_err ( |_| bad_request ( "invalid email address" ) ) ?;
95
95
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 ( ) ;
101
100
102
101
let token = new_email. insert_or_update ( & mut conn) . await ;
103
102
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 ;
1
2
use chrono:: NaiveDateTime ;
2
3
use diesel:: { OptionalExtension , QueryResult } ;
3
4
use diesel_async:: { AsyncPgConnection , RunQueryDsl } ;
@@ -18,11 +19,12 @@ pub struct Email {
18
19
pub token_generated_at : Option < NaiveDateTime > ,
19
20
}
20
21
21
- #[ derive( Debug , Insertable , AsChangeset ) ]
22
+ #[ derive( Debug , Insertable , AsChangeset , Builder ) ]
22
23
#[ diesel( table_name = emails, check_for_backend( diesel:: pg:: Pg ) ) ]
23
24
pub struct NewEmail < ' a > {
24
25
pub user_id : i32 ,
25
26
pub email : & ' a str ,
27
+ #[ builder( default = false ) ]
26
28
pub verified : bool ,
27
29
}
28
30
Original file line number Diff line number Diff line change @@ -170,11 +170,10 @@ impl<'a> NewUser<'a> {
170
170
171
171
// To send the user an account verification email
172
172
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 ( ) ;
178
177
179
178
if let Some ( token) = new_email. insert_if_missing ( conn) . await ? {
180
179
// 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 {
132
132
. await
133
133
. unwrap ( ) ;
134
134
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 ( ) ;
140
140
141
141
new_email. insert ( & mut conn) . await . unwrap ( ) ;
142
142
You can’t perform that action at this time.
0 commit comments