Skip to content

Commit

Permalink
Code generation module
Browse files Browse the repository at this point in the history
  • Loading branch information
wenjianzhang committed Mar 19, 2020
1 parent e149589 commit 65dbf58
Show file tree
Hide file tree
Showing 13 changed files with 497 additions and 62 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@ main.exe
temp/logs/log.txt
vendor
config/settings.dev.yml
temp/logs/log.txt
20 changes: 10 additions & 10 deletions apis/role.go
Expand Up @@ -10,12 +10,12 @@ import (
"strconv"
)

// @Summary 配置列表数据
// @Description 获取JSON
// @Tags 配置
// @Param configKey query string false "configKey"
// @Param configName query string false "configName"
// @Param configType query string false "configType"
// @Summary 角色列表数据
// @Description Get JSON
// @Tags 角色/Role
// @Param roleName query string false "roleName"
// @Param status query string false "status"
// @Param roleKey query string false "roleKey"
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} models.Response "{"code": 200, "data": [...]}"
Expand Down Expand Up @@ -56,7 +56,7 @@ func GetRoleList(c *gin.Context) {

// @Summary 获取Role数据
// @Description 获取JSON
// @Tags 角色
// @Tags 角色/Role
// @Param roleId path string false "roleId"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
Expand Down Expand Up @@ -87,7 +87,7 @@ func GetRole(c *gin.Context) {

// @Summary 创建角色
// @Description 获取JSON
// @Tags 角色
// @Tags 角色/Role
// @Accept application/json
// @Product application/json
// @Param data body models.Config true "data"
Expand All @@ -113,7 +113,7 @@ func InsertRole(c *gin.Context) {

// @Summary 修改用户角色
// @Description 获取JSON
// @Tags 角色
// @Tags 角色/Role
// @Accept application/json
// @Product application/json
// @Param data body models.SysRole true "body"
Expand Down Expand Up @@ -162,7 +162,7 @@ func UpdateRoleDataScope(c *gin.Context) {

// @Summary 删除用户角色
// @Description 删除数据
// @Tags 角色
// @Tags 角色/Role
// @Param roleId path int true "roleId"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
Expand Down
48 changes: 48 additions & 0 deletions apis/tools/dbcolumns.go
@@ -0,0 +1,48 @@
package tools

import (
"github.com/gin-gonic/gin"
"go-admin/models"
"go-admin/models/tools"
"go-admin/pkg"
"net/http"
)

// @Summary 分页列表数据 / page list data
// @Description 数据库表列分页列表 / database table column page list
// @Tags 工具 / Tools
// @Param tableName query string false "tableName / 数据表名称"
// @Param pageSize query int false "pageSize / 页条数"
// @Param pageIndex query int false "pageIndex / 页码"
// @Success 200 {object} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/db/columns/page [get]
func GetDBColumnList(c *gin.Context) {
var data tools.DBColumns
var err error
var pageSize = 10
var pageIndex = 1

if size := c.Request.FormValue("pageSize"); size != "" {
pageSize = pkg.StrToInt(err, size)
}

if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex = pkg.StrToInt(err, index)
}

data.TableName = c.Request.FormValue("tableName")
pkg.Assert(data.TableName=="","table name cannot be empty!",500)
result, count, err := data.GetPage(pageSize, pageIndex)
pkg.AssertErr(err, "", -1)

var mp = make(map[string]interface{}, 3)
mp["list"] = result
mp["count"] = count
mp["pageIndex"] = pageIndex
mp["pageIndex"] = pageSize

var res models.Response
res.Data = mp

c.JSON(http.StatusOK, res.ReturnOK())
}
47 changes: 47 additions & 0 deletions apis/tools/dbtables.go
@@ -0,0 +1,47 @@
package tools

import (
"github.com/gin-gonic/gin"
"go-admin/models"
"go-admin/models/tools"
"go-admin/pkg"
"net/http"
)

// @Summary 分页列表数据 / page list data
// @Description 数据库表分页列表 / database table page list
// @Tags 工具 / Tools
// @Param tableName query string false "tableName / 数据表名称"
// @Param pageSize query int false "pageSize / 页条数"
// @Param pageIndex query int false "pageIndex / 页码"
// @Success 200 {object} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/db/tables/page [get]
func GetDBTableList(c *gin.Context) {
var data tools.DBTables
var err error
var pageSize = 10
var pageIndex = 1

if size := c.Request.FormValue("pageSize"); size != "" {
pageSize = pkg.StrToInt(err, size)
}

if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex = pkg.StrToInt(err, index)
}

data.TableName = c.Request.FormValue("tableName")
result, count, err := data.GetPage(pageSize, pageIndex)
pkg.AssertErr(err, "", -1)

var mp = make(map[string]interface{}, 3)
mp["list"] = result
mp["count"] = count
mp["pageIndex"] = pageIndex
mp["pageIndex"] = pageSize

var res models.Response
res.Data = mp

c.JSON(http.StatusOK, res.ReturnOK())
}
47 changes: 47 additions & 0 deletions apis/tools/systables.go
@@ -0,0 +1,47 @@
package tools

import (
"github.com/gin-gonic/gin"
"go-admin/models"
"go-admin/models/tools"
"go-admin/pkg"
"net/http"
)

// @Summary 分页列表数据 / page list data
// @Description 生成表分页列表 / gen table page list
// @Tags 工具 - Tools / 生成表 - Gen Table
// @Param tableName query string false "tableName / 数据表名称"
// @Param pageSize query int false "pageSize / 页条数"
// @Param pageIndex query int false "pageIndex / 页码"
// @Success 200 {object} models.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/sys/tables/page [get]
func GetSysTableList(c *gin.Context) {
var data tools.SysTables
var err error
var pageSize = 10
var pageIndex = 1

if size := c.Request.FormValue("pageSize"); size != "" {
pageSize = pkg.StrToInt(err, size)
}

if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex = pkg.StrToInt(err, index)
}

data.TableName = c.Request.FormValue("tableName")
result, count, err := data.GetPage(pageSize, pageIndex)
pkg.AssertErr(err, "", -1)

var mp = make(map[string]interface{}, 3)
mp["list"] = result
mp["count"] = count
mp["pageIndex"] = pageIndex
mp["pageIndex"] = pageSize

var res models.Response
res.Data = mp

c.JSON(http.StatusOK, res.ReturnOK())
}
73 changes: 55 additions & 18 deletions docs/docs.go
@@ -1,6 +1,6 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2020-03-17 14:25:08.714368 +0800 CST m=+0.081722206
// 2020-03-19 00:24:21.426215 +0800 CST m=+0.087420189

package docs

Expand Down Expand Up @@ -436,9 +436,9 @@ var doc = `{
"application/json"
],
"tags": [
"字典数据"
"配置"
],
"summary": "添加字典数据",
"summary": "添加配置",
"parameters": [
{
"description": "data",
Expand All @@ -447,7 +447,7 @@ var doc = `{
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/models.DictType"
"$ref": "#/definitions/models.Config"
}
}
],
Expand Down Expand Up @@ -1570,7 +1570,7 @@ var doc = `{
],
"description": "获取JSON",
"tags": [
"角色"
"角色/Role"
],
"summary": "获取Role数据",
"parameters": [
Expand All @@ -1596,7 +1596,7 @@ var doc = `{
"application/json"
],
"tags": [
"角色"
"角色/Role"
],
"summary": "修改用户角色",
"parameters": [
Expand Down Expand Up @@ -1626,7 +1626,7 @@ var doc = `{
"application/json"
],
"tags": [
"角色"
"角色/Role"
],
"summary": "创建角色",
"parameters": [
Expand Down Expand Up @@ -1655,7 +1655,7 @@ var doc = `{
"delete": {
"description": "删除数据",
"tags": [
"角色"
"角色/Role"
],
"summary": "删除用户角色",
"parameters": [
Expand Down Expand Up @@ -1684,28 +1684,28 @@ var doc = `{
"": []
}
],
"description": "获取JSON",
"description": "Get JSON",
"tags": [
"配置"
"角色/Role"
],
"summary": "配置列表数据",
"summary": "角色列表数据",
"parameters": [
{
"type": "string",
"description": "configKey",
"name": "configKey",
"description": "roleName",
"name": "roleName",
"in": "query"
},
{
"type": "string",
"description": "configName",
"name": "configName",
"description": "status",
"name": "status",
"in": "query"
},
{
"type": "string",
"description": "configType",
"name": "configType",
"description": "roleKey",
"name": "roleKey",
"in": "query"
},
{
Expand Down Expand Up @@ -1996,6 +1996,43 @@ var doc = `{
}
}
},
"/api/v1/tables/page": {
"get": {
"description": "数据库表分页列表 / database table page list",
"tags": [
"工具 / Tools"
],
"summary": "分页列表数据 / page list data",
"parameters": [
{
"type": "string",
"description": "tableName / 数据表名称",
"name": "tableName",
"in": "query"
},
{
"type": "integer",
"description": "pageSize / 页条数",
"name": "pageSize",
"in": "query"
},
{
"type": "integer",
"description": "pageIndex / 页码",
"name": "pageIndex",
"in": "query"
}
],
"responses": {
"200": {
"description": "{\"code\": 200, \"data\": [...]}",
"schema": {
"$ref": "#/definitions/models.Response"
}
}
}
}
},
"/api/v1/user/profile": {
"get": {
"security": [
Expand Down Expand Up @@ -2955,7 +2992,7 @@ var SwaggerInfo = swaggerInfo{
BasePath: "",
Schemes: []string{},
Title: "go-admin API",
Description: "基于Gin + Vue + Element UI的前后端分离权限管理系统的接口文档\n添加微信号: zwj891129 进入技术交流微信群 请备注,谢谢!",
Description: "基于Gin + Vue + Element UI的前后端分离权限管理系统的接口文档\n添加qq群: 74520518 进入技术交流群 请备注,谢谢!",
}

type s struct{}
Expand Down

0 comments on commit 65dbf58

Please sign in to comment.