1
+ use sea_orm:: * ;
2
+ use serde:: { Deserialize , Serialize } ;
1
3
use serde_json:: { json, Value } ;
2
4
use uuid:: Uuid ;
5
+ use jz_model:: repository;
3
6
use crate :: AppModule ;
4
7
8
+ #[ derive( Deserialize , Serialize ) ]
9
+ pub struct RepositoryListParam {
10
+ pub r#type : String ,
11
+ pub limit : Option < i64 > ,
12
+ pub offset : Option < i64 > ,
13
+ }
14
+ #[ derive( Deserialize , Serialize ) ]
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 ,
23
+ }
24
+
5
25
impl AppModule {
6
26
pub async fn repo_list_info ( & self , ops_uid : Option < Uuid > , owner_name : String ) -> anyhow:: Result < Vec < Value > > {
7
27
let repos = self . repo_info_by_owner ( owner_name) . await ?;
@@ -35,4 +55,57 @@ impl AppModule {
35
55
}
36
56
Ok ( result)
37
57
}
58
+ pub async fn repo_list ( & self , parma : RepositoryListParam ) -> anyhow:: Result < serde_json:: Value > {
59
+ let rtype = if parma. r#type == "all" {
60
+ None
61
+ } else {
62
+ let rf = parma. r#type . to_lowercase ( ) ;
63
+ if rf == "code" {
64
+ Some ( "Code" . to_string ( ) )
65
+ } else if rf == "data" {
66
+ Some ( "Data" . to_string ( ) )
67
+ } else if rf == "model" {
68
+ Some ( "Model" . to_string ( ) )
69
+ } else {
70
+ return Err ( anyhow:: anyhow!( "invalid rtype" ) ) ;
71
+ }
72
+ } ;
73
+ let mut condition = Condition :: all ( )
74
+ . add ( repository:: Column :: IsPrivate . eq ( false ) ) ;
75
+ if let Some ( ref rtype) = rtype {
76
+ condition = condition. add ( repository:: Column :: Rtype . eq ( rtype) ) ;
77
+ } ;
78
+ let repos = repository:: Entity :: find ( )
79
+ . filter ( condition)
80
+ . order_by_desc ( repository:: Column :: CreatedAt )
81
+ . limit ( parma. limit . unwrap_or ( 20 ) as u64 )
82
+ . offset ( parma. offset . unwrap_or ( 0 ) as u64 )
83
+ . all ( & self . read )
84
+ . await ?;
85
+ let mut result: Vec < RepositoryListResult > = Vec :: new ( ) ;
86
+ for i in repos {
87
+ result. push ( RepositoryListResult {
88
+ creator : i. owner_name ,
89
+ description : i. description ,
90
+ id : i. uid ,
91
+ image : None ,
92
+ runs : None ,
93
+ size : None ,
94
+ r#type : i. rtype ,
95
+ } ) ;
96
+ }
97
+ let total = repository:: Entity :: find ( )
98
+ . filter ( repository:: Column :: Rtype . eq ( parma. r#type ) )
99
+ . filter ( repository:: Column :: IsPrivate . eq ( false ) )
100
+ . count ( & self . read )
101
+ . await ?;
102
+ Ok ( json ! ( {
103
+ "data" : result,
104
+ "limit" : parma. limit,
105
+ "offset" : parma. offset,
106
+ "total" : total,
107
+ "type" : rtype,
108
+ } ) )
109
+
110
+ }
38
111
}
0 commit comments