@@ -5,25 +5,78 @@ import (
55 "net/http"
66)
77
8- // List 查看应用列表
9- func (r * apps ) List (ctx context.Context , req * SwaggerOperationRequest ) (* SwaggerOperationResponse , error ) {
10- if req == nil {
11- req = & SwaggerOperationRequest {}
8+ func (r * apps ) List (ctx context.Context , req * ListAppReq ) (NumberPaged [SimpleApp ], error ) {
9+ if req .PageSize == 0 {
10+ req .PageSize = 20
1211 }
13- request := & RawRequestReq {
14- Method : http .MethodGet ,
15- URL : buildSwaggerOperationURL ("/v1/apps" , req .PathParams , req .QueryParams ),
16- Body : req .Body ,
12+ if req .PageNum == 0 {
13+ req .PageNum = 1
14+ }
15+ return NewNumberPaged (
16+ func (request * pageRequest ) (* pageResponse [SimpleApp ], error ) {
17+ resp := new (listAppResp )
18+ err := r .core .rawRequest (ctx , & RawRequestReq {
19+ Method : http .MethodGet ,
20+ URL : "/v1/apps" ,
21+ Body : req .toReq (request ),
22+ }, resp )
23+ if err != nil {
24+ return nil , err
25+ }
26+ return & pageResponse [SimpleApp ]{
27+ response : resp .HTTPResponse ,
28+ HasMore : len (resp .Data .Items ) >= request .PageSize ,
29+ Data : resp .Data .Items ,
30+ LogID : resp .HTTPResponse .LogID (),
31+ }, nil
32+ }, req .PageSize , req .PageNum )
33+ }
34+
35+ type ListAppReq struct {
36+ WorkspaceID string `query:"workspace_id" json:"-"`
37+ PublishStatus * PublishStatus `query:"publish_status" json:"-"`
38+ ConnectorID * string `query:"connector_id" json:"-"`
39+ PageNum int `query:"page_num" json:"-"`
40+ PageSize int `query:"page_size" json:"-"`
41+ }
42+
43+ type SimpleApp struct {
44+ ID string `json:"id,omitempty"`
45+ Name string `json:"name,omitempty"`
46+ Description string `json:"description,omitempty"`
47+ IconURL string `json:"icon_url,omitempty"`
48+ IsPublished bool `json:"is_published,omitempty"`
49+ OwnerUserID string `json:"owner_user_id,omitempty"`
50+ UpdatedAt int `json:"updated_at,omitempty"`
51+ PublishedAt * int `json:"published_at,omitempty"`
52+ }
53+
54+ type ListAppResp struct {
55+ Total int `json:"total"`
56+ Items []* SimpleApp `json:"items"`
57+ }
58+
59+ type listAppResp struct {
60+ baseResponse
61+ Data * ListAppResp `json:"data"`
62+ }
63+
64+ func (r ListAppReq ) toReq (request * pageRequest ) * ListAppReq {
65+ return & ListAppReq {
66+ WorkspaceID : r .WorkspaceID ,
67+ PublishStatus : r .PublishStatus ,
68+ ConnectorID : r .ConnectorID ,
69+ PageNum : request .PageNum ,
70+ PageSize : request .PageSize ,
1771 }
18- response := new (SwaggerOperationResponse )
19- err := r .core .rawRequest (ctx , request , response )
20- return response , err
2172}
2273
2374type apps struct {
2475 core * core
2576}
2677
2778func newApps (core * core ) * apps {
28- return & apps {core : core }
79+ return & apps {
80+ core : core ,
81+ }
2982}
0 commit comments