feat: allow to fetch collections

This commit is contained in:
Alexander Navarro 2024-11-21 20:27:57 -03:00
parent 01086d12c9
commit 8c660053e5
7 changed files with 147 additions and 83 deletions

View file

@ -23,3 +23,32 @@ type Platform struct {
Node // Underlaying node info
collections []*Collection // Child nodes
}
type Fetcher = func(conn *DB, pagination Pagination) ([]*Collection, Pagination, error)
type Pagination struct {
Total int
HasMore bool
Limit int
Offset int
}
var StartPagination = Pagination{
Total: 0,
HasMore: false,
Limit: 10,
Offset: 0,
}
func (platform *Platform) FetchCollections(fetcher Fetcher, start_pagination Pagination) error {
collections, pagination, err := fetcher(platform._conn, start_pagination)
if err != nil {
return err
}
platform.collections = collections
if pagination.HasMore {
return platform.FetchCollections(fetcher, pagination)
}
return nil
}