91 lines
2.4 KiB
Go
91 lines
2.4 KiB
Go
package api
|
|
|
|
import (
|
|
"SciencesServer/app/api/admin/controller/menu"
|
|
"SciencesServer/app/basic/api"
|
|
"SciencesServer/app/session"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Menu struct{}
|
|
|
|
type (
|
|
// menuForm 菜单信息
|
|
menuForm struct {
|
|
ParentID uint64 `json:"parent_id" form:"parent_id"`
|
|
Name string `json:"name" form:"name" binding:"required"`
|
|
Kind int `json:"kind" form:"kind" binding:"required"`
|
|
Link string `json:"link" form:"link"`
|
|
Component string `json:"component" form:"component"`
|
|
Icon string `json:"icon" form:"icon"`
|
|
Auth int `json:"auth" form:"auth"`
|
|
Sort int `json:"sort" form:"sort"`
|
|
Status int `json:"status" form:"status"`
|
|
Remark string `json:"remark" form:"remark"`
|
|
}
|
|
)
|
|
|
|
/**
|
|
* @apiDefine Menu 菜单管理
|
|
*/
|
|
|
|
func (a *Menu) List(c *gin.Context) {
|
|
data, err := menu.NewInstance()(api.GetSession()(c).(*session.Admin)).List()
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (a *Menu) Add(c *gin.Context) {
|
|
form := new(menuForm)
|
|
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := menu.NewInstance()(api.GetSession()(c).(*session.Admin)).Form(&menu.InstanceParams{
|
|
ParentID: form.ParentID, Name: form.Name, Kind: form.Kind, Link: form.Link, Component: form.Component,
|
|
Icon: form.Icon, Auth: form.Auth, Sort: form.Sort, Status: form.Status, Remark: form.Remark,
|
|
})
|
|
APIResponse(err)(c)
|
|
}
|
|
|
|
func (a *Menu) Edit(c *gin.Context) {
|
|
form := &struct {
|
|
idForm
|
|
menuForm
|
|
}{}
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := menu.NewInstance()(api.GetSession()(c).(*session.Admin)).Form(&menu.InstanceParams{
|
|
ID: form.ID, ParentID: form.ParentID, Name: form.Name, Kind: form.Kind, Link: form.Link, Component: form.Component,
|
|
Icon: form.Icon, Auth: form.Auth, Sort: form.Sort, Status: form.Status, Remark: form.Remark,
|
|
})
|
|
APIResponse(err)(c)
|
|
}
|
|
|
|
func (a *Menu) Status(c *gin.Context) {
|
|
form := &struct {
|
|
idForm
|
|
Status int `json:"status" form:"status" binding:"required"`
|
|
}{}
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := menu.NewInstance()(api.GetSession()(c).(*session.Admin)).Status(form.ID, form.Status)
|
|
APIResponse(err)(c)
|
|
}
|
|
|
|
func (a *Menu) Delete(c *gin.Context) {
|
|
form := new(idForm)
|
|
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := menu.NewInstance()(api.GetSession()(c).(*session.Admin)).Delete(form.ID)
|
|
APIResponse(err)(c)
|
|
}
|