mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-20 14:35:07 +00:00
fix posts handlers
This commit is contained in:
@@ -197,23 +197,11 @@ func (p *Posts) Index(ctx context.Context, req *proto.IndexRequest, rsp *proto.I
|
|||||||
return err
|
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
|
// iterate and add
|
||||||
for i := 0; i < limit; i++ {
|
for _, post := range posts {
|
||||||
// strip the content
|
// strip the content
|
||||||
posts[i].Content = ""
|
post.Content = ""
|
||||||
rsp.Posts = append(rsp.Posts, posts[i])
|
rsp.Posts = append(rsp.Posts, post)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -247,19 +235,6 @@ func (p *Posts) Query(ctx context.Context, req *proto.QueryRequest, rsp *proto.Q
|
|||||||
return err
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user