完善生成模版,调整目录

This commit is contained in:
xh
2025-06-25 01:31:34 +08:00
parent cf4e879fe2
commit 915bcfe22c
35 changed files with 57 additions and 67 deletions
@@ -0,0 +1,108 @@
package commonController
import (
"x_admin/core/request"
"x_admin/core/response"
"x_admin/middleware"
"x_admin/schema/commonSchema"
"x_admin/service/commonService"
"x_admin/util"
"github.com/gin-gonic/gin"
)
func AlbumRoute(rg *gin.RouterGroup) {
handle := albumHandler{}
rg = rg.Group("/common", middleware.TokenAuth())
rg.GET("/album/albumList", handle.albumList)
rg.POST("/album/albumRename", middleware.RecordLog("相册文件重命名"), handle.albumRename)
rg.POST("/album/albumMove", middleware.RecordLog("相册文件移动"), handle.albumMove)
rg.POST("/album/albumDel", middleware.RecordLog("相册文件删除"), handle.albumDel)
rg.GET("/album/cateList", handle.cateList)
rg.POST("/album/cateAdd", middleware.RecordLog("相册分类新增"), handle.cateAdd)
rg.POST("/album/cateRename", middleware.RecordLog("相册分类重命名"), handle.cateRename)
rg.POST("/album/cateDel", middleware.RecordLog("相册分类删除"), handle.cateDel)
}
type albumHandler struct{}
// albumList 相册文件列表
func (ah albumHandler) albumList(c *gin.Context) {
var page request.PageReq
var listReq commonSchema.CommonAlbumListReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
return
}
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
return
}
res, err := commonService.AlbumService.AlbumList(page, listReq)
response.CheckAndRespWithData(c, res, err)
}
// albumRename 相册文件重命名
func (ah albumHandler) albumRename(c *gin.Context) {
var rnReq commonSchema.CommonAlbumRenameReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &rnReq)) {
return
}
response.CheckAndResp(c, commonService.AlbumService.AlbumRename(rnReq.ID, rnReq.Name))
}
// albumMove 相册文件移动
func (ah albumHandler) albumMove(c *gin.Context) {
var mvReq commonSchema.CommonAlbumMoveReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &mvReq)) {
return
}
response.CheckAndResp(c, commonService.AlbumService.AlbumMove(mvReq.Ids, mvReq.Cid))
}
// albumDel 相册文件删除
func (ah albumHandler) albumDel(c *gin.Context) {
var delReq commonSchema.CommonAlbumDelReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
return
}
response.CheckAndResp(c, commonService.AlbumService.AlbumDel(delReq.Ids))
}
// cateList 类目列表
func (ah albumHandler) cateList(c *gin.Context) {
var listReq commonSchema.CommonCateListReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
return
}
res, err := commonService.AlbumService.CateList(listReq)
response.CheckAndRespWithData(c, res, err)
}
// cateAdd 类目新增
func (ah albumHandler) cateAdd(c *gin.Context) {
var addReq commonSchema.CommonCateAddReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &addReq)) {
return
}
response.CheckAndResp(c, commonService.AlbumService.CateAdd(addReq))
}
// cateRename 类目命名
func (ah albumHandler) cateRename(c *gin.Context) {
var rnReq commonSchema.CommonCateRenameReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &rnReq)) {
return
}
response.CheckAndResp(c, commonService.AlbumService.CateRename(rnReq.ID, rnReq.Name))
}
// cateDel 类目删除
func (ah albumHandler) cateDel(c *gin.Context) {
var delReq commonSchema.CommonCateDelReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
return
}
response.CheckAndResp(c, commonService.AlbumService.CateDel(delReq.ID))
}
@@ -0,0 +1,71 @@
package commonController
import (
"errors"
"x_admin/schema/commonSchema"
"x_admin/service/commonService"
"github.com/gin-gonic/gin"
)
func CaptchaRoute(rg *gin.RouterGroup) {
rg = rg.Group("/common/captcha")
rg.POST("/get", func(c *gin.Context) {
var captchaGet commonSchema.CaptchaGetParams
if err := c.ShouldBind(&captchaGet); err != nil {
// 返回错误信息
c.JSON(200, errorRes(err))
return
}
if captchaGet.CaptchaType == "" {
c.JSON(200, errorRes(errors.New("验证码类型不能为空")))
return
}
// 根据参数类型获取不同服务即可
data, err := commonService.CaptchaGet(captchaGet.CaptchaType)
if err != nil {
c.JSON(200, errorRes(err))
return
}
//输出json结果给调用方
c.JSON(200, successRes(data))
})
rg.POST("/check", func(c *gin.Context) {
var params commonSchema.ClientParams
if err := c.ShouldBind(&params); err != nil {
// 返回错误信息
c.JSON(200, errorRes(err))
return
}
err := commonService.CaptchaCheck(params)
if err != nil {
c.JSON(200, errorRes(err))
return
}
//输出json结果给调用方
c.JSON(200, successRes(nil))
})
}
func successRes(data interface{}) map[string]interface{} {
ret := make(map[string]interface{})
ret["error"] = false
ret["repCode"] = "0000"
ret["repData"] = data
ret["repMsg"] = nil
ret["successRes"] = true
return ret
}
func errorRes(err error) map[string]interface{} {
ret := make(map[string]interface{})
ret["error"] = true
ret["repCode"] = "0001"
ret["repData"] = nil
ret["repMsg"] = err.Error()
ret["successRes"] = false
return ret
}
@@ -0,0 +1,32 @@
package commonController
import (
"x_admin/core/response"
"x_admin/middleware"
"x_admin/service/commonService"
"github.com/gin-gonic/gin"
)
func IndexRoute(rg *gin.RouterGroup) {
handle := indexHandler{}
rg = rg.Group("/common", middleware.TokenAuth())
rg.GET("/index/console", handle.console)
rg.GET("/index/config", handle.config)
}
type indexHandler struct{}
// console 控制台
func (ih indexHandler) console(c *gin.Context) {
res, err := commonService.IndexService.Console()
response.CheckAndRespWithData(c, res, err)
}
// config 公共配置
func (ih indexHandler) config(c *gin.Context) {
res, err := commonService.IndexService.Config()
response.CheckAndRespWithData(c, res, err)
}
@@ -0,0 +1,50 @@
package commonController
import (
"x_admin/config"
"x_admin/core/response"
"x_admin/middleware"
"x_admin/schema/commonSchema"
"x_admin/service/commonService"
"x_admin/util"
"github.com/gin-gonic/gin"
)
func UploadRoute(rg *gin.RouterGroup) {
handle := uploadHandler{}
rg = rg.Group("/common", middleware.TokenAuth())
rg.POST("/upload/image", middleware.RecordLog("上传图片", middleware.RequestFile), handle.uploadImage)
rg.POST("/upload/video", middleware.RecordLog("上传视频", middleware.RequestFile), handle.uploadVideo)
}
type uploadHandler struct{}
// uploadImage 上传图片
func (uh uploadHandler) uploadImage(c *gin.Context) {
var uReq commonSchema.CommonUploadImageReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &uReq)) {
return
}
file, ve := util.VerifyUtil.VerifyFile(c, "file")
if response.IsFailWithResp(c, ve) {
return
}
res, err := commonService.UploadService.UploadImage(file, uReq.Cid, config.AdminConfig.GetAdminId(c))
response.CheckAndRespWithData(c, res, err)
}
// uploadVideo 上传视频
func (uh uploadHandler) uploadVideo(c *gin.Context) {
var uReq commonSchema.CommonUploadImageReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &uReq)) {
return
}
file, ve := util.VerifyUtil.VerifyFile(c, "file")
if response.IsFailWithResp(c, ve) {
return
}
res, err := commonService.UploadService.UploadVideo(file, uReq.Cid, config.AdminConfig.GetAdminId(c))
response.CheckAndRespWithData(c, res, err)
}