Commit bbac8ee7 authored by zauberstuhl's avatar zauberstuhl
Browse files

Initial commit

parents
This diff is collapsed.
package controllers
//
// GangGo Application Server
// Copyright (C) 2017 Lukas Matt <lukas@zauberstuhl.de>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
import (
"net/http"
"github.com/revel/revel"
"github.com/ganggo/ganggo/app/models"
"github.com/ganggo/ganggo/app/jobs"
"github.com/ganggo/federation"
)
type Comment struct {
*revel.Controller
}
func (c Comment) Index() revel.Result {
var (
postID uint
comments models.Comments
)
c.Params.Bind(&postID, "id")
err := comments.FindByPostID(postID)
if err != nil {
c.Response.Status = http.StatusInternalServerError
revel.ERROR.Println(err)
}
return c.RenderJson(comments)
}
func (c Comment) Create() revel.Result {
var (
comment string
postID uint
post models.Post
)
c.Params.Bind(&comment, "comment")
c.Params.Bind(&postID, "id")
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)
}
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)
}
dispatcher := jobs.Dispatcher{
User: user,
Message: federation.EntityComment{
ParentGuid: post.Guid,
Text: comment,
},
}
go dispatcher.Run()
return c.Redirect(Stream.Index)
}
func (c Comment) Show() revel.Result {
return c.Render()
}
func (c Comment) Delete() revel.Result {
return c.Render()
}
package controllers
//
// GangGo Application Server
// Copyright (C) 2017 Lukas Matt <lukas@zauberstuhl.de>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
import (
"net/http"
"github.com/revel/revel"
"github.com/ganggo/ganggo/app/models"
)
type Like struct {
*revel.Controller
}
func (l Like) Index() revel.Result {
var (
postID uint
likes models.Likes
)
l.Params.Bind(&postID, "id")
err := likes.FindByPostID(postID)
if err != nil {
l.Response.Status = http.StatusInternalServerError
revel.ERROR.Println(err)
}
return l.RenderJson(likes)
}
func (l Like) Create() revel.Result {
return l.Render()
}
func (l Like) Show() revel.Result {
return l.Render()
}
func (l Like) Delete() revel.Result {
return l.Render()
}
package controllers
//
// GangGo Application Server
// Copyright (C) 2017 Lukas Matt <lukas@zauberstuhl.de>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
import (
"github.com/revel/revel"
)
type People struct {
*revel.Controller
}
func (p People) Index() revel.Result {
return p.Render()
}
func (p People) Create() revel.Result {
return p.Render()
}
func (p People) Show() revel.Result {
return p.Render()
}
func (p People) Delete() revel.Result {
return p.Render()
}
package controllers
//
// GangGo Application Server
// Copyright (C) 2017 Lukas Matt <lukas@zauberstuhl.de>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
import (
"net/http"
"github.com/revel/revel"
"github.com/ganggo/ganggo/app/models"
"github.com/ganggo/ganggo/app/jobs"
"github.com/ganggo/federation"
)
type Post struct {
*revel.Controller
}
func (p Post) Index() revel.Result {
var (
offset int
posts models.Posts
)
p.Params.Bind(&offset, "offset")
err := posts.FindAll(offset)
if err != nil {
p.Response.Status = http.StatusInternalServerError
revel.ERROR.Println(err)
}
return p.RenderJson(posts)
}
func (p Post) Create() revel.Result {
var post string
p.Params.Bind(&post, "post")
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)
}
dispatcher := jobs.Dispatcher{
User: user,
Message: federation.EntityStatusMessage{
RawMessage: post,
},
}
go dispatcher.Run()
return p.Redirect(Stream.Index)
}
func (p Post) Show() revel.Result {
var (
postID uint
post models.Post
)
p.Params.Bind(&postID, "id")
err := post.FindByID(postID)
if err != nil {
p.Response.Status = http.StatusInternalServerError
revel.ERROR.Println(err)
}
return p.RenderJson(post)
}
func (p Post) Delete() revel.Result {
return p.Render()
}
package controllers
//
// GangGo Application Server
// Copyright (C) 2017 Lukas Matt <lukas@zauberstuhl.de>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
import (
"github.com/revel/revel"
)
type Profile struct {
*revel.Controller
}
func (p Profile) Index() revel.Result {
return p.Render()
}
func (p Profile) Create() revel.Result {
return p.Render()
}
func (p Profile) Show() revel.Result {
return p.Render()
}
func (p Profile) Delete() revel.Result {
return p.Render()
}
package app
import (
"github.com/revel/revel"
)
func init() {
revel.OnAppStart(func() {
revel.INFO.Println("Restful API loaded.")
})
}
# 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/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/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/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/v1/people People.Index
POST /api/v1/people People.Create
GET /api/v1/people/:id People.Show
DELETE /api/v1/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