generated from alecodes/base-template
feat: allow to fetch collections
This commit is contained in:
parent
01086d12c9
commit
8c660053e5
7 changed files with 147 additions and 83 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue