mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-02 23:40:24 +08:00
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package router
|
|
|
|
import (
|
|
"mayfly-go/internal/sys/api"
|
|
"mayfly-go/internal/sys/application"
|
|
"mayfly-go/pkg/req"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func InitResourceRouter(router *gin.RouterGroup) {
|
|
r := &api.Resource{ResourceApp: application.GetResourceApp()}
|
|
db := router.Group("sys/resources")
|
|
{
|
|
db.GET("", func(c *gin.Context) {
|
|
req.NewCtxWithGin(c).Handle(r.GetAllResourceTree)
|
|
})
|
|
|
|
db.GET(":id", func(c *gin.Context) {
|
|
req.NewCtxWithGin(c).Handle(r.GetById)
|
|
})
|
|
|
|
saveResource := req.NewLogInfo("保存资源").WithSave(true)
|
|
srPermission := req.NewPermission("resource:add")
|
|
db.POST("", func(c *gin.Context) {
|
|
req.NewCtxWithGin(c).
|
|
WithLog(saveResource).
|
|
WithRequiredPermission(srPermission).
|
|
Handle(r.SaveResource)
|
|
})
|
|
|
|
changeStatus := req.NewLogInfo("修改资源状态").WithSave(true)
|
|
csPermission := req.NewPermission("resource:changeStatus")
|
|
db.PUT(":id/:status", func(c *gin.Context) {
|
|
req.NewCtxWithGin(c).
|
|
WithLog(changeStatus).
|
|
WithRequiredPermission(csPermission).
|
|
Handle(r.ChangeStatus)
|
|
})
|
|
|
|
sort := req.NewLogInfo("资源排序").WithSave(true)
|
|
db.POST("sort", func(c *gin.Context) {
|
|
req.NewCtxWithGin(c).
|
|
WithLog(sort).
|
|
Handle(r.Sort)
|
|
})
|
|
|
|
delResource := req.NewLogInfo("删除资源").WithSave(true)
|
|
dePermission := req.NewPermission("resource:delete")
|
|
db.DELETE(":id", func(c *gin.Context) {
|
|
req.NewCtxWithGin(c).
|
|
WithLog(delResource).
|
|
WithRequiredPermission(dePermission).
|
|
Handle(r.DelResource)
|
|
})
|
|
}
|
|
}
|