[chore] much improved paging package (#2182)

This commit is contained in:
kim
2023-09-07 15:58:37 +01:00
committed by GitHub
parent 14ef098099
commit b093947d84
15 changed files with 1154 additions and 445 deletions

View File

@@ -34,11 +34,11 @@ import (
func (p *Processor) BlocksGet(
ctx context.Context,
requestingAccount *gtsmodel.Account,
page paging.Pager,
page *paging.Page,
) (*apimodel.PageableResponse, gtserror.WithCode) {
blocks, err := p.state.DB.GetAccountBlocks(ctx,
requestingAccount.ID,
&page,
page,
)
if err != nil && !errors.Is(err, db.ErrNoEntries) {
return nil, gtserror.NewErrorInternalError(err)
@@ -77,13 +77,10 @@ func (p *Processor) BlocksGet(
items = append(items, account)
}
return util.PackagePageableResponse(util.PageableResponseParams{
Items: items,
Path: "/api/v1/blocks",
NextMaxIDKey: "max_id",
PrevMinIDKey: "since_id",
NextMaxIDValue: nextMaxIDValue,
PrevMinIDValue: prevMinIDValue,
Limit: page.Limit,
})
return paging.PackageResponse(paging.ResponseParams{
Items: items,
Path: "/api/v1/blocks",
Next: page.Next(nextMaxIDValue),
Prev: page.Prev(prevMinIDValue),
}), nil
}