Moved Rest controllers to 'api' package. Also removed annotation routes

This commit is contained in:
Deluan 2016-02-25 16:31:06 -05:00
parent 543e195744
commit 39757f884a
14 changed files with 20 additions and 143 deletions

1
.gitignore vendored
View file

@ -1,4 +1,3 @@
tests/**/commentsRouter_*.go
lastupdate.tmp lastupdate.tmp
gosonic gosonic
iTunes Music Library.xml iTunes Music Library.xml

View file

@ -1,13 +1,12 @@
package controllers package api
import ( import (
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/deluan/gosonic/controllers/responses" "github.com/deluan/gosonic/api/responses"
) )
type GetLicenseController struct{ beego.Controller } type GetLicenseController struct{ beego.Controller }
// @router /rest/getLicense.view [get]
func (this *GetLicenseController) Get() { func (this *GetLicenseController) Get() {
response := responses.NewXML(&responses.License{Valid: true}) response := responses.NewXML(&responses.License{Valid: true})
this.Ctx.Output.Body(response) this.Ctx.Output.Body(response)

View file

@ -1,14 +1,13 @@
package controllers package api
import ( import (
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/deluan/gosonic/controllers/responses" "github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/repositories" "github.com/deluan/gosonic/repositories"
) )
type GetMusicFoldersController struct{ beego.Controller } type GetMusicFoldersController struct{ beego.Controller }
// @router /rest/getMusicFolders.view [get]
func (this *GetMusicFoldersController) Get() { func (this *GetMusicFoldersController) Get() {
repository := new(repositories.MediaFolderRepository) repository := new(repositories.MediaFolderRepository)
mediaFolderList, _ := repository.GetAll() mediaFolderList, _ := repository.GetAll()

View file

@ -1,14 +1,13 @@
package controllers package api
import ( import (
"github.com/astaxie/beego" "github.com/astaxie/beego"
"encoding/xml" "encoding/xml"
"github.com/deluan/gosonic/controllers/responses" "github.com/deluan/gosonic/api/responses"
) )
type PingController struct{ beego.Controller } type PingController struct{ beego.Controller }
// @router /rest/ping.view [get]
func (this *PingController) Get() { func (this *PingController) Get() {
response := responses.NewEmpty() response := responses.NewEmpty()
xmlBody, _ := xml.Marshal(response) xmlBody, _ := xml.Marshal(response)

View file

@ -1,8 +1,8 @@
package controllers package api
import ( import (
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/deluan/gosonic/controllers/responses" "github.com/deluan/gosonic/api/responses"
) )
type ControllerInterface interface { type ControllerInterface interface {

View file

@ -8,7 +8,6 @@ import (
type MainController struct{ beego.Controller } type MainController struct{ beego.Controller }
// @router / [get]
func (this *MainController) Get() { func (this *MainController) Get() {
this.Ctx.Redirect(302, "/static/Jamstash/") this.Ctx.Redirect(302, "/static/Jamstash/")
} }

View file

@ -1,121 +0,0 @@
package routers
import (
"github.com/astaxie/beego"
)
func init() {
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:GetLicenseController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:GetLicenseController"],
beego.ControllerComments{
"Get",
`/rest/getLicense.view`,
[]string{"get"},
nil})
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:GetMusicFoldersController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:GetMusicFoldersController"],
beego.ControllerComments{
"Get",
`/rest/getMusicFolders.view`,
[]string{"get"},
nil})
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:MainController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:MainController"],
beego.ControllerComments{
"Get",
`/`,
[]string{"get"},
nil})
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:ObjectController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:ObjectController"],
beego.ControllerComments{
"Post",
`/`,
[]string{"post"},
nil})
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:ObjectController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:ObjectController"],
beego.ControllerComments{
"Get",
`/:objectId`,
[]string{"get"},
nil})
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:ObjectController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:ObjectController"],
beego.ControllerComments{
"GetAll",
`/`,
[]string{"get"},
nil})
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:ObjectController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:ObjectController"],
beego.ControllerComments{
"Put",
`/:objectId`,
[]string{"put"},
nil})
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:ObjectController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:ObjectController"],
beego.ControllerComments{
"Delete",
`/:objectId`,
[]string{"delete"},
nil})
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:PingController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:PingController"],
beego.ControllerComments{
"Get",
`/rest/ping.view`,
[]string{"get"},
nil})
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:UserController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:UserController"],
beego.ControllerComments{
"Post",
`/`,
[]string{"post"},
nil})
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:UserController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:UserController"],
beego.ControllerComments{
"GetAll",
`/`,
[]string{"get"},
nil})
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:UserController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:UserController"],
beego.ControllerComments{
"Get",
`/:uid`,
[]string{"get"},
nil})
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:UserController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:UserController"],
beego.ControllerComments{
"Put",
`/:uid`,
[]string{"put"},
nil})
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:UserController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:UserController"],
beego.ControllerComments{
"Delete",
`/:uid`,
[]string{"delete"},
nil})
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:UserController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:UserController"],
beego.ControllerComments{
"Login",
`/login`,
[]string{"get"},
nil})
beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:UserController"] = append(beego.GlobalControllerRouter["github.com/deluan/gosonic/controllers:UserController"],
beego.ControllerComments{
"Logout",
`/logout`,
[]string{"get"},
nil})
}

View file

@ -1,22 +1,25 @@
package routers package routers
import ( import (
"github.com/deluan/gosonic/controllers" "github.com/deluan/gosonic/api"
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/astaxie/beego/context" "github.com/astaxie/beego/context"
"github.com/deluan/gosonic/controllers"
) )
func init() { func init() {
beego.Include( ns := beego.NewNamespace("/rest",
&controllers.MainController{}, beego.NSRouter("/ping.view", &api.PingController{}),
&controllers.PingController{}, beego.NSRouter("/getLicense.view", &api.GetLicenseController{}),
&controllers.GetLicenseController{}, beego.NSRouter("/getMusicFolders.view", &api.GetMusicFoldersController{}),
&controllers.GetMusicFoldersController{},
) )
beego.AddNamespace(ns)
beego.Router("/", &controllers.MainController{})
var ValidateRequest = func(ctx *context.Context) { var ValidateRequest = func(ctx *context.Context) {
controllers.Validate(&beego.Controller{Ctx: ctx}) api.Validate(&beego.Controller{Ctx: ctx})
} }
beego.InsertFilter("/rest/*", beego.BeforeRouter, ValidateRequest) beego.InsertFilter("/rest/*", beego.BeforeRouter, ValidateRequest)

View file

@ -5,7 +5,7 @@ import (
"encoding/xml" "encoding/xml"
_ "github.com/deluan/gosonic/routers" _ "github.com/deluan/gosonic/routers"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"github.com/deluan/gosonic/controllers/responses" "github.com/deluan/gosonic/api/responses"
. "github.com/deluan/gosonic/tests" . "github.com/deluan/gosonic/tests"
) )

View file

@ -6,7 +6,7 @@ import (
_ "github.com/deluan/gosonic/routers" _ "github.com/deluan/gosonic/routers"
. "github.com/deluan/gosonic/tests" . "github.com/deluan/gosonic/tests"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"github.com/deluan/gosonic/controllers/responses" "github.com/deluan/gosonic/api/responses"
) )
func TestCheckParams(t *testing.T) { func TestCheckParams(t *testing.T) {