@@ -2,7 +2,7 @@ use sea_orm::*;
22use serde:: { Deserialize , Serialize } ;
33use serde_json:: { json, Value } ;
44use uuid:: Uuid ;
5- use jz_model:: repository;
5+ use jz_model:: { repository, users } ;
66use crate :: AppModule ;
77
88#[ derive( Deserialize , Serialize ) ]
@@ -13,13 +13,38 @@ pub struct RepositoryListParam {
1313}
1414#[ derive( Deserialize , Serialize ) ]
1515pub struct RepositoryListResult {
16- creator : String , // owner name
17- description : Option < String > ,
18- id : Uuid ,
19- image : Option < String > ,
20- runs : Option < i32 > ,
21- size : Option < String > ,
22- r#type : String ,
16+ pub author : RepositoryListAuthor ,
17+ #[ serde( rename = "modelInfo" ) ]
18+ pub model_info : RepositoryModelInfo ,
19+ #[ serde( rename = "moduleStats" ) ]
20+ pub module_stats : RepositoryStats ,
21+ pub id : Uuid ,
22+ }
23+
24+ #[ derive( Deserialize , Serialize ) ]
25+ pub struct RepositoryListAuthor {
26+ pub name : Option < String > ,
27+ pub avatar : Option < String > ,
28+ pub address : Option < String >
29+ }
30+
31+ #[ derive( Deserialize , Serialize ) ]
32+ pub struct RepositoryModelInfo {
33+ pub name : String ,
34+ pub version : Option < String > ,
35+ pub description : Option < String > ,
36+ #[ serde( rename = "displayImage" ) ]
37+ pub display_image : Option < String > ,
38+ pub size : Option < String > ,
39+ pub category : Option < String > ,
40+ }
41+
42+ #[ derive( Deserialize , Serialize ) ]
43+ pub struct RepositoryStats {
44+ pub runs : Option < i32 > ,
45+ pub price : Option < i32 > ,
46+ #[ serde( rename = "APIcompatible" ) ]
47+ pub api_compatible : bool ,
2348}
2449
2550impl AppModule {
@@ -84,19 +109,60 @@ impl AppModule {
84109 . await ?;
85110 let mut result: Vec < RepositoryListResult > = Vec :: new ( ) ;
86111 for i in repos {
87- result. push ( RepositoryListResult {
88- creator : i. owner_name ,
112+ let author = match users:: Entity :: find ( )
113+ . filter ( users:: Column :: Uid . eq ( i. owner_uid ) )
114+ . one ( & self . read )
115+ . await ? {
116+ Some ( user) => RepositoryListAuthor {
117+ name : Some ( user. username ) ,
118+ avatar : user. avatar ,
119+ address : None ,
120+ } ,
121+ None => match self . org_by_uid ( i. owner_uid ) . await {
122+ Ok ( org) => RepositoryListAuthor {
123+ name : Some ( org. name ) ,
124+ avatar : org. avatar ,
125+ address : None ,
126+ } ,
127+ Err ( _) => RepositoryListAuthor {
128+ name : None ,
129+ avatar : None ,
130+ address : None ,
131+ } ,
132+ } ,
133+ } ;
134+ let model_info = RepositoryModelInfo {
135+ name : i. name ,
136+ version : None ,
89137 description : i. description ,
90- id : i. uid ,
91- image : None ,
92- runs : None ,
138+ display_image : None ,
93139 size : None ,
94- r#type : i. rtype ,
95- } ) ;
140+ category : None ,
141+ } ;
142+ let module_stats = RepositoryStats {
143+ runs : None ,
144+ price : None ,
145+ api_compatible : false ,
146+ } ;
147+ result. push (
148+ RepositoryListResult {
149+ author,
150+ model_info,
151+ module_stats,
152+ id : i. uid ,
153+ } ,
154+ ) ;
96155 }
156+ let cond = if let Some ( ref rtype) = rtype && rtype != "all" {
157+ Condition :: all ( )
158+ . add ( repository:: Column :: IsPrivate . eq ( false ) )
159+ . add ( repository:: Column :: Rtype . eq ( rtype) )
160+ } else {
161+ Condition :: all ( )
162+ . add ( repository:: Column :: IsPrivate . eq ( false ) )
163+ } ;
97164 let total = repository:: Entity :: find ( )
98- . filter ( repository:: Column :: Rtype . eq ( parma. r#type ) )
99- . filter ( repository:: Column :: IsPrivate . eq ( false ) )
165+ . filter ( cond)
100166 . count ( & self . read )
101167 . await ?;
102168 Ok ( json ! ( {
0 commit comments