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 {
2424 let conn = req. db_read_only ( ) ?;
2525 let data: Paginated < Keyword > = query. load ( & * conn) ?;
2626 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+ } ) ) )
4336}
4437
4538/// Handles the `GET /keywords/:keyword_id` route.
@@ -49,9 +42,5 @@ pub fn show(req: &mut dyn RequestExt) -> EndpointResult {
4942
5043 let kw = Keyword :: find_by_keyword ( & conn, name) ?;
5144
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) } ) ) )
5746}
You can’t perform that action at this time.
0 commit comments