Commit b65cf57b authored by zauberstuhl's avatar zauberstuhl
Browse files

Fix import loop and use api v0 version

parent bbac8ee7
GangGo Restful API Library
--------------------------
......@@ -18,7 +18,6 @@ package controllers
//
import (
"net/http"
"github.com/revel/revel"
"github.com/ganggo/ganggo/app/models"
"github.com/ganggo/ganggo/app/jobs"
......@@ -38,8 +37,8 @@ func (c Comment) Index() revel.Result {
c.Params.Bind(&postID, "id")
err := comments.FindByPostID(postID)
if err != nil {
c.Response.Status = http.StatusInternalServerError
revel.ERROR.Println(err)
return c.NotFound("Post not found")
}
return c.RenderJson(comments)
}
......@@ -56,16 +55,14 @@ func (c Comment) Create() revel.Result {
user, err := models.GetCurrentUser(c.Session["TOKEN"])
if err != nil {
c.Flash.Error("Something went wrong! Please contact your server admin.")
revel.ERROR.Println(err)
return c.Redirect(Stream.Index)
return c.RenderError(err)
}
err = post.FindByID(postID)
if err != nil {
c.Flash.Error("Something went wrong! Please contact your server admin.")
revel.ERROR.Println(err)
return c.Redirect(Stream.Index)
return c.NotFound("Post not found")
}
dispatcher := jobs.Dispatcher{
......@@ -77,7 +74,7 @@ func (c Comment) Create() revel.Result {
}
go dispatcher.Run()
return c.Redirect(Stream.Index)
return c.Redirect("/")
}
func (c Comment) Show() revel.Result {
......
......@@ -18,7 +18,6 @@ package controllers
//
import (
"net/http"
"github.com/revel/revel"
"github.com/ganggo/ganggo/app/models"
"github.com/ganggo/ganggo/app/jobs"
......@@ -38,8 +37,8 @@ func (p Post) Index() revel.Result {
p.Params.Bind(&offset, "offset")
err := posts.FindAll(offset)
if err != nil {
p.Response.Status = http.StatusInternalServerError
revel.ERROR.Println(err)
return p.RenderError(err)
}
return p.RenderJson(posts)
......@@ -51,9 +50,8 @@ func (p Post) Create() revel.Result {
user, err := models.GetCurrentUser(p.Session["TOKEN"])
if err != nil {
p.Flash.Error("Something went wrong! Please contact your server admin.")
revel.ERROR.Println(err)
return p.Redirect(Stream.Index)
return p.RenderError(err)
}
dispatcher := jobs.Dispatcher{
......@@ -64,7 +62,7 @@ func (p Post) Create() revel.Result {
}
go dispatcher.Run()
return p.Redirect(Stream.Index)
return p.Redirect("/")
}
func (p Post) Show() revel.Result {
......@@ -76,8 +74,8 @@ func (p Post) Show() revel.Result {
p.Params.Bind(&postID, "id")
err := post.FindByID(postID)
if err != nil {
p.Response.Status = http.StatusInternalServerError
revel.ERROR.Println(err)
return p.NotFound("Post not found")
}
return p.RenderJson(post)
......
# Restful API routes
GET /api/v1/posts Post.Index
POST /api/v1/posts Post.Create
GET /api/v1/posts/:id Post.Show
DELETE /api/v1/posts/:id Post.Delete
GET /api/v0/posts Post.Index
POST /api/v0/posts Post.Create
GET /api/v0/posts/:id Post.Show
DELETE /api/v0/posts/:id Post.Delete
GET /api/v1/posts/:id/likes Like.Index
POST /api/v1/posts/:id/likes Like.Create
GET /api/v1/posts/:id/likes/:like_id Like.Show
DELETE /api/v1/posts/:id/likes/:like_id Like.Delete
GET /api/v0/posts/:id/likes Like.Index
POST /api/v0/posts/:id/likes Like.Create
GET /api/v0/posts/:id/likes/:like_id Like.Show
DELETE /api/v0/posts/:id/likes/:like_id Like.Delete
GET /api/v1/posts/:id/comments Comment.Index
POST /api/v1/posts/:id/comments Comment.Create
GET /api/v1/posts/:id/comments/:comment_id Comment.Show
DELETE /api/v1/posts/:id/comments/:comment_id Comment.Delete
GET /api/v0/posts/:id/comments Comment.Index
POST /api/v0/posts/:id/comments Comment.Create
GET /api/v0/posts/:id/comments/:comment_id Comment.Show
DELETE /api/v0/posts/:id/comments/:comment_id Comment.Delete
GET /api/v1/profiles Profile.Index
POST /api/v1/profiles Profile.Create
GET /api/v1/profiles/:id Profile.Show
DELETE /api/v1/profiles/:id Profile.Delete
GET /api/v0/profiles Profile.Index
POST /api/v0/profiles Profile.Create
GET /api/v0/profiles/:id Profile.Show
DELETE /api/v0/profiles/:id Profile.Delete
GET /api/v1/people People.Index
POST /api/v1/people People.Create
GET /api/v1/people/:id People.Show
DELETE /api/v1/people/:id People.Delete
GET /api/v0/people People.Index
POST /api/v0/people People.Create
GET /api/v0/people/:id People.Show
DELETE /api/v0/people/:id People.Delete
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