119 lines
3.9 KiB
Go
119 lines
3.9 KiB
Go
package router
|
|
|
|
import (
|
|
"git.hpds.cc/Component/logging"
|
|
ginzap "github.com/gin-contrib/zap"
|
|
"github.com/gin-gonic/gin"
|
|
"hpds-iot-web/internal/handler"
|
|
"hpds-iot-web/internal/middleware"
|
|
"xorm.io/xorm"
|
|
|
|
e "hpds-iot-web/pkg/err"
|
|
)
|
|
|
|
func InitRouter(logger *logging.Logger, engine *xorm.Engine) *gin.Engine {
|
|
hs := handler.NewHandlerService(engine, logger)
|
|
gin.SetMode(gin.ReleaseMode)
|
|
root := gin.New()
|
|
root.Use(ginzap.Ginzap(logger.Logger, "2006-01-02 15:04:05.000", true))
|
|
root.Use(middleware.Cors())
|
|
r := root.Group("/api")
|
|
{
|
|
user := r.Group("/user")
|
|
{
|
|
user.Use(middleware.JwtAuthMiddleware(logger.Logger))
|
|
user.POST("/login", e.ErrorWrapper(hs.Login))
|
|
user.GET("/getUserInfo", e.ErrorWrapper(hs.GetUserInfo))
|
|
|
|
menu := user.Group("/menu")
|
|
{
|
|
menu.GET("/list", e.ErrorWrapper(hs.MenuList))
|
|
}
|
|
}
|
|
manage := r.Group("/manage")
|
|
{
|
|
manage.Use(middleware.JwtAuthMiddleware(logger.Logger))
|
|
owner := manage.Group("/owner")
|
|
{
|
|
owner.POST("/list", e.ErrorWrapper(hs.OwnerList))
|
|
owner.GET("/info", e.ErrorWrapper(hs.OwnerInfo))
|
|
owner.POST("/add", e.ErrorWrapper(hs.AddOwner))
|
|
owner.POST("/edit", e.ErrorWrapper(hs.EditOwner))
|
|
owner.POST("/delete", e.ErrorWrapper(hs.DelOwner))
|
|
}
|
|
project := manage.Group("/project")
|
|
{
|
|
project.POST("/list", e.ErrorWrapper(hs.ProjectList))
|
|
project.POST("/add", e.ErrorWrapper(hs.AddProject))
|
|
project.POST("/edit", e.ErrorWrapper(hs.EditProject))
|
|
project.POST("/delete", e.ErrorWrapper(hs.DelProject))
|
|
|
|
}
|
|
product := manage.Group("/product")
|
|
{
|
|
product.POST("/list", e.ErrorWrapper(hs.ProductList))
|
|
|
|
product.POST("/info", e.ErrorWrapper(hs.GetProductInfo))
|
|
product.POST("/add", e.ErrorWrapper(hs.AddProduct))
|
|
product.POST("/edit", e.ErrorWrapper(hs.EditProduct))
|
|
product.POST("/delete", e.ErrorWrapper(hs.DelProduct))
|
|
|
|
category := product.Group("/category")
|
|
{
|
|
category.POST("/list", e.ErrorWrapper(hs.CategoryList))
|
|
category.POST("/add", e.ErrorWrapper(hs.AddCategory))
|
|
category.POST("/edit", e.ErrorWrapper(hs.EditCategory))
|
|
category.POST("/delete", e.ErrorWrapper(hs.DelCategory))
|
|
}
|
|
attribute := product.Group("/attribute")
|
|
{
|
|
attribute.POST("/list", e.ErrorWrapper(hs.AttributeList))
|
|
attribute.POST("/add", e.ErrorWrapper(hs.AddAttribute))
|
|
attribute.POST("/edit", e.ErrorWrapper(hs.EditAttribute))
|
|
attribute.POST("/delete", e.ErrorWrapper(hs.DelAttribute))
|
|
}
|
|
event := product.Group("/event")
|
|
{
|
|
event.POST("/list", e.ErrorWrapper(hs.EventList))
|
|
event.POST("/add", e.ErrorWrapper(hs.AddEvent))
|
|
event.POST("/edit", e.ErrorWrapper(hs.EditEvent))
|
|
event.POST("/delete", e.ErrorWrapper(hs.DelEvent))
|
|
|
|
params := event.Group("/params")
|
|
{
|
|
params.POST("/list", e.ErrorWrapper(hs.EventParamsList))
|
|
params.POST("/add", e.ErrorWrapper(hs.AddEventParams))
|
|
params.POST("/edit", e.ErrorWrapper(hs.EditEventParams))
|
|
params.POST("/delete", e.ErrorWrapper(hs.DelEventParams))
|
|
}
|
|
|
|
}
|
|
service := product.Group("/service")
|
|
{
|
|
service.POST("/list", e.ErrorWrapper(hs.ServiceList))
|
|
service.POST("/add", e.ErrorWrapper(hs.AddService))
|
|
service.POST("/edit", e.ErrorWrapper(hs.EditService))
|
|
service.POST("/delete", e.ErrorWrapper(hs.DelService))
|
|
|
|
params := service.Group("/params")
|
|
{
|
|
params.POST("/list", e.ErrorWrapper(hs.ServiceParamsList))
|
|
params.POST("/add", e.ErrorWrapper(hs.AddServiceParams))
|
|
params.POST("/edit", e.ErrorWrapper(hs.EditServiceParams))
|
|
params.POST("/delete", e.ErrorWrapper(hs.DelServiceParams))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
model := r.Group("/model")
|
|
{
|
|
model.Use(middleware.JwtAuthMiddleware(logger.Logger))
|
|
model.POST("/list", e.ErrorWrapper(hs.ModelList))
|
|
model.POST("/add", e.ErrorWrapper(hs.AddModel))
|
|
model.POST("/edit", e.ErrorWrapper(hs.EditModel))
|
|
model.POST("/delete", e.ErrorWrapper(hs.DelModel))
|
|
}
|
|
}
|
|
return root
|
|
}
|