sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0

[web] menu tree

This commit is contained in:
Martin Geno 2016-09-13 20:00:18 +02:00
parent b5409b101a
commit 3649b56515
4 changed files with 28 additions and 4 deletions

View File

@ -43,6 +43,7 @@ func NewAPI(config *libconfig.Config, sessions *session.Manager, dbconnection *g
router.GET(prefix+"/website/:websiteid/domain", InvolveWebsiteHandler(api.DomainList, sessions, dbconnection)) router.GET(prefix+"/website/:websiteid/domain", InvolveWebsiteHandler(api.DomainList, sessions, dbconnection))
router.POST(prefix+"/website/:websiteid/domain/:domain", InvolveWebsiteHandler(api.DomainAdd, sessions, dbconnection)) router.POST(prefix+"/website/:websiteid/domain/:domain", InvolveWebsiteHandler(api.DomainAdd, sessions, dbconnection))
router.DELETE(prefix+"/website/:websiteid/domain/:domain", InvolveWebsiteHandler(api.DomainDelete, sessions, dbconnection)) router.DELETE(prefix+"/website/:websiteid/domain/:domain", InvolveWebsiteHandler(api.DomainDelete, sessions, dbconnection))
router.GET(prefix+"/website/:websiteid/menu", InvolveWebsiteHandler(api.MenuTree, sessions, dbconnection))
} }
// Involve to get Website where loggend in user has privilegs // Involve to get Website where loggend in user has privilegs

22
modul/web/apimenu.go Normal file
View File

@ -0,0 +1,22 @@
package web
import (
"net/http"
"github.com/astaxie/session"
"github.com/julienschmidt/httprouter"
libapi "dev.sum7.de/sum7/warehost/lib/api"
libsystem "dev.sum7.de/sum7/warehost/system"
)
// MenuTree to give the tree of a menu back
func (api *API) MenuTree(w http.ResponseWriter, r *http.Request, _ httprouter.Params, sess session.Session, login *libsystem.Login, websiteid int64) (returndata interface{}, returnerr *libapi.ErrorResult) {
returndata = false
logger := api.log.GetLog(r, "menutree")
var menus []*Menu
api.dbconnection.Where("website = ?", websiteid).Preload("Menu").Order("position").Find(&menus)
returndata = BuildMenuTree(menus)
logger.Info("done")
return
}

View File

@ -49,11 +49,12 @@ func (Media) TableName() string { return "web_media" }
// Menu struct // Menu struct
type Menu struct { type Menu struct {
ID int64 `gorm:"primary_key"` ID int64 `gorm:"primary_key"`
WebsiteID int64 `sql:"type:bigint REFERENCES web_website(id) ON UPDATE CASCADE ON DELETE CASCADE;column:website"` WebsiteID int64 `sql:"type:bigint REFERENCES web_website(id) ON UPDATE CASCADE ON DELETE CASCADE;column:website" json:"-"`
Name string `gorm:"type:varchar(255);column:name" json:"name"` Name string `gorm:"type:varchar(255);column:name" json:"name"`
Shorturl string `gorm:"type:varchar(255);column:url" json:"url"` Shorturl string `gorm:"type:varchar(255);column:url" json:"url"`
ParentID sql.NullInt64 `sql:"type:bigint REFERENCES web_menu(id) ON UPDATE SET NULL ON DELETE SET NULL;column:menu"` ParentID sql.NullInt64 `sql:"type:bigint REFERENCES web_menu(id) ON UPDATE SET NULL ON DELETE SET NULL;column:menu" json:"parentid"`
Children []*Menu `json:"menu"` Position int `sql:"type:int;column:position" json:"position"`
Children []*Menu `json:"children"`
} }
// TableName of struct // TableName of struct

@ -1 +1 @@
Subproject commit 58aab8dfd889cc4b5101524e8340c0f1321d7faa Subproject commit 7f94fc78be45b3bba60da3b7b40c37e6aeccabe2