Commit 4a56e762 authored by zauberstuhl's avatar zauberstuhl

Add struct prefix and people/profile show

parent 89b8e88b
......@@ -24,11 +24,11 @@ import (
"github.com/ganggo/federation"
)
type Comment struct {
type ApiComment struct {
*revel.Controller
}
func (c Comment) Index() revel.Result {
func (c ApiComment) Index() revel.Result {
var (
postID uint
comments models.Comments
......@@ -43,7 +43,7 @@ func (c Comment) Index() revel.Result {
return c.RenderJson(comments)
}
func (c Comment) Create() revel.Result {
func (c ApiComment) Create() revel.Result {
var (
comment string
postID uint
......@@ -77,10 +77,10 @@ func (c Comment) Create() revel.Result {
return c.Redirect("/")
}
func (c Comment) Show() revel.Result {
func (c ApiComment) Show() revel.Result {
return c.NotFound("Not implemented yet")
}
func (c Comment) Delete() revel.Result {
func (c ApiComment) Delete() revel.Result {
return c.NotFound("Not implemented yet")
}
......@@ -23,11 +23,11 @@ import (
"github.com/ganggo/ganggo/app/models"
)
type Like struct {
type ApiLike struct {
*revel.Controller
}
func (l Like) Index() revel.Result {
func (l ApiLike) Index() revel.Result {
var (
postID uint
likes models.Likes
......@@ -43,14 +43,14 @@ func (l Like) Index() revel.Result {
return l.RenderJson(likes)
}
func (l Like) Create() revel.Result {
func (l ApiLike) Create() revel.Result {
return l.NotFound("Not implemented yet")
}
func (l Like) Show() revel.Result {
func (l ApiLike) Show() revel.Result {
return l.NotFound("Not implemented yet")
}
func (l Like) Delete() revel.Result {
func (l ApiLike) Delete() revel.Result {
return l.NotFound("Not implemented yet")
}
......@@ -19,24 +19,37 @@ package controllers
import (
"github.com/revel/revel"
"github.com/ganggo/ganggo/app/models"
)
type People struct {
type ApiPeople struct {
*revel.Controller
}
func (p People) Index() revel.Result {
func (p ApiPeople) Index() revel.Result {
return p.NotFound("Not implemented yet")
}
func (p People) Create() revel.Result {
func (p ApiPeople) Create() revel.Result {
return p.NotFound("Not implemented yet")
}
func (p People) Show() revel.Result {
return p.NotFound("Not implemented yet")
func (p ApiPeople) Show() revel.Result {
var (
personID uint
person models.Person
)
p.Params.Bind(&personID, "id")
err := person.FindByID(personID)
if err != nil {
revel.ERROR.Println(err)
return p.NotFound("Person not found")
}
return p.RenderJson(person)
}
func (p People) Delete() revel.Result {
func (p ApiPeople) Delete() revel.Result {
return p.NotFound("Not implemented yet")
}
......@@ -24,11 +24,11 @@ import (
"github.com/ganggo/federation"
)
type Post struct {
type ApiPost struct {
*revel.Controller
}
func (p Post) Index() revel.Result {
func (p ApiPost) Index() revel.Result {
var (
offset int
posts models.Posts
......@@ -44,7 +44,7 @@ func (p Post) Index() revel.Result {
return p.RenderJson(posts)
}
func (p Post) Create() revel.Result {
func (p ApiPost) Create() revel.Result {
var post string
p.Params.Bind(&post, "post")
......@@ -65,7 +65,7 @@ func (p Post) Create() revel.Result {
return p.Redirect("/")
}
func (p Post) Show() revel.Result {
func (p ApiPost) Show() revel.Result {
var (
postID uint
post models.Post
......@@ -81,6 +81,6 @@ func (p Post) Show() revel.Result {
return p.RenderJson(post)
}
func (p Post) Delete() revel.Result {
func (p ApiPost) Delete() revel.Result {
return p.NotFound("Not implemented yet")
}
......@@ -19,24 +19,33 @@ package controllers
import (
"github.com/revel/revel"
"github.com/ganggo/ganggo/app/models"
)
type Profile struct {
type ApiProfile struct {
*revel.Controller
}
func (p Profile) Index() revel.Result {
func (p ApiProfile) Create() revel.Result {
return p.NotFound("Not implemented yet")
}
func (p Profile) Create() revel.Result {
return p.NotFound("Not implemented yet")
}
func (p ApiProfile) Show() revel.Result {
var (
personID uint
profile models.Profile
)
func (p Profile) Show() revel.Result {
return p.NotFound("Not implemented yet")
p.Params.Bind(&personID, "id")
err := profile.FindByPersonID(personID)
if err != nil {
revel.ERROR.Println(err)
return p.NotFound("Profile not found")
}
return p.RenderJson(profile)
}
func (p Profile) Delete() revel.Result {
func (p ApiProfile) Delete() revel.Result {
return p.NotFound("Not implemented yet")
}
# Restful API routes
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/v0/posts ApiPost.Index
POST /api/v0/posts ApiPost.Create
GET /api/v0/posts/:id ApiPost.Show
DELETE /api/v0/posts/:id ApiPost.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/v0/posts/:id/likes ApiLike.Index
POST /api/v0/posts/:id/likes ApiLike.Create
GET /api/v0/posts/:id/likes/:like_id ApiLike.Show
DELETE /api/v0/posts/:id/likes/:like_id ApiLike.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/v0/posts/:id/comments ApiComment.Index
POST /api/v0/posts/:id/comments ApiComment.Create
GET /api/v0/posts/:id/comments/:comment_id ApiComment.Show
DELETE /api/v0/posts/:id/comments/:comment_id ApiComment.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/v0/people ApiPeople.Index
POST /api/v0/people ApiPeople.Create
GET /api/v0/people/:id ApiPeople.Show
DELETE /api/v0/people/:id ApiPeople.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
GET /api/v0/people/:id/profile ApiProfile.Show
POST /api/v0/people/:id/profile ApiProfile.Create
DELETE /api/v0/people/:id/profile ApiProfile.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