From b8a2fe86bf4b26f15c462cb1f4c57b22b7eea8b0 Mon Sep 17 00:00:00 2001 From: Lukas Matt Date: Mon, 8 Jan 2018 14:52:08 +0100 Subject: [PATCH] Remove redirects from API This should be handle by the application server --- app/controllers/comment.go | 6 ++++-- app/controllers/post.go | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/comment.go b/app/controllers/comment.go index 431a4a1..f16ec5b 100644 --- a/app/controllers/comment.go +++ b/app/controllers/comment.go @@ -47,12 +47,13 @@ func (c ApiComment) Index() revel.Result { func (c ApiComment) Create() revel.Result { var ( - comment string + comment, fields string postID uint post models.Post ) c.Params.Bind(&comment, "comment") + c.Params.Bind(&fields, "fields") c.Params.Bind(&postID, "id") user, err := models.CurrentUser(c.Params, c.Session) @@ -77,7 +78,8 @@ func (c ApiComment) Create() revel.Result { } go dispatcher.Run() - return c.Redirect("/") + // XXX that should return the comment + return c.RenderJSON(post) } func (c ApiComment) Show() revel.Result { diff --git a/app/controllers/post.go b/app/controllers/post.go index 0966a71..d82f5a7 100644 --- a/app/controllers/post.go +++ b/app/controllers/post.go @@ -65,11 +65,12 @@ func (p ApiPost) Index() revel.Result { func (p ApiPost) Create() revel.Result { var ( post models.Post - postText string + postText, fields string aspectID uint ) p.Params.Bind(&postText, "post") + p.Params.Bind(&fields, "fields") p.Params.Bind(&aspectID, "aspectID") emptyPost, err := regexp.MatchString(`^\s*?$`, postText) @@ -144,7 +145,8 @@ func (p ApiPost) Create() revel.Result { } go dispatcher.Run() - return p.Redirect("/") + return p.RenderJSON( + apiHelpers.SelectStructFields(post, fields)) } func (p ApiPost) Show(guid string) revel.Result { -- GitLab