后端重构

This commit is contained in:
Yvan
2026-01-08 20:16:27 +08:00
parent 9cb6b965e0
commit f5f77b32fe
23 changed files with 1450 additions and 2 deletions
+11
View File
@@ -22,6 +22,9 @@ type ApiGroup struct {
DBApi
AutoCodeApi
AutoCodeHistoryApi
AutoCodePackageApi
AutoCodeTemplateApi
AutoCodePluginApi
}
// 业务层依赖
@@ -42,6 +45,7 @@ var (
exportTemplateUsecase *system.ExportTemplateUsecase
autoCodeUsecase *system.AutoCodeUsecase
autoCodeHistoryUsecase *system.AutoCodeHistoryUsecase
autoCodePackageUsecase *system.AutoCodePackageUsecase
)
// InitUsecases 初始化业务层依赖
@@ -62,6 +66,7 @@ func InitUsecases(
exportTemplate *system.ExportTemplateUsecase,
autoCode *system.AutoCodeUsecase,
autoCodeHistory *system.AutoCodeHistoryUsecase,
autoCodePackage *system.AutoCodePackageUsecase,
) {
userUsecase = user
apiUsecase = api
@@ -79,4 +84,10 @@ func InitUsecases(
exportTemplateUsecase = exportTemplate
autoCodeUsecase = autoCode
autoCodeHistoryUsecase = autoCodeHistory
autoCodePackageUsecase = autoCodePackage
}
// Api类型定义
type AutoCodePackageApi struct{}
type AutoCodeTemplateApi struct{}
type AutoCodePluginApi struct{}
@@ -0,0 +1,60 @@
package system
import (
"kra/pkg/response"
"github.com/gin-gonic/gin"
)
// GetPackages 获取所有包
// @Tags AutoCodePackage
// @Summary 获取所有包
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {object} response.Response{data=[]system.SysAutoCodePackage} "获取成功"
// @Router /autoCode/getPackage [post]
func GetPackages(c *gin.Context) {
pkgs, err := autoCodePackageUsecase.All(c.Request.Context())
if err != nil {
response.FailWithMessage("获取失败: "+err.Error(), c)
return
}
response.OkWithDetailed(pkgs, "获取成功", c)
}
// DeletePackage 删除包
// @Tags AutoCodePackage
// @Summary 删除包
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetById true "删除包"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /autoCode/delPackage [post]
func DeletePackage(c *gin.Context) {
var req struct {
ID uint `json:"id"`
}
if err := c.ShouldBindJSON(&req); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := autoCodePackageUsecase.Delete(c.Request.Context(), req.ID); err != nil {
response.FailWithMessage("删除失败: "+err.Error(), c)
return
}
response.OkWithMessage("删除成功", c)
}
// GetTemplates 获取所有模版
// @Tags AutoCodePackage
// @Summary 获取所有模版
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {object} response.Response{data=[]string} "获取成功"
// @Router /autoCode/getTemplates [get]
func GetTemplates(c *gin.Context) {
// 返回固定的模版列表
templates := []string{"package", "plugin"}
response.OkWithDetailed(templates, "获取成功", c)
}
@@ -0,0 +1,63 @@
package system
import (
"kra/pkg/response"
"github.com/gin-gonic/gin"
)
// InstallPlugin 安装插件
// @Tags AutoCodePlugin
// @Summary 安装插件
// @Security ApiKeyAuth
// @accept multipart/form-data
// @Produce application/json
// @Param plug formData file true "插件文件"
// @Success 200 {object} response.Response{data=[]interface{}} "安装成功"
// @Router /autoCode/installPlugin [post]
func InstallPlugin(c *gin.Context) {
// TODO: 实现插件安装功能
response.FailWithMessage("功能开发中", c)
}
// PackagedPlugin 打包插件
// @Tags AutoCodePlugin
// @Summary 打包插件
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param plugName query string true "插件名称"
// @Success 200 {object} response.Response{msg=string} "打包成功"
// @Router /autoCode/pubPlug [post]
func PackagedPlugin(c *gin.Context) {
// TODO: 实现插件打包功能
response.FailWithMessage("功能开发中", c)
}
// InitPluginMenu 初始化插件菜单
// @Tags AutoCodePlugin
// @Summary 初始化插件菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body map[string]interface{} true "菜单信息"
// @Success 200 {object} response.Response{msg=string} "初始化成功"
// @Router /autoCode/initMenu [post]
func InitPluginMenu(c *gin.Context) {
// TODO: 实现插件菜单初始化功能
response.FailWithMessage("功能开发中", c)
}
// InitPluginAPI 初始化插件API
// @Tags AutoCodePlugin
// @Summary 初始化插件API
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body map[string]interface{} true "API信息"
// @Success 200 {object} response.Response{msg=string} "初始化成功"
// @Router /autoCode/initAPI [post]
func InitPluginAPI(c *gin.Context) {
// TODO: 实现插件API初始化功能
response.FailWithMessage("功能开发中", c)
}
@@ -0,0 +1,49 @@
package system
import (
"kra/pkg/response"
"github.com/gin-gonic/gin"
)
// PreviewCode 预览代码
// @Tags AutoCodeTemplate
// @Summary 预览创建后的代码
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body map[string]interface{} true "预览创建代码"
// @Success 200 {object} response.Response{data=map[string]interface{}} "预览成功"
// @Router /autoCode/preview [post]
func PreviewCode(c *gin.Context) {
// TODO: 实现代码预览功能
response.FailWithMessage("功能开发中", c)
}
// CreateCode 创建代码
// @Tags AutoCodeTemplate
// @Summary 自动代码模板
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body map[string]interface{} true "创建自动代码"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /autoCode/createTemp [post]
func CreateCode(c *gin.Context) {
// TODO: 实现代码创建功能
response.FailWithMessage("功能开发中", c)
}
// AddFunc 增加方法
// @Tags AutoCodeTemplate
// @Summary 增加方法
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body map[string]interface{} true "增加方法"
// @Success 200 {object} response.Response{msg=string} "注入成功"
// @Router /autoCode/addFunc [post]
func AddFunc(c *gin.Context) {
// TODO: 实现方法注入功能
response.FailWithMessage("功能开发中", c)
}