增加了前端api模板
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import service from '@/utils/request'
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 创建{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body {{.PackageName}}.{{.StructName}} true "创建{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /{{.Abbreviation}}/create{{.StructName}} [post]
|
||||
export const create{{.StructName}} = (data) => {
|
||||
return service({
|
||||
url: "/{{.Abbreviation}}/create{{.StructName}}",
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 删除{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body {{.PackageName}}.{{.StructName}} true "删除{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /{{.Abbreviation}}/delete{{.StructName}} [post]
|
||||
export const delete{{.StructName}} = (data) => {
|
||||
return service({
|
||||
url: "/{{.Abbreviation}}/delete{{.StructName}}",
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 更新{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body {{.PackageName}}.{{.StructName}} true "更新{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||
// @Router /{{.Abbreviation}}/update{{.StructName}} [post]
|
||||
export const update{{.StructName}} = (data) => {
|
||||
return service({
|
||||
url: "/{{.Abbreviation}}/update{{.StructName}}",
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 用id查询{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body {{.PackageName}}.{{.StructName}} true "用id查询{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
||||
// @Router /{{.Abbreviation}}/find{{.StructName}} [post]
|
||||
export const find{{.StructName}} = (data) => {
|
||||
return service({
|
||||
url: "/{{.Abbreviation}}/find{{.StructName}}",
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 分页获取{{.StructName}}列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body modelInterface.PageInfo true "分页获取{{.StructName}}列表"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /{{.Abbreviation}}/get{{.StructName}}List [post]
|
||||
export const get{{.StructName}}List = (data) => {
|
||||
return service({
|
||||
url: "/{{.Abbreviation}}/get{{.StructName}}List",
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"gin-vue-admin/controller/servers"
|
||||
"gin-vue-admin/model/modelInterface"
|
||||
"gin-vue-admin/model/sysModel"
|
||||
// 请自行引入model路径
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -27,3 +27,92 @@ func Create{{.StructName}}(c *gin.Context) {
|
||||
servers.ReportFormat(c, true, "创建成功", gin.H{})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 删除{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body {{.PackageName}}.{{.StructName}} true "删除{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /{{.Abbreviation}}/delete{{.StructName}} [post]
|
||||
func Delete{{.StructName}}(c *gin.Context) {
|
||||
var {{.Abbreviation}} {{.PackageName}}.{{.StructName}}
|
||||
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
||||
err := {{.Abbreviation}}.Delete{{.StructName}}()
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "创建成功", gin.H{})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 更新{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body {{.PackageName}}.{{.StructName}} true "更新{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||
// @Router /{{.Abbreviation}}/update{{.StructName}} [post]
|
||||
func Update{{.StructName}}(c *gin.Context) {
|
||||
var {{.Abbreviation}} {{.PackageName}}.{{.StructName}}
|
||||
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
||||
err,re{{.Abbreviation}} := {{.Abbreviation}}.Update{{.StructName}}()
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("更新失败:%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "更新成功", gin.H{
|
||||
"re{{.Abbreviation}}":re{{.Abbreviation}},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 用id查询{{.StructName}}
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body {{.PackageName}}.{{.StructName}} true "用id查询{{.StructName}}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
||||
// @Router /{{.Abbreviation}}/find{{.StructName}} [post]
|
||||
func Find{{.StructName}}(c *gin.Context) {
|
||||
var {{.Abbreviation}} {{.PackageName}}.{{.StructName}}
|
||||
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
||||
err,re{{.Abbreviation}} := {{.Abbreviation}}.FindById()
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("查询失败:%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "查询成功", gin.H{
|
||||
"re{{.Abbreviation}}":re{{.Abbreviation}},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary 分页获取{{.StructName}}列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body modelInterface.PageInfo true "分页获取{{.StructName}}列表"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /{{.Abbreviation}}/get{{.StructName}}List [post]
|
||||
func Get{{.StructName}}List(c *gin.Context) {
|
||||
var pageInfo modelInterface.PageInfo
|
||||
_ = c.ShouldBindJSON(&pageInfo)
|
||||
err, list, total := new({{.PackageName}}.{{.StructName}}).GetInfoList(pageInfo)
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "获取数据成功", gin.H{
|
||||
"{{.PackageName}}List": list,
|
||||
"total": total,
|
||||
"page": pageInfo.Page,
|
||||
"pageSize": pageInfo.PageSize,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"gin-vue-admin/controller/api"
|
||||
"gin-vue-admin/middleware"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Init{{.StructName}}Router(Router *gin.RouterGroup) {
|
||||
{{.StructName}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
|
||||
{
|
||||
{{.StructName}}Router.POST("create{{.StructName}}", api.Create{{.StructName}}) // 新建{{.StructName}}
|
||||
{{.StructName}}Router.POST("delete{{.StructName}}", api.Delete{{.StructName}}) //删除{{.StructName}}
|
||||
{{.StructName}}Router.POST("update{{.StructName}}", api.Update{{.StructName}}) //更新{{.StructName}}
|
||||
{{.StructName}}Router.POST("find{{.StructName}} ", api.Find{{.StructName}}) // 根据ID获取{{.StructName}}
|
||||
{{.StructName}}Router.POST("get{{.StructName}}List", api.Get{{.StructName}}List) //获取{{.StructName}}列表
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user