From fc61b45ee4276a028b44bd5ea20f3ec0fc531beb Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 2 Feb 2021 11:41:49 +0000 Subject: [PATCH] fix posts querying --- posts/handler/posts.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/posts/handler/posts.go b/posts/handler/posts.go index 39c0202..6a1c0e8 100644 --- a/posts/handler/posts.go +++ b/posts/handler/posts.go @@ -211,13 +211,16 @@ func (p *Posts) Query(ctx context.Context, req *proto.QueryRequest, rsp *proto.Q return err } - if len(posts) <= int(req.Limit) { - rsp.Posts = posts - return nil + // model does not deal with limits yet + limit := int(req.Limit) + + // set the limit to length of posts + if v := len(posts); v < limit { + limit = v } - // TODO: deal with offset or let model handle it. - for i := 0; i < int(req.Limit); i++ { + // iterate and add + for i := 0; i <= limit; i++ { rsp.Posts = append(rsp.Posts, posts[i]) }