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 ( ...@@ -22,6 +22,7 @@ import (
"github.com/revel/revel" "github.com/revel/revel"
"regexp" "regexp"
"errors" "errors"
"strings"
"strconv" "strconv"
"gopkg.in/ganggo/ganggo.v0/app/helpers" "gopkg.in/ganggo/ganggo.v0/app/helpers"
"gopkg.in/ganggo/ganggo.v0/app/models" "gopkg.in/ganggo/ganggo.v0/app/models"
...@@ -38,10 +39,12 @@ type ApiPost struct { ...@@ -38,10 +39,12 @@ type ApiPost struct {
func (p ApiPost) Index() revel.Result { func (p ApiPost) Index() revel.Result {
var ( var (
offset int offset int
fields string
posts models.Posts posts models.Posts
) )
p.Params.Bind(&offset, "offset") p.Params.Bind(&offset, "offset")
p.Params.Bind(&fields, "fields")
user, err := models.CurrentUser(p.Params, p.Session) user, err := models.CurrentUser(p.Params, p.Session)
if err != nil { if err != nil {
...@@ -55,7 +58,11 @@ func (p ApiPost) Index() revel.Result { ...@@ -55,7 +58,11 @@ func (p ApiPost) Index() revel.Result {
return p.RenderApiError(err) 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 { 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