后端重构
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"kra/internal/data/model"
|
||||
"kra/internal/plugin/plugin-tool/utils"
|
||||
)
|
||||
|
||||
func Api(ctx context.Context, db *gorm.DB) {
|
||||
entities := []model.SysAPI{
|
||||
{
|
||||
Path: "/info/createInfo",
|
||||
Description: "新建公告",
|
||||
APIGroup: "公告",
|
||||
Method: "POST",
|
||||
},
|
||||
{
|
||||
Path: "/info/deleteInfo",
|
||||
Description: "删除公告",
|
||||
APIGroup: "公告",
|
||||
Method: "DELETE",
|
||||
},
|
||||
{
|
||||
Path: "/info/deleteInfoByIds",
|
||||
Description: "批量删除公告",
|
||||
APIGroup: "公告",
|
||||
Method: "DELETE",
|
||||
},
|
||||
{
|
||||
Path: "/info/updateInfo",
|
||||
Description: "更新公告",
|
||||
APIGroup: "公告",
|
||||
Method: "PUT",
|
||||
},
|
||||
{
|
||||
Path: "/info/findInfo",
|
||||
Description: "根据ID获取公告",
|
||||
APIGroup: "公告",
|
||||
Method: "GET",
|
||||
},
|
||||
{
|
||||
Path: "/info/getInfoList",
|
||||
Description: "获取公告列表",
|
||||
APIGroup: "公告",
|
||||
Method: "GET",
|
||||
},
|
||||
}
|
||||
utils.RegisterApis(db, entities...)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
"kra/internal/plugin/announcement/model"
|
||||
)
|
||||
|
||||
func Gorm(ctx context.Context, db *gorm.DB) {
|
||||
err := db.WithContext(ctx).AutoMigrate(
|
||||
new(model.Info),
|
||||
)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "注册表失败!")
|
||||
zap.L().Error(fmt.Sprintf("%+v", err))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"kra/internal/data/model"
|
||||
"kra/internal/plugin/plugin-tool/utils"
|
||||
)
|
||||
|
||||
func Menu(ctx context.Context, db *gorm.DB) {
|
||||
entities := []model.SysBaseMenu{
|
||||
{
|
||||
ParentID: 24,
|
||||
Path: "anInfo",
|
||||
Name: "anInfo",
|
||||
Hidden: false,
|
||||
Component: "plugin/announcement/view/info.vue",
|
||||
Sort: 5,
|
||||
Title: "公告管理",
|
||||
Icon: "box",
|
||||
},
|
||||
}
|
||||
utils.RegisterMenus(db, entities...)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"kra/internal/plugin/announcement/router"
|
||||
"kra/internal/server/middleware"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// RouterConfig 路由配置
|
||||
type RouterConfig struct {
|
||||
RouterPrefix string
|
||||
}
|
||||
|
||||
func Router(engine *gin.Engine, db *gorm.DB) {
|
||||
RouterWithConfig(engine, db, nil)
|
||||
}
|
||||
|
||||
func RouterWithConfig(engine *gin.Engine, db *gorm.DB, cfg *RouterConfig) {
|
||||
// 获取配置中的路由前缀
|
||||
routerPrefix := ""
|
||||
if cfg != nil {
|
||||
routerPrefix = cfg.RouterPrefix
|
||||
}
|
||||
|
||||
public := engine.Group(routerPrefix)
|
||||
private := engine.Group(routerPrefix)
|
||||
private.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
|
||||
|
||||
routerInstance := router.NewRouter(db)
|
||||
routerInstance.Info.Init(public, private)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/viper"
|
||||
"go.uber.org/zap"
|
||||
"kra/internal/plugin/announcement/global"
|
||||
)
|
||||
|
||||
func Viper(vp *viper.Viper) {
|
||||
err := vp.UnmarshalKey("announcement", &global.Config)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "初始化配置文件失败!")
|
||||
zap.L().Error(fmt.Sprintf("%+v", err))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user