Commit a8e1f8e4 authored by zauberstuhl's avatar zauberstuhl

Add fields parameter to post call

related to ganggo@ff16e649
parent a0d65473
......@@ -22,6 +22,7 @@ import (
"github.com/revel/revel"
"regexp"
"errors"
"strings"
"strconv"
"gopkg.in/ganggo/ganggo.v0/app/helpers"
"gopkg.in/ganggo/ganggo.v0/app/models"
......@@ -38,10 +39,12 @@ type ApiPost struct {
func (p ApiPost) Index() revel.Result {
var (
offset int
fields string
posts models.Posts
)
p.Params.Bind(&offset, "offset")
p.Params.Bind(&fields, "fields")
user, err := models.CurrentUser(p.Params, p.Session)
if err != nil {
......@@ -55,7 +58,11 @@ func (p ApiPost) Index() revel.Result {
return p.RenderApiError(err)
}
return p.RenderJSON(posts)
f := strings.Split(fields, ",")
p.Log.Debug("optimized queries", "fields", f)
return p.RenderJSON(posts.SelectFields(f...))
}
func (p ApiPost) Create() revel.Result {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment