2023-01-06 10:09:23 +08:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
2023-01-06 19:15:52 +08:00
|
|
|
"git.hpds.cc/Component/logging"
|
2023-01-06 10:09:23 +08:00
|
|
|
ginzap "github.com/gin-contrib/zap"
|
|
|
|
"github.com/gin-gonic/gin"
|
2023-01-11 18:05:29 +08:00
|
|
|
"hpds-iot-web/config"
|
2023-01-06 10:09:23 +08:00
|
|
|
"hpds-iot-web/internal/handler"
|
|
|
|
"hpds-iot-web/internal/middleware"
|
|
|
|
"xorm.io/xorm"
|
|
|
|
|
|
|
|
e "hpds-iot-web/pkg/err"
|
|
|
|
)
|
|
|
|
|
2023-01-11 18:05:29 +08:00
|
|
|
func InitRouter(cfg *config.WebConfig, logger *logging.Logger, engine *xorm.Engine) *gin.Engine {
|
|
|
|
hs := handler.NewHandlerService(cfg, engine, logger)
|
2023-01-06 10:09:23 +08:00
|
|
|
gin.SetMode(gin.ReleaseMode)
|
2023-01-06 17:48:53 +08:00
|
|
|
root := gin.New()
|
2023-01-06 19:15:52 +08:00
|
|
|
root.Use(ginzap.Ginzap(logger.Logger, "2006-01-02 15:04:05.000", true))
|
2023-01-06 17:48:53 +08:00
|
|
|
root.Use(middleware.Cors())
|
|
|
|
r := root.Group("/api")
|
2023-01-06 10:09:23 +08:00
|
|
|
{
|
2023-01-06 17:48:53 +08:00
|
|
|
user := r.Group("/user")
|
2023-01-06 10:09:23 +08:00
|
|
|
{
|
2023-01-06 19:15:52 +08:00
|
|
|
user.Use(middleware.JwtAuthMiddleware(logger.Logger))
|
2023-01-06 17:48:53 +08:00
|
|
|
user.POST("/login", e.ErrorWrapper(hs.Login))
|
2023-03-23 18:03:09 +08:00
|
|
|
user.POST("/list", e.ErrorWrapper(hs.GetUserList))
|
2023-01-06 17:48:53 +08:00
|
|
|
user.GET("/getUserInfo", e.ErrorWrapper(hs.GetUserInfo))
|
2023-01-10 10:01:42 +08:00
|
|
|
|
|
|
|
menu := user.Group("/menu")
|
|
|
|
{
|
|
|
|
menu.GET("/list", e.ErrorWrapper(hs.MenuList))
|
|
|
|
}
|
2023-01-06 10:09:23 +08:00
|
|
|
}
|
2023-01-06 17:48:53 +08:00
|
|
|
manage := r.Group("/manage")
|
2023-01-06 10:09:23 +08:00
|
|
|
{
|
2023-01-06 19:15:52 +08:00
|
|
|
manage.Use(middleware.JwtAuthMiddleware(logger.Logger))
|
2023-01-06 17:48:53 +08:00
|
|
|
owner := manage.Group("/owner")
|
2023-01-06 10:09:23 +08:00
|
|
|
{
|
2023-01-06 17:48:53 +08:00
|
|
|
owner.POST("/list", e.ErrorWrapper(hs.OwnerList))
|
2023-01-10 10:01:42 +08:00
|
|
|
owner.GET("/info", e.ErrorWrapper(hs.OwnerInfo))
|
2023-01-06 17:48:53 +08:00
|
|
|
owner.POST("/add", e.ErrorWrapper(hs.AddOwner))
|
|
|
|
owner.POST("/edit", e.ErrorWrapper(hs.EditOwner))
|
|
|
|
owner.POST("/delete", e.ErrorWrapper(hs.DelOwner))
|
2023-01-06 10:09:23 +08:00
|
|
|
}
|
2023-01-06 17:48:53 +08:00
|
|
|
project := manage.Group("/project")
|
2023-01-06 10:09:23 +08:00
|
|
|
{
|
2023-01-06 17:48:53 +08:00
|
|
|
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))
|
|
|
|
|
2023-01-06 10:09:23 +08:00
|
|
|
}
|
2023-01-06 17:48:53 +08:00
|
|
|
product := manage.Group("/product")
|
2023-01-06 10:09:23 +08:00
|
|
|
{
|
2023-01-06 17:48:53 +08:00
|
|
|
product.POST("/list", e.ErrorWrapper(hs.ProductList))
|
2023-01-10 10:01:42 +08:00
|
|
|
|
|
|
|
product.POST("/info", e.ErrorWrapper(hs.GetProductInfo))
|
2023-01-06 17:48:53 +08:00
|
|
|
product.POST("/add", e.ErrorWrapper(hs.AddProduct))
|
|
|
|
product.POST("/edit", e.ErrorWrapper(hs.EditProduct))
|
|
|
|
product.POST("/delete", e.ErrorWrapper(hs.DelProduct))
|
2023-01-06 14:38:22 +08:00
|
|
|
|
2023-01-06 17:48:53 +08:00
|
|
|
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")
|
2023-01-06 14:38:22 +08:00
|
|
|
{
|
2023-01-06 17:48:53 +08:00
|
|
|
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))
|
2023-01-06 14:38:22 +08:00
|
|
|
}
|
2023-01-06 17:48:53 +08:00
|
|
|
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))
|
2023-01-06 14:38:22 +08:00
|
|
|
|
2023-01-06 17:48:53 +08:00
|
|
|
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))
|
|
|
|
}
|
2023-01-06 14:38:22 +08:00
|
|
|
|
2023-01-06 17:48:53 +08:00
|
|
|
}
|
|
|
|
service := product.Group("/service")
|
2023-01-06 14:38:22 +08:00
|
|
|
{
|
2023-01-06 17:48:53 +08:00
|
|
|
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))
|
|
|
|
}
|
2023-01-06 14:38:22 +08:00
|
|
|
}
|
2023-01-11 18:05:29 +08:00
|
|
|
device := product.Group("/device")
|
|
|
|
{
|
|
|
|
device.POST("/list", e.ErrorWrapper(hs.DeviceList))
|
|
|
|
device.POST("/info", e.ErrorWrapper(hs.DeviceInfo))
|
|
|
|
device.POST("/add", e.ErrorWrapper(hs.AddDevice))
|
|
|
|
device.POST("/edit", e.ErrorWrapper(hs.EditDevice))
|
|
|
|
device.POST("/delete", e.ErrorWrapper(hs.DeleteDevice))
|
|
|
|
}
|
2023-01-06 10:09:23 +08:00
|
|
|
}
|
2023-03-23 18:03:09 +08:00
|
|
|
//detection := manage.Group("/detection")
|
|
|
|
//{
|
|
|
|
//
|
|
|
|
//}
|
2023-01-06 10:09:23 +08:00
|
|
|
}
|
2023-01-06 17:48:53 +08:00
|
|
|
model := r.Group("/model")
|
|
|
|
{
|
2023-01-06 19:15:52 +08:00
|
|
|
model.Use(middleware.JwtAuthMiddleware(logger.Logger))
|
2023-01-06 17:48:53 +08:00
|
|
|
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))
|
2023-03-23 18:03:09 +08:00
|
|
|
model.POST("/issue", e.ErrorWrapper(hs.ModelIssue))
|
|
|
|
model.POST("/workflow", e.ErrorWrapper(hs.GetModelWorkflow))
|
2023-01-06 17:48:53 +08:00
|
|
|
}
|
2023-01-11 18:05:29 +08:00
|
|
|
file := r.Group("/file")
|
|
|
|
{
|
|
|
|
file.Use(middleware.JwtAuthMiddleware(logger.Logger))
|
|
|
|
file.POST("/upload", e.ErrorWrapper(hs.UploadFile))
|
|
|
|
}
|
|
|
|
system := r.Group("/system")
|
|
|
|
{
|
|
|
|
system.Use(middleware.JwtAuthMiddleware(logger.Logger))
|
|
|
|
brand := system.Group("/brand")
|
|
|
|
{
|
|
|
|
brand.POST("/list", e.ErrorWrapper(hs.BrandList))
|
|
|
|
brand.POST("/info", e.ErrorWrapper(hs.BrandInfo))
|
|
|
|
brand.POST("/add", e.ErrorWrapper(hs.AddBrand))
|
|
|
|
brand.POST("/edit", e.ErrorWrapper(hs.EditBrand))
|
|
|
|
brand.POST("/delete", e.ErrorWrapper(hs.DeleteBrand))
|
|
|
|
}
|
2023-03-23 18:03:09 +08:00
|
|
|
node := system.Group("/node")
|
|
|
|
{
|
|
|
|
node.POST("/list", e.ErrorWrapper(hs.NodeList))
|
|
|
|
node.POST("/info", e.ErrorWrapper(hs.NodeInfo))
|
|
|
|
node.POST("/edit", e.ErrorWrapper(hs.EditNode))
|
|
|
|
|
|
|
|
node.POST("/state", e.ErrorWrapper(hs.NodeState))
|
|
|
|
node.POST("/last", e.ErrorWrapper(hs.NodeLastState))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
task := r.Group("/task")
|
|
|
|
{
|
|
|
|
task.Use(middleware.JwtAuthMiddleware(logger.Logger))
|
|
|
|
task.POST("/list", e.ErrorWrapper(hs.TaskList))
|
|
|
|
task.POST("/add", e.ErrorWrapper(hs.AddTask))
|
2023-01-11 18:05:29 +08:00
|
|
|
}
|
2023-01-12 10:21:40 +08:00
|
|
|
disease := r.Group("/disease")
|
|
|
|
{
|
2023-01-13 11:26:39 +08:00
|
|
|
disease.Use(middleware.JwtAuthMiddleware(logger.Logger))
|
2023-03-23 18:03:09 +08:00
|
|
|
disease.POST("/list", e.ErrorWrapper(hs.DiseaseList))
|
2023-01-12 10:21:40 +08:00
|
|
|
diseaseType := disease.Group("/type")
|
|
|
|
{
|
|
|
|
diseaseType.POST("/list", e.ErrorWrapper(hs.DiseaseTypeList))
|
|
|
|
diseaseType.POST("/add", e.ErrorWrapper(hs.AddDiseaseType))
|
|
|
|
diseaseType.POST("/edit", e.ErrorWrapper(hs.EditDiseaseType))
|
|
|
|
diseaseType.POST("/delete", e.ErrorWrapper(hs.DeleteDiseaseType))
|
|
|
|
}
|
|
|
|
}
|
2023-01-13 11:26:39 +08:00
|
|
|
dataset := r.Group("/dataset")
|
|
|
|
{
|
|
|
|
dataset.Use(middleware.JwtAuthMiddleware(logger.Logger))
|
|
|
|
dataset.POST("/ownerList", e.ErrorWrapper(hs.GetOwnerProjectList))
|
|
|
|
|
|
|
|
dataset.POST("/list", e.ErrorWrapper(hs.DatasetList))
|
|
|
|
dataset.POST("/import", e.ErrorWrapper(hs.ImportDataset))
|
|
|
|
}
|
2023-01-06 10:09:23 +08:00
|
|
|
}
|
2023-01-06 17:48:53 +08:00
|
|
|
return root
|
2023-01-06 10:09:23 +08:00
|
|
|
}
|