Commit 35eee2d1 authored by zauberstuhl's avatar zauberstuhl

Accept guid and uint for posts call

parent 7c628312
......@@ -22,6 +22,7 @@ import (
"github.com/revel/revel"
"regexp"
"errors"
"strconv"
"gopkg.in/ganggo/api.v0/app/helpers"
"gopkg.in/ganggo/ganggo.v0/app/models"
"gopkg.in/ganggo/ganggo.v0/app/jobs"
......@@ -140,14 +141,21 @@ func (p ApiPost) Create() revel.Result {
return p.Redirect("/")
}
func (p ApiPost) Show() revel.Result {
var (
postID uint
post models.Post
)
func (p ApiPost) Show(guid string) revel.Result {
var post models.Post
user, err := models.CurrentUser(p.Params, p.Session)
if err != nil {
revel.AppLog.Error(err.Error())
return p.RenderError(err)
}
p.Params.Bind(&postID, "id")
err := post.FindByID(postID)
postID, err := strconv.ParseUint(guid, 10, 32);
if err == nil {
err = post.FindByIDAndUser(uint(postID), user)
} else {
err = post.FindByGuidAndUser(guid, user)
}
if err != nil {
revel.AppLog.Error(err.Error())
return p.NotFound("Post not found")
......
......@@ -5,8 +5,9 @@ DELETE /api/v0/oauth/tokens/:id ApiOAuth.Delete
GET /api/v0/posts ApiPost.Index
POST /api/v0/posts ApiPost.Create
GET /api/v0/posts/:id ApiPost.Show
DELETE /api/v0/posts/:id ApiPost.Delete
# both guid and uint are possible here
GET /api/v0/posts/:guid ApiPost.Show
DELETE /api/v0/posts/:guid ApiPost.Delete
GET /api/v0/notifications ApiNotification.Index
POST /api/v0/notifications ApiNotification.Create
......
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