|
@@ -1,10 +1,13 @@
|
|
|
-package api
|
|
|
+package v1
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
- "gin-vue-admin/global/response"
|
|
|
+ "gin-vue-admin/global/response"
|
|
|
"gin-vue-admin/model"
|
|
|
- "github.com/gin-gonic/gin"
|
|
|
+ "gin-vue-admin/model/request"
|
|
|
+ resp "gin-vue-admin/model/response"
|
|
|
+ "gin-vue-admin/service"
|
|
|
+ "github.com/gin-gonic/gin"
|
|
|
)
|
|
|
|
|
|
|
|
@@ -17,13 +20,13 @@ import (
|
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|
|
// @Router /{{.Abbreviation}}/create{{.StructName}} [post]
|
|
|
func Create{{.StructName}}(c *gin.Context) {
|
|
|
- var {{.Abbreviation}} {{.PackageName}}.{{.StructName}}
|
|
|
+ var {{.Abbreviation}} model.{{.StructName}}
|
|
|
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
|
|
- err := {{.Abbreviation}}.Create{{.StructName}}()
|
|
|
+ err := service.Create{{.StructName}}({{.Abbreviation}})
|
|
|
if err != nil {
|
|
|
- response.Result(response.ERROR, gin.H{}, fmt.Sprintf("创建失败,%v", err), c)
|
|
|
+ response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
|
|
|
} else {
|
|
|
- response.Result(response.SUCCESS, gin.H{}, "创建成功", c)
|
|
|
+ response.OkWithMessage("创建成功", c)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -35,15 +38,15 @@ func Create{{.StructName}}(c *gin.Context) {
|
|
|
// @Produce application/json
|
|
|
// @Param data body model.{{.StructName}} true "删除{{.StructName}}"
|
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
|
|
-// @Router /{{.Abbreviation}}/delete{{.StructName}} [post]
|
|
|
+// @Router /{{.Abbreviation}}/delete{{.StructName}} [delete]
|
|
|
func Delete{{.StructName}}(c *gin.Context) {
|
|
|
- var {{.Abbreviation}} {{.PackageName}}.{{.StructName}}
|
|
|
+ var {{.Abbreviation}} model.{{.StructName}}
|
|
|
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
|
|
- err := {{.Abbreviation}}.Delete{{.StructName}}()
|
|
|
+ err := service.Delete{{.StructName}}({{.Abbreviation}})
|
|
|
if err != nil {
|
|
|
- response.Result(response.ERROR, gin.H{}, fmt.Sprintf("删除失败,%v", err), c)
|
|
|
+ response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
|
|
|
} else {
|
|
|
- response.Result(response.SUCCESS, gin.H{}, "删除成功", c)
|
|
|
+ response.OkWithMessage("删除成功", c)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -55,17 +58,15 @@ func Delete{{.StructName}}(c *gin.Context) {
|
|
|
// @Produce application/json
|
|
|
// @Param data body model.{{.StructName}} true "更新{{.StructName}}"
|
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
|
|
-// @Router /{{.Abbreviation}}/update{{.StructName}} [post]
|
|
|
+// @Router /{{.Abbreviation}}/update{{.StructName}} [put]
|
|
|
func Update{{.StructName}}(c *gin.Context) {
|
|
|
- var {{.Abbreviation}} {{.PackageName}}.{{.StructName}}
|
|
|
+ var {{.Abbreviation}} model.{{.StructName}}
|
|
|
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
|
|
- err,re{{.Abbreviation}} := {{.Abbreviation}}.Update{{.StructName}}()
|
|
|
+ err := service.Update{{.StructName}}(&{{.Abbreviation}})
|
|
|
if err != nil {
|
|
|
- response.Result(response.ERROR, gin.H{}, fmt.Sprintf("更新失败,%v", err), c)
|
|
|
+ response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
|
|
|
} else {
|
|
|
- response.Result(response.SUCCESS, gin.H{
|
|
|
- "re{{.Abbreviation}}":re{{.Abbreviation}},
|
|
|
- }, "更新成功", c)
|
|
|
+ response.OkWithMessage("删除成功", c)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -77,17 +78,15 @@ func Update{{.StructName}}(c *gin.Context) {
|
|
|
// @Produce application/json
|
|
|
// @Param data body model.{{.StructName}} true "用id查询{{.StructName}}"
|
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
|
|
-// @Router /{{.Abbreviation}}/find{{.StructName}} [post]
|
|
|
+// @Router /{{.Abbreviation}}/find{{.StructName}} [get]
|
|
|
func Find{{.StructName}}(c *gin.Context) {
|
|
|
- var {{.Abbreviation}} {{.PackageName}}.{{.StructName}}
|
|
|
- _ = c.ShouldBindJSON(&{{.Abbreviation}})
|
|
|
- err,re{{.Abbreviation}} := {{.Abbreviation}}.FindById()
|
|
|
+ var {{.Abbreviation}} model.{{.StructName}}
|
|
|
+ _ = c.ShouldBindQuery(&{{.Abbreviation}})
|
|
|
+ err,re{{.Abbreviation}} := service.Get{{.StructName}}({{.Abbreviation}}.ID)
|
|
|
if err != nil {
|
|
|
- response.Result(response.ERROR, gin.H{}, fmt.Sprintf("查询失败,%v", err), c)
|
|
|
+ response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
|
|
|
} else {
|
|
|
- response.Result(response.SUCCESS, gin.H{
|
|
|
- "re{{.Abbreviation}}":re{{.Abbreviation}},
|
|
|
- }, "查询成功", c)
|
|
|
+ response.OkWithData( gin.H{"re{{.Abbreviation}}":re{{.Abbreviation}},}, c)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -99,19 +98,19 @@ func Find{{.StructName}}(c *gin.Context) {
|
|
|
// @Produce application/json
|
|
|
// @Param data body request.PageInfo true "分页获取{{.StructName}}列表"
|
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|
|
-// @Router /{{.Abbreviation}}/get{{.StructName}}List [post]
|
|
|
+// @Router /{{.Abbreviation}}/get{{.StructName}}List [get]
|
|
|
func Get{{.StructName}}List(c *gin.Context) {
|
|
|
var pageInfo request.PageInfo
|
|
|
- _ = c.ShouldBindJSON(&pageInfo)
|
|
|
- err, list, total := new({{.PackageName}}.{{.StructName}}).GetInfoList(pageInfo)
|
|
|
+ _ = c.ShouldBindQuery(&pageInfo)
|
|
|
+ err, list, total := service.Get{{.StructName}}InfoList(pageInfo)
|
|
|
if err != nil {
|
|
|
- response.Result(response.ERROR, gin.H{}, fmt.Sprintf("获取数据失败,%v", err), c)
|
|
|
+ response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
|
|
|
} else {
|
|
|
- response.Result(response.SUCCESS, gin.H{
|
|
|
- "{{.PackageName}}List": list,
|
|
|
- "total": total,
|
|
|
- "page": pageInfo.Page,
|
|
|
- "pageSize": pageInfo.PageSize,
|
|
|
- }, "获取数据成功", c)
|
|
|
+ response.OkWithData(resp.PageResult{
|
|
|
+ List: list,
|
|
|
+ Total: total,
|
|
|
+ Page: pageInfo.Page,
|
|
|
+ PageSize: pageInfo.PageSize,
|
|
|
+ }, c)
|
|
|
}
|
|
|
}
|