@@ -2,7 +2,7 @@ use sea_orm::*;
2
2
use serde:: { Deserialize , Serialize } ;
3
3
use serde_json:: { json, Value } ;
4
4
use uuid:: Uuid ;
5
- use jz_model:: repository;
5
+ use jz_model:: { repository, users } ;
6
6
use crate :: AppModule ;
7
7
8
8
#[ derive( Deserialize , Serialize ) ]
@@ -13,13 +13,38 @@ pub struct RepositoryListParam {
13
13
}
14
14
#[ derive( Deserialize , Serialize ) ]
15
15
pub 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 ,
23
48
}
24
49
25
50
impl AppModule {
@@ -84,19 +109,60 @@ impl AppModule {
84
109
. await ?;
85
110
let mut result: Vec < RepositoryListResult > = Vec :: new ( ) ;
86
111
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 ,
89
137
description : i. description ,
90
- id : i. uid ,
91
- image : None ,
92
- runs : None ,
138
+ display_image : None ,
93
139
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
+ ) ;
96
155
}
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
+ } ;
97
164
let total = repository:: Entity :: find ( )
98
- . filter ( repository:: Column :: Rtype . eq ( parma. r#type ) )
99
- . filter ( repository:: Column :: IsPrivate . eq ( false ) )
165
+ . filter ( cond)
100
166
. count ( & self . read )
101
167
. await ?;
102
168
Ok ( json ! ( {
0 commit comments