mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
refactor(services): share the SDK list-page wrapper
Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
12 files changed
+98
-142
No files matched your search
@@ -13,6 +13,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
gitea "gitea.dev/sdk"
|
||||
"gitea.dev/tea/internal/transport"
|
||||
)
|
||||
|
||||
@@ -99,6 +100,16 @@ func listPage[T any](limit, page int, fetch func(limit, page int) ([]T, http.Hea
|
||||
return Page[T]{Items: result[:min(len(result), limit)], More: more, Total: total, Counted: counted}, nil
|
||||
}
|
||||
|
||||
// callPage is listPage over an SDK list call.
|
||||
func callPage[T any](ctx context.Context, client *transport.Client, limit, page int, list func(context.Context, *gitea.Client, gitea.ListOptions) ([]T, *gitea.Response, error)) (Page[T], error) {
|
||||
return listPage(limit, page, func(limit, page int) ([]T, http.Header, error) {
|
||||
items, resp, err := call(ctx, client, func(ctx context.Context, c *gitea.Client) ([]T, *gitea.Response, error) {
|
||||
return list(ctx, c, listOptions(limit, page))
|
||||
})
|
||||
return items, headerOf(resp), err
|
||||
})
|
||||
}
|
||||
|
||||
// rawPage is listPage over a raw JSON collection endpoint; it sets limit and page on query.
|
||||
func rawPage[T any](ctx context.Context, client *transport.Client, endpoint string, query url.Values, limit, page int) (Page[T], error) {
|
||||
query = maps.Clone(query)
|
||||
|
||||
Reference in new issue
Block a user