fix posts handlers

This commit is contained in:
Asim Aslam
2021-02-05 13:46:32 +00:00
parent da0f4a9dba
commit 421a6be0a0

View File

@@ -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
}