Commit 2c3ef89e authored by zauberstuhl's avatar zauberstuhl

Adjust post api in respect of frontend changes

see ganggo@f11b35cf
parent da093388
......@@ -20,6 +20,8 @@ package controllers
import (
"time"
"github.com/revel/revel"
"regexp"
"errors"
"gopkg.in/ganggo/api.v0/app/helpers"
"gopkg.in/ganggo/ganggo.v0/app/models"
"gopkg.in/ganggo/ganggo.v0/app/jobs"
......@@ -63,6 +65,13 @@ func (p ApiPost) Create() revel.Result {
p.Params.Bind(&postText, "post")
p.Params.Bind(&aspectID, "aspectID")
emptyPost, err := regexp.MatchString(`^\s*?$`, postText)
if err == nil && emptyPost {
err = errors.New("Cannot submit an empty post!")
revel.ERROR.Println(err)
return p.RenderError(err)
}
user, err := models.GetCurrentUser(p.Session["TOKEN"])
if err != nil {
revel.ERROR.Println(err)
......@@ -90,33 +99,35 @@ func (p ApiPost) Create() revel.Result {
}
// save post locally
err = post.Create(&entity, nil)
err = post.Create(&entity, false)
if err != nil {
revel.ERROR.Println(err)
return p.RenderError(err)
}
// this is required for mapping
// posts to the author
shareable := models.Shareable{
ShareableID: post.ID,
UserID: user.ID,
ShareableType: models.ShareablePost,
}; if err := shareable.Create(); err != nil {
revel.ERROR.Println(err)
return p.RenderError(err)
}
// create an aspect visibillity entry
// the host has to remember the recipients
visibility := models.AspectVisibility{
ShareableID: post.ID,
AspectID: aspectID,
ShareableType: models.ShareablePost,
}
if err := visibility.Create(); err != nil {
revel.ERROR.Println(err)
return p.RenderError(err)
if entity.Public == false {
// this is required for mapping
// posts to the author
shareable := models.Shareable{
ShareableID: post.ID,
UserID: user.ID,
ShareableType: models.ShareablePost,
}; if err := shareable.Create(); err != nil {
revel.ERROR.Println(err)
return p.RenderError(err)
}
// create an aspect visibillity entry
// the host has to remember the recipients
visibility := models.AspectVisibility{
ShareableID: post.ID,
AspectID: aspectID,
ShareableType: models.ShareablePost,
}
if err := visibility.Create(); err != nil {
revel.ERROR.Println(err)
return p.RenderError(err)
}
}
dispatcher := jobs.Dispatcher{
......
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