mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-17 13:24:56 +00:00
fix posts querying
This commit is contained in:
@@ -211,13 +211,16 @@ func (p *Posts) Query(ctx context.Context, req *proto.QueryRequest, rsp *proto.Q
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(posts) <= int(req.Limit) {
|
// model does not deal with limits yet
|
||||||
rsp.Posts = posts
|
limit := int(req.Limit)
|
||||||
return nil
|
|
||||||
|
// set the limit to length of posts
|
||||||
|
if v := len(posts); v < limit {
|
||||||
|
limit = v
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: deal with offset or let model handle it.
|
// iterate and add
|
||||||
for i := 0; i < int(req.Limit); i++ {
|
for i := 0; i <= limit; i++ {
|
||||||
rsp.Posts = append(rsp.Posts, posts[i])
|
rsp.Posts = append(rsp.Posts, posts[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user