@@ -14,15 +14,12 @@ pub fn list(req: &mut dyn RequestExt) -> EndpointResult {
1414 let conn = req. db_conn ( ) ?;
1515 let user = authenticated_user. user ( ) ;
1616
17- let tokens = ApiToken :: belonging_to ( & user)
17+ let tokens: Vec < ApiToken > = ApiToken :: belonging_to ( & user)
1818 . filter ( api_tokens:: revoked. eq ( false ) )
1919 . order ( api_tokens:: created_at. desc ( ) )
2020 . load ( & * conn) ?;
21- #[ derive( Serialize ) ]
22- struct R {
23- api_tokens : Vec < ApiToken > ,
24- }
25- Ok ( req. json ( & R { api_tokens : tokens } ) )
21+
22+ Ok ( req. json ( & json ! ( { "api_tokens" : tokens } ) ) )
2623}
2724
2825/// Handles the `PUT /me/tokens` route.
@@ -82,14 +79,9 @@ pub fn new(req: &mut dyn RequestExt) -> EndpointResult {
8279 }
8380
8481 let api_token = ApiToken :: insert ( & * conn, user. id , name) ?;
82+ let api_token = EncodableApiTokenWithToken :: from ( api_token) ;
8583
86- #[ derive( Serialize ) ]
87- struct R {
88- api_token : EncodableApiTokenWithToken ,
89- }
90- Ok ( req. json ( & R {
91- api_token : api_token. into ( ) ,
92- } ) )
84+ Ok ( req. json ( & json ! ( { "api_token" : api_token } ) ) )
9385}
9486
9587/// Handles the `DELETE /me/tokens/:id` route.
@@ -105,9 +97,7 @@ pub fn revoke(req: &mut dyn RequestExt) -> EndpointResult {
10597 . set ( api_tokens:: revoked. eq ( true ) )
10698 . execute ( & * conn) ?;
10799
108- #[ derive( Serialize ) ]
109- struct R { }
110- Ok ( req. json ( & R { } ) )
100+ Ok ( req. json ( & json ! ( { } ) ) )
111101}
112102
113103/// Handles the `DELETE /tokens/current` route.
0 commit comments