@@ -18,6 +18,12 @@ pub struct EncodableCategory {
1818 pub description : String ,
1919 pub created_at : DateTime < Utc > ,
2020 pub crates_cnt : i32 ,
21+
22+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
23+ pub subcategories : Option < Vec < EncodableCategory > > ,
24+
25+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
26+ pub parent_categories : Option < Vec < EncodableCategory > > ,
2127}
2228
2329impl From < Category > for EncodableCategory {
@@ -37,22 +43,12 @@ impl From<Category> for EncodableCategory {
3743 created_at,
3844 crates_cnt,
3945 category : category. rsplit ( "::" ) . collect :: < Vec < _ > > ( ) [ 0 ] . to_string ( ) ,
46+ subcategories : None ,
47+ parent_categories : None ,
4048 }
4149 }
4250}
4351
44- #[ derive( Serialize , Deserialize , Debug ) ]
45- pub struct EncodableCategoryWithSubcategories {
46- pub id : String ,
47- pub category : String ,
48- pub slug : String ,
49- pub description : String ,
50- pub created_at : DateTime < Utc > ,
51- pub crates_cnt : i32 ,
52- pub subcategories : Vec < EncodableCategory > ,
53- pub parent_categories : Vec < EncodableCategory > ,
54- }
55-
5652/// The serialization format for the `CrateOwnerInvitation` model.
5753#[ derive( Deserialize , Serialize , Debug , PartialEq , Eq ) ]
5854pub struct EncodableCrateOwnerInvitationV1 {
@@ -701,26 +697,8 @@ mod tests {
701697 . and_hms_opt ( 14 , 23 , 11 )
702698 . unwrap ( )
703699 . and_utc ( ) ,
704- } ;
705- let json = serde_json:: to_string ( & cat) . unwrap ( ) ;
706- assert_some ! ( json. as_str( ) . find( r#""created_at":"2017-01-06T14:23:11Z""# ) ) ;
707- }
708-
709- #[ test]
710- fn category_with_sub_dates_serializes_to_rfc3339 ( ) {
711- let cat = EncodableCategoryWithSubcategories {
712- id : "" . to_string ( ) ,
713- category : "" . to_string ( ) ,
714- slug : "" . to_string ( ) ,
715- description : "" . to_string ( ) ,
716- crates_cnt : 1 ,
717- created_at : NaiveDate :: from_ymd_opt ( 2017 , 1 , 6 )
718- . unwrap ( )
719- . and_hms_opt ( 14 , 23 , 11 )
720- . unwrap ( )
721- . and_utc ( ) ,
722- subcategories : vec ! [ ] ,
723- parent_categories : vec ! [ ] ,
700+ subcategories : None ,
701+ parent_categories : None ,
724702 } ;
725703 let json = serde_json:: to_string ( & cat) . unwrap ( ) ;
726704 assert_some ! ( json. as_str( ) . find( r#""created_at":"2017-01-06T14:23:11Z""# ) ) ;
0 commit comments