hpds_jkw_web/internal/router/router.go

90 lines
3.0 KiB
Go

package router
import (
ginzap "github.com/gin-contrib/zap"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"hpds-iot-web/internal/handler"
"hpds-iot-web/internal/middleware"
"xorm.io/xorm"
e "hpds-iot-web/pkg/err"
)
func InitRouter(logger *zap.Logger, engine *xorm.Engine) *gin.Engine {
hs := handler.NewHandlerService(engine, logger)
gin.SetMode(gin.ReleaseMode)
r := gin.New()
r.Use(ginzap.Ginzap(logger, "2006-01-02 15:04:05.000", true))
r.Use(middleware.Cors())
user := r.Group("/user")
{
user.Use(middleware.JwtAuthMiddleware(logger))
user.POST("/login", e.ErrorWrapper(hs.Login))
user.GET("/getUserInfo", e.ErrorWrapper(hs.GetUserInfo))
}
manage := r.Group("/manage")
{
owner := manage.Group("/owner")
{
owner.Use(middleware.JwtAuthMiddleware(logger))
owner.POST("/list", e.ErrorWrapper(hs.OwnerList))
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.Use(middleware.JwtAuthMiddleware(logger))
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.Use(middleware.JwtAuthMiddleware(logger))
product.POST("/list", e.ErrorWrapper(hs.ProductList))
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.Use(middleware.JwtAuthMiddleware(logger))
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.Use(middleware.JwtAuthMiddleware(logger))
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.Use(middleware.JwtAuthMiddleware(logger))
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))
}
service := product.Group("/service")
{
service.Use(middleware.JwtAuthMiddleware(logger))
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))
}
}
}
return r
}