~edwargix/git.sr.ht

99f88913f642772b41f1c892a796e605e820a00c — Drew DeVault 5 years ago 87c55fb
API: Implement count for filters -> cursor
2 files changed, 20 insertions(+), 4 deletions(-)

M api/graph/model/cursor.go
M api/graph/schema.resolvers.go
M api/graph/model/cursor.go => api/graph/model/cursor.go +17 -1
@@ 43,8 43,24 @@ func (cur Cursor) MarshalGQL(w io.Writer) {
	w.Write([]byte("\""))
}

func derefOrInt(i *int, d int) int {
	if i != nil {
		return *i
	}
	return d
}

func NewCursor(filter *Filter) *Cursor {
	// TODO: Apply filter
	if filter != nil {
		return &Cursor{
			Next: "",

			Count: derefOrInt(filter.Count, 25),
			// TODO:
			OrderBy: "",
			Search:  "",
		}
	}
	return &Cursor{
		Count:   25,
		Next:    "",

M api/graph/schema.resolvers.go => api/graph/schema.resolvers.go +3 -3
@@ 185,14 185,14 @@ func (r *userResolver) Repositories(ctx context.Context, obj *model.User, cursor
		repos = append(repos, &repo)
	}

	if len(repos) > 25 {
	if len(repos) > cursor.Count {
		cursor = &model.Cursor{
			Count:   25,
			Count:   cursor.Count,
			Next:    strconv.Itoa(repos[len(repos)-1].ID),
			OrderBy: `id DESC`,
			Search:  "",
		}
		repos = repos[:25]
		repos = repos[:cursor.Count]
	} else {
		cursor = nil
	}