File tree Expand file tree Collapse file tree 1 file changed +10
-21
lines changed Expand file tree Collapse file tree 1 file changed +10
-21
lines changed Original file line number Diff line number Diff line change @@ -24,22 +24,15 @@ pub fn index(req: &mut dyn RequestExt) -> EndpointResult {
24
24
let conn = req. db_read_only ( ) ?;
25
25
let data: Paginated < Keyword > = query. load ( & * conn) ?;
26
26
let total = data. total ( ) ;
27
- let kws = data. into_iter ( ) . map ( Keyword :: into) . collect :: < Vec < _ > > ( ) ;
28
-
29
- #[ derive( Serialize ) ]
30
- struct R {
31
- keywords : Vec < EncodableKeyword > ,
32
- meta : Meta ,
33
- }
34
- #[ derive( Serialize ) ]
35
- struct Meta {
36
- total : Option < i64 > ,
37
- }
38
-
39
- Ok ( req. json ( & R {
40
- keywords : kws,
41
- meta : Meta { total : Some ( total) } ,
42
- } ) )
27
+ let kws = data
28
+ . into_iter ( )
29
+ . map ( Keyword :: into)
30
+ . collect :: < Vec < EncodableKeyword > > ( ) ;
31
+
32
+ Ok ( req. json ( & json ! ( {
33
+ "keywords" : kws,
34
+ "meta" : { "total" : total } ,
35
+ } ) ) )
43
36
}
44
37
45
38
/// Handles the `GET /keywords/:keyword_id` route.
@@ -49,9 +42,5 @@ pub fn show(req: &mut dyn RequestExt) -> EndpointResult {
49
42
50
43
let kw = Keyword :: find_by_keyword ( & conn, name) ?;
51
44
52
- #[ derive( Serialize ) ]
53
- struct R {
54
- keyword : EncodableKeyword ,
55
- }
56
- Ok ( req. json ( & R { keyword : kw. into ( ) } ) )
45
+ Ok ( req. json ( & json ! ( { "keyword" : EncodableKeyword :: from( kw) } ) ) )
57
46
}
You can’t perform that action at this time.
0 commit comments