@@ -11,6 +11,7 @@ pub struct RepositoryListParam {
11
11
pub limit : Option < i64 > ,
12
12
pub offset : Option < i64 > ,
13
13
pub category : Option < String > ,
14
+ pub id : Option < Uuid > ,
14
15
}
15
16
#[ derive( Deserialize , Serialize ) ]
16
17
pub struct RepositoryListResult {
@@ -88,11 +89,11 @@ impl AppModule {
88
89
let rf = parma. r#type . to_lowercase ( ) ;
89
90
if rf == "code" {
90
91
Some ( "Code" . to_string ( ) )
91
- } else if rf == "data" {
92
+ } else if rf == "data" {
92
93
Some ( "Data" . to_string ( ) )
93
- } else if rf == "model" {
94
+ } else if rf == "model" {
94
95
Some ( "Model" . to_string ( ) )
95
- } else {
96
+ } else {
96
97
return Err ( anyhow:: anyhow!( "invalid rtype" ) ) ;
97
98
}
98
99
} ;
@@ -101,6 +102,9 @@ impl AppModule {
101
102
if let Some ( ref rtype) = rtype {
102
103
condition = condition. add ( repository:: Column :: Rtype . eq ( rtype) ) ;
103
104
} ;
105
+ if let Some ( ref uid) = parma. id {
106
+ condition = condition. add ( repository:: Column :: Uid . eq ( uid. clone ( ) ) ) ;
107
+ }
104
108
let repos = repository:: Entity :: find ( )
105
109
. filter ( condition)
106
110
. order_by_desc ( repository:: Column :: CreatedAt )
@@ -114,24 +118,24 @@ impl AppModule {
114
118
. filter ( users:: Column :: Uid . eq ( i. owner_uid ) )
115
119
. one ( & self . read )
116
120
. await ? {
117
- Some ( user) => RepositoryListAuthor {
118
- name : Some ( user. username ) ,
119
- avatar : user. avatar ,
121
+ Some ( user) => RepositoryListAuthor {
122
+ name : Some ( user. username ) ,
123
+ avatar : user. avatar ,
124
+ address : None ,
125
+ } ,
126
+ None => match self . org_by_uid ( i. owner_uid ) . await {
127
+ Ok ( org) => RepositoryListAuthor {
128
+ name : Some ( org. name ) ,
129
+ avatar : org. avatar ,
120
130
address : None ,
121
131
} ,
122
- None => match self . org_by_uid ( i. owner_uid ) . await {
123
- Ok ( org) => RepositoryListAuthor {
124
- name : Some ( org. name ) ,
125
- avatar : org. avatar ,
126
- address : None ,
127
- } ,
128
- Err ( _) => RepositoryListAuthor {
129
- name : None ,
130
- avatar : None ,
131
- address : None ,
132
- } ,
132
+ Err ( _) => RepositoryListAuthor {
133
+ name : None ,
134
+ avatar : None ,
135
+ address : None ,
133
136
} ,
134
- } ;
137
+ } ,
138
+ } ;
135
139
let model_info = RepositoryModelInfo {
136
140
name : i. name ,
137
141
version : None ,
@@ -154,25 +158,28 @@ impl AppModule {
154
158
} ,
155
159
) ;
156
160
}
157
- let cond = if let Some ( ref rtype) = rtype && rtype != "all" {
161
+ let total = if let Some ( _) = parma. id {
162
+ let cond = if let Some ( ref rtype) = rtype && rtype != "all" {
158
163
Condition :: all ( )
159
164
. add ( repository:: Column :: IsPrivate . eq ( false ) )
160
165
. add ( repository:: Column :: Rtype . eq ( rtype) )
161
166
} else {
162
167
Condition :: all ( )
163
168
. add ( repository:: Column :: IsPrivate . eq ( false ) )
164
169
} ;
165
- let total = repository:: Entity :: find ( )
170
+ repository:: Entity :: find ( )
166
171
. filter ( cond)
167
172
. count ( & self . read )
168
- . await ?;
169
- Ok ( json ! ( {
173
+ . await ?
174
+ } else {
175
+ 1
176
+ } ;
177
+ Ok ( json ! ( {
170
178
"data" : result,
171
179
"limit" : parma. limit,
172
180
"offset" : parma. offset,
173
181
"total" : total,
174
182
"type" : rtype,
175
183
} ) )
176
-
177
184
}
178
185
}
0 commit comments