feat:update api model router tpl

This commit is contained in:
zhangwenjian
2020-09-10 14:14:08 +08:00
parent fa07a57d22
commit 8a7a9db7fd
12 changed files with 148 additions and 38 deletions
+84
View File
@@ -0,0 +1,84 @@
package student
import (
"github.com/gin-gonic/gin"
"go-admin/app/admin/models"
"go-admin/app/admin/service/dto"
"go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/app/msg"
)
func GetStudentList(c *gin.Context) {
var data models.Student
var err error
var pageSize = 10
var pageIndex = 1
if size := c.Request.FormValue("pageSize"); size != "" {
pageSize, err = tools.StringToInt(size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex, err = tools.StringToInt(index)
}
var v dto.StudentSearch
err = c.Bind(&v)
tools.HasError(err, "数据解析失败", 422)
data.DataScope = tools.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex, v)
tools.HasError(err, "", -1)
app.PageOK(c, result, count, pageIndex, pageSize, "")
}
func GetStudent(c *gin.Context) {
var data models.Student
data.Id, _ = tools.StringToInt(c.Param("id"))
result, err := data.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c, result, "")
}
// @Summary 添加Student
// @Description 获取JSON
// @Tags Student
// @Accept application/json
// @Product application/json
// @Param data body models.Student true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/student [post]
func InsertStudent(c *gin.Context) {
var data models.Student
err := c.ShouldBindJSON(&data)
data.CreateBy = tools.GetUserIdStr(c)
tools.HasError(err, "", 500)
result, err := data.Create()
tools.HasError(err, "", -1)
app.OK(c, result, "")
}
func UpdateStudent(c *gin.Context) {
var data models.Student
err := c.ShouldBindJSON(&data)
tools.HasError(err, "数据解析失败", -1)
data.UpdateBy = tools.GetUserIdStr(c)
result, err := data.Update(data.Id)
tools.HasError(err, "", -1)
app.OK(c, result, "")
}
func DeleteStudent(c *gin.Context) {
var data models.Student
data.UpdateBy = tools.GetUserIdStr(c)
IDS := tools.IdsStrToIdsIntGroup("id", c)
_, err := data.BatchDelete(IDS)
tools.HasError(err, msg.DeletedFail, 500)
app.OK(c, nil, msg.DeletedSuccess)
}
+6 -6
View File
@@ -71,7 +71,7 @@ func GenCode(c *gin.Context) {
oldTest := "// {{认证路由自动补充在此处请勿删除}}"
newText := "// {{认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1,authMiddleware)"
if !tab.IsAuth {
if tab.IsAuth == 2 {
oldTest = "// {{无需认证路由自动补充在此处请勿删除}}"
newText = "// {{无需认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1)"
routerfile = "template/routernocheckrole.go.template"
@@ -142,7 +142,7 @@ func GenCodeV2(c *gin.Context) {
table.TableId = id
tab, _ := table.Get()
if tab.IsActions {
if tab.IsActions == 1 {
ActionsGen(tab)
} else {
NOActionsGen(tab)
@@ -154,7 +154,7 @@ func GenCodeV2(c *gin.Context) {
func NOActionsGen(tab tools.SysTables) {
routerfile := "template/routercheckrole.go.template"
if !tab.IsAuth {
if tab.IsAuth == 2 {
routerfile = "template/routernocheckrole.go.template"
}
@@ -171,7 +171,7 @@ func NOActionsGen(tab tools.SysTables) {
t6, err := template.ParseFiles("template/v2/dto.go.template")
tools2.HasError(err, "", -1)
_ = tools2.PathCreate("./app/" + tab.PackageName + "/apis/" + tab.ModuleName + "/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/apis/" + tab.ModuleName)
_ = tools2.PathCreate("./app/" + tab.PackageName + "/models/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/router/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/service/dto/")
@@ -202,7 +202,7 @@ func NOActionsGen(tab tools.SysTables) {
func ActionsGen(tab tools.SysTables) {
routerfile := "template/v2/routercheckrole.go.template"
if !tab.IsAuth {
if tab.IsAuth == 2 {
routerfile = "template/v2/routernocheckrole.go.template"
}
@@ -464,7 +464,7 @@ func GenMenuAndApi(c *gin.Context) {
ADelete.MenuName = ""
ADelete.Title = "删除" + tab.TableComment
ADelete.Icon = "bug"
ADelete.Path = "/api/v1/" + tab.ModuleName + "/:id"
ADelete.Path = "/api/v1/" + tab.ModuleName
ADelete.MenuType = "A"
ADelete.Action = "DELETE"
ADelete.ParentId = Amenu.MenuId