sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0

[web] first page try

This commit is contained in:
Martin Geno 2016-09-27 10:27:21 +02:00
parent baf722a95e
commit e6cf99db85
4 changed files with 36 additions and 1 deletions

View File

@ -64,7 +64,7 @@ func handlerfunc(w http.ResponseWriter, r *http.Request) {
logger = logger.WithField("hID", website.ID) logger = logger.WithField("hID", website.ID)
var menus []*modul.Menu var menus []*modul.Menu
dbconnection.Where("website = ?", website.ID).Preload("Menu").Find(&menus) dbconnection.Where("website = ?", website.ID).Preload("Menu").Order("position").Find(&menus)
var menu *modul.Menu var menu *modul.Menu
for _, item := range menus { for _, item := range menus {
if item.Shorturl == "" && menu == nil { if item.Shorturl == "" && menu == nil {

View File

@ -44,9 +44,11 @@ func NewAPI(config *libconfig.Config, sessions *session.Manager, dbconnection *g
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)) router.GET(prefix+"/website/:websiteid/menu", InvolveWebsiteHandler(api.MenuTree, sessions, dbconnection))
router.GET(prefix+"/website/:websiteid/menu/list", InvolveWebsiteHandler(api.MenuList, sessions, dbconnection))
router.POST(prefix+"/website/:websiteid/menu", InvolveWebsiteHandler(api.MenuAdd, sessions, dbconnection)) router.POST(prefix+"/website/:websiteid/menu", InvolveWebsiteHandler(api.MenuAdd, sessions, dbconnection))
router.PUT(prefix+"/website/:websiteid/menu/:menuid", InvolveWebsiteHandler(api.MenuEdit, sessions, dbconnection)) router.PUT(prefix+"/website/:websiteid/menu/:menuid", InvolveWebsiteHandler(api.MenuEdit, sessions, dbconnection))
router.DELETE(prefix+"/website/:websiteid/menu/:menuid", InvolveWebsiteHandler(api.MenuDelete, sessions, dbconnection)) router.DELETE(prefix+"/website/:websiteid/menu/:menuid", InvolveWebsiteHandler(api.MenuDelete, sessions, dbconnection))
router.GET(prefix+"/website/:websiteid/page", InvolveWebsiteHandler(api.PageList, sessions, dbconnection))
} }
// Involve to get Website where loggend in user has privilegs // Involve to get Website where loggend in user has privilegs

View File

@ -23,6 +23,17 @@ func (api *API) MenuTree(w http.ResponseWriter, r *http.Request, _ httprouter.Pa
return return
} }
// MenuList give all menu entries of a website
func (api *API) MenuList(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, "menulist")
var menus []*Menu
api.dbconnection.Where("website = ?", websiteid).Preload("Menu").Order("position").Find(&menus)
returndata = menus
logger.Info("done")
return
}
// MenuAdd to add a new menu entry // MenuAdd to add a new menu entry
func (api *API) MenuAdd(w http.ResponseWriter, r *http.Request, ps httprouter.Params, sess session.Session, login *libsystem.Login, websiteid int64) (returndata interface{}, returnerr *libapi.ErrorResult) { func (api *API) MenuAdd(w http.ResponseWriter, r *http.Request, ps httprouter.Params, sess session.Session, login *libsystem.Login, websiteid int64) (returndata interface{}, returnerr *libapi.ErrorResult) {
returndata = false returndata = false

22
modul/web/apipage.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"
)
// PageList give all pages of a website
func (api *API) PageList(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, "pagelist")
var pages []*Page
api.dbconnection.Where("website = ?", websiteid).Preload("Page").Find(&pages)
returndata = pages
logger.Info("done")
return
}