From 421a6be0a0554f3d9a91fabc8aebe0309bb991b9 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 5 Feb 2021 13:46:32 +0000 Subject: [PATCH] fix posts handlers --- posts/handler/posts.go | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/posts/handler/posts.go b/posts/handler/posts.go index dedc380..8e970e7 100644 --- a/posts/handler/posts.go +++ b/posts/handler/posts.go @@ -197,23 +197,11 @@ func (p *Posts) Index(ctx context.Context, req *proto.IndexRequest, rsp *proto.I return err } - // model does not deal with limits yet - limit := int(req.Limit) - - // TODO: implement offset - if limit == 0 { - limit = 20 - } - // set the limit to length of posts - if v := len(posts); v < limit { - limit = v - } - // iterate and add - for i := 0; i < limit; i++ { + for _, post := range posts { // strip the content - posts[i].Content = "" - rsp.Posts = append(rsp.Posts, posts[i]) + post.Content = "" + rsp.Posts = append(rsp.Posts, post) } return nil @@ -247,19 +235,6 @@ func (p *Posts) Query(ctx context.Context, req *proto.QueryRequest, rsp *proto.Q return err } - // 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 - } - - // iterate and add - for i := 0; i < limit; i++ { - rsp.Posts = append(rsp.Posts, posts[i]) - } - return nil }