@@ -18,25 +18,18 @@ pub fn index(req: &mut dyn RequestExt) -> EndpointResult {
18
18
let conn = req. db_read_only ( ) ?;
19
19
let categories =
20
20
Category :: toplevel ( & conn, sort, i64:: from ( options. per_page ) , i64:: from ( offset) ) ?;
21
- let categories = categories. into_iter ( ) . map ( Category :: into) . collect ( ) ;
21
+ let categories = categories
22
+ . into_iter ( )
23
+ . map ( Category :: into)
24
+ . collect :: < Vec < EncodableCategory > > ( ) ;
22
25
23
26
// Query for the total count of categories
24
27
let total = Category :: count_toplevel ( & conn) ?;
25
28
26
- #[ derive( Serialize ) ]
27
- struct R {
28
- categories : Vec < EncodableCategory > ,
29
- meta : Meta ,
30
- }
31
- #[ derive( Serialize ) ]
32
- struct Meta {
33
- total : i64 ,
34
- }
35
-
36
- Ok ( req. json ( & R {
37
- categories,
38
- meta : Meta { total } ,
39
- } ) )
29
+ Ok ( req. json ( & json ! ( {
30
+ "categories" : categories,
31
+ "meta" : { "total" : total } ,
32
+ } ) ) )
40
33
}
41
34
42
35
/// Handles the `GET /categories/:category_id` route.
@@ -67,19 +60,13 @@ pub fn show(req: &mut dyn RequestExt) -> EndpointResult {
67
60
parent_categories : parents,
68
61
} ;
69
62
70
- #[ derive( Serialize ) ]
71
- struct R {
72
- category : EncodableCategoryWithSubcategories ,
73
- }
74
- Ok ( req. json ( & R {
75
- category : cat_with_subcats,
76
- } ) )
63
+ Ok ( req. json ( & json ! ( { "category" : cat_with_subcats } ) ) )
77
64
}
78
65
79
66
/// Handles the `GET /category_slugs` route.
80
67
pub fn slugs ( req : & mut dyn RequestExt ) -> EndpointResult {
81
68
let conn = req. db_read_only ( ) ?;
82
- let slugs = categories:: table
69
+ let slugs: Vec < Slug > = categories:: table
83
70
. select ( ( categories:: slug, categories:: slug, categories:: description) )
84
71
. order ( categories:: slug)
85
72
. load ( & * conn) ?;
@@ -91,11 +78,5 @@ pub fn slugs(req: &mut dyn RequestExt) -> EndpointResult {
91
78
description : String ,
92
79
}
93
80
94
- #[ derive( Serialize ) ]
95
- struct R {
96
- category_slugs : Vec < Slug > ,
97
- }
98
- Ok ( req. json ( & R {
99
- category_slugs : slugs,
100
- } ) )
81
+ Ok ( req. json ( & json ! ( { "category_slugs" : slugs } ) ) )
101
82
}
0 commit comments