add: first curd

This commit is contained in:
vilet.yy 2021-03-24 11:29:15 +08:00
parent 2e78eff033
commit dfafd87235
13 changed files with 475 additions and 1508 deletions

View File

@ -10,23 +10,32 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
type CreateVendorRequest struct {
Name string `json:"name" binding:"required"`
Uuid int `json:"uuid"`
}
type UpdateVendorRequest struct {
Name string `json:"name"`
Uuid int `json:"uuid"`
}
// @Summary 系统厂商列表 // @Summary 系统厂商列表
// @Tags vendors // @Tags vendors
// @Description // @Description
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Authorization header string true "auth by /auth" // @Param Authorization header string true "auth by /auth"
// @Param data body models.VendorSearch true "页码, 每页大小, 搜索条件" // @Param name query string false "系统厂商名称"
// @Param page query int false "页码"
// @Param page_size query int false "每页数量"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /v1/vendors [get] // @Router /v1/vendors [get]
func GetVendors(c *gin.Context) { func GetVendors(c *gin.Context) {
var search basic.VendorSearch var search basic.VendorSearch
if err := c.ShouldBindJSON(&search); err != nil { search.Name = c.Query("name")
c.JSON(http.StatusBadRequest, gin.H{ search.Page, search.PageSize = utils.GetPageInfo(c)
"error": err.Error(),
})
}
if result, err := basic.GetVendors(&search); err != nil { if result, err := basic.GetVendors(&search); err != nil {
global.GO_LOG.Error("获取失败!", zap.Any("err", err)) global.GO_LOG.Error("获取失败!", zap.Any("err", err))
@ -42,17 +51,29 @@ func GetVendors(c *gin.Context) {
// @Accept mpfd // @Accept mpfd
// @Produce json // @Produce json
// @Param Authorization header string true "auth by /auth" // @Param Authorization header string true "auth by /auth"
// @Param data body basic.Vendor true "Vendor模型" // @Param data body CreateVendorRequest true "Vendor模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /v1/vendors [post] // @Router /v1/vendors [post]
func AddVendor(c *gin.Context) { func CreateVendor(c *gin.Context) {
var vendor basic.Vendor var vendor CreateVendorRequest
if err := c.ShouldBindJSON(&vendor); err != nil { if err := c.ShouldBindJSON(&vendor); err != nil {
c.JSON(http.StatusBadRequest, gin.H{ c.JSON(http.StatusBadRequest, gin.H{
"error": err.Error(), "error": err.Error(),
}) })
return
} }
if err := basic.CreateVendor(vendor); err != nil { if exist := basic.ExistVendorByName(vendor.Name); exist {
global.GO_LOG.Error("该系统厂商名称已存在!")
utils.FailWithMessage("该系统厂商名称已存在", c)
return
}
if exist := basic.ExistVendorByUuid(vendor.Uuid); exist {
global.GO_LOG.Error("该系统厂商uuid已存在!")
utils.FailWithMessage("该系统厂商uuid已存在", c)
return
}
if err := basic.CreateVendor(basic.Vendor{Name: vendor.Name, Uuid: vendor.Uuid}); err != nil {
global.GO_LOG.Error("创建失败!", zap.Any("err", err)) global.GO_LOG.Error("创建失败!", zap.Any("err", err))
utils.FailWithMessage("创建失败", c) utils.FailWithMessage("创建失败", c)
} else { } else {
@ -67,16 +88,35 @@ func AddVendor(c *gin.Context) {
// @Produce json // @Produce json
// @Param Authorization header string true "auth by /auth" // @Param Authorization header string true "auth by /auth"
// @Param id path int true "系统厂商 ID" // @Param id path int true "系统厂商 ID"
// @Param data body basic.Vendor true "Vendor模型" // @Param data body UpdateVendorRequest true "Vendor模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /v1/vendors/{id} [patch] // @Router /v1/vendors/{id} [patch]
func UpdateVendor(c *gin.Context) { func UpdateVendor(c *gin.Context) {
var vendor basic.Vendor vendor, gErr := basic.GetVendorById(c.Param("id"))
if gErr != nil {
global.GO_LOG.Error("系统厂商不存在!", zap.Any("err", gErr))
utils.FailWithMessage("系统厂商不存在!", c)
return
}
if err := c.ShouldBindJSON(&vendor); err != nil { if err := c.ShouldBindJSON(&vendor); err != nil {
c.JSON(http.StatusBadRequest, gin.H{ c.JSON(http.StatusBadRequest, gin.H{
"error": err.Error(), "error": err.Error(),
}) })
return
} }
if exist := basic.ExistVendorByName(vendor.Name); exist {
global.GO_LOG.Error("该系统厂商名称已存在!")
utils.FailWithMessage("该系统厂商名称已存在", c)
return
}
if exist := basic.ExistVendorByUuid(vendor.Uuid); exist {
global.GO_LOG.Error("该系统厂商uuid已存在!")
utils.FailWithMessage("该系统厂商uuid已存在", c)
return
}
if err := basic.UpdateVendor(&vendor); err != nil { if err := basic.UpdateVendor(&vendor); err != nil {
global.GO_LOG.Error("更新失败!", zap.Any("err", err)) global.GO_LOG.Error("更新失败!", zap.Any("err", err))
utils.FailWithMessage("更新失败", c) utils.FailWithMessage("更新失败", c)
@ -95,11 +135,11 @@ func UpdateVendor(c *gin.Context) {
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /v1/vendors/{id} [delete] // @Router /v1/vendors/{id} [delete]
func DeleteVendor(c *gin.Context) { func DeleteVendor(c *gin.Context) {
var vendor basic.Vendor vendor, gErr := basic.GetVendorById(c.Param("id"))
if err := c.ShouldBindJSON(&vendor); err != nil { if gErr != nil {
c.JSON(http.StatusBadRequest, gin.H{ global.GO_LOG.Error("系统厂商不存在!", zap.Any("err", gErr))
"error": err.Error(), utils.FailWithMessage("系统厂商不存在!", c)
}) return
} }
if err := basic.DeleteVendor(&vendor); err != nil { if err := basic.DeleteVendor(&vendor); err != nil {
global.GO_LOG.Error("删除失败!", zap.Any("err", err)) global.GO_LOG.Error("删除失败!", zap.Any("err", err))

View File

@ -1,7 +1,7 @@
/* /*
* @Date: 2021-03-21 19:54:57 * @Date: 2021-03-21 19:54:57
* @LastEditors: viletyy * @LastEditors: viletyy
* @LastEditTime: 2021-03-23 00:44:10 * @LastEditTime: 2021-03-24 10:08:27
* @FilePath: /potato/controller/api/v1/user.go * @FilePath: /potato/controller/api/v1/user.go
*/ */
package v1 package v1
@ -13,69 +13,92 @@ import (
"github.com/viletyy/potato/global" "github.com/viletyy/potato/global"
"github.com/viletyy/potato/models" "github.com/viletyy/potato/models"
"github.com/viletyy/potato/utils" "github.com/viletyy/potato/utils"
"github.com/viletyy/potato/utils/crypt"
"go.uber.org/zap" "go.uber.org/zap"
) )
type LoginResponse struct { type AuthResponse struct {
User models.User `json:"user"` User models.User `json:"user"`
Token string `json:"token"` Token string `json:"token"`
} }
type AuthRequest struct {
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required,gte=6`
}
type RegisterRequest struct {
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required,gte=6`
Nickname string `json:"nickname"`
}
// @Summary 用户验证 // @Summary 用户验证
// @Description // @Description
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param data body models.User true "User模型" // @Param data body AuthRequest true "用户名,密码"
// @Success 200 {string} json "{"code" : 200, "data" : {"token" : ""}, "msg" : "ok"}" // @Success 200 {string} json "{"code" : 200, "data" : {"token" : ""}, "msg" : "ok"}"
// @Router /v1/auth [get] // @Router /v1/auth [post]
func GetUserAuth(c *gin.Context) { func Auth(c *gin.Context) {
var user models.User var user AuthRequest
if err := c.ShouldBindJSON(&user); err != nil { if err := c.ShouldBindJSON(&user); err != nil {
c.JSON(http.StatusBadRequest, gin.H{ c.JSON(http.StatusBadRequest, gin.H{
"error": err.Error(), "error": err.Error(),
}) })
return
} }
mUser, gErr := models.GetUserByUsername(user.Username) mUser, gErr := models.GetUserByUsername(user.Username)
if gErr != nil { if gErr != nil {
global.GO_LOG.Error("查找用户失败", zap.Any("err", gErr)) global.GO_LOG.Error("查找用户失败", zap.Any("err", gErr))
utils.FailWithMessage("查找用户失败", c) utils.FailWithMessage("查找用户失败", c)
return
} }
isTrue := mUser.CheckPassword(user.Password) isTrue := mUser.CheckPassword(user.Password)
if !isTrue { if !isTrue {
global.GO_LOG.Error("用户密码不正确") global.GO_LOG.Error("用户密码不正确")
utils.FailWithMessage("用户密码不正确", c) utils.FailWithMessage("用户密码不正确", c)
return
} }
token, tokenErr := utils.GenerateToken(mUser.ID) token, tokenErr := utils.GenerateToken(mUser.ID)
if tokenErr != nil { if tokenErr != nil {
global.GO_LOG.Error("获取token失败", zap.Any("err", tokenErr)) global.GO_LOG.Error("获取token失败", zap.Any("err", tokenErr))
utils.FailWithMessage("获取token失败", c) utils.FailWithMessage("获取token失败", c)
return
} }
utils.OkWithDetailed(LoginResponse{ utils.OkWithDetailed(AuthResponse{
User: mUser, User: mUser,
Token: token, Token: token,
}, "登录成功", c) }, "登录成功", c)
} }
// @Summary 新增用户 // @Summary 注册用户
// @Tags users
// @Description // @Description
// @Accept mpfd // @Accept json
// @Produce json // @Produce json
// @Param data body basic.User true "User模型" // @Param data body RegisterRequest true "用户名"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /v1/users [post] // @Router /v1/register [post]
func AddUser(c *gin.Context) { func Register(c *gin.Context) {
var user models.User var user RegisterRequest
if err := c.ShouldBindJSON(&user); err != nil { if err := c.ShouldBindJSON(&user); err != nil {
c.JSON(http.StatusBadRequest, gin.H{ c.JSON(http.StatusBadRequest, gin.H{
"error": err.Error(), "error": err.Error(),
}) })
return
} }
if err := models.CreateUser(user); err != nil {
if isExsit := models.ExistUserByUsername(user.Username); isExsit {
global.GO_LOG.Error("用户已存在")
utils.FailWithMessage("用户已存在", c)
return
}
if err := models.CreateUser(models.User{Username: user.Username, Password: crypt.Md5Encode(user.Password), Nickname: user.Nickname}); err != nil {
global.GO_LOG.Error("创建失败!", zap.Any("err", err)) global.GO_LOG.Error("创建失败!", zap.Any("err", err))
utils.FailWithMessage("创建失败", c) utils.FailWithMessage("创建失败", c)
} else { } else {

View File

@ -25,7 +25,7 @@ var doc = `{
"basePath": "{{.BasePath}}", "basePath": "{{.BasePath}}",
"paths": { "paths": {
"/v1/auth": { "/v1/auth": {
"get": { "post": {
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -35,18 +35,13 @@ var doc = `{
"summary": "用户验证", "summary": "用户验证",
"parameters": [ "parameters": [
{ {
"type": "string", "description": "用户名,密码",
"description": "用户 用户名", "name": "data",
"name": "username", "in": "body",
"in": "query", "required": true,
"required": true "schema": {
}, "$ref": "#/definitions/v1.AuthRequest"
{ }
"type": "string",
"description": "用户 密码",
"name": "password",
"in": "query",
"required": true
} }
], ],
"responses": { "responses": {
@ -59,523 +54,29 @@ var doc = `{
} }
} }
}, },
"/v1/businesses": { "/v1/register": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"businesses"
],
"summary": "业务系统列表",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"data\" : {}, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
},
"post": { "post": {
"consumes": [ "consumes": [
"multipart/form-data" "application/json"
], ],
"produces": [ "produces": [
"application/json" "application/json"
], ],
"tags": [ "summary": "注册用户",
"businesses"
],
"summary": "新增业务系统",
"parameters": [ "parameters": [
{ {
"type": "string", "description": "用户名",
"description": "auth by /auth", "name": "data",
"name": "Authorization", "in": "body",
"in": "header", "required": true,
"required": true
},
{
"type": "string",
"description": "业务系统 名称",
"name": "name",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "业务系统 描述",
"name": "desc",
"in": "formData"
},
{
"type": "integer",
"description": "业务系统 云端id",
"name": "c_id",
"in": "formData"
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/v1.RegisterRequest"
} }
} }
}
}
},
"/v1/businesses/{id}": {
"delete": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"businesses"
],
"summary": "删除业务系统",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "integer",
"description": "业务系统 ID",
"name": "id",
"in": "path",
"required": true
}
], ],
"responses": { "responses": {
"200": { "200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}", "description": "{\"success\":true,\"data\":{},\"msg\":\"创建成功\"}",
"schema": {
"type": "string"
}
}
}
},
"patch": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"businesses"
],
"summary": "修改业务系统",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "integer",
"description": "业务系统 ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "业务系统 名称",
"name": "name",
"in": "formData"
},
{
"type": "string",
"description": "业务系统 描述",
"name": "desc",
"in": "formData"
},
{
"type": "string",
"description": "业务系统 云端id",
"name": "c_id",
"in": "formData"
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/meta_databases": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"meta_databases"
],
"summary": "数据源列表",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"basic\" : {}, \"msg\": \"ok\" }",
"schema": {
"type": "string"
}
}
}
},
"post": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"meta_databases"
],
"summary": "新增数据源",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "string",
"description": "数据源 名称",
"name": "name",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "数据源 地址",
"name": "host",
"in": "formData",
"required": true
},
{
"type": "integer",
"description": "数据源 端口号",
"name": "port",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "数据源 数据库名称",
"name": "db_name",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "数据源 用户名",
"name": "username",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "数据源 密码",
"name": "password",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "数据源 备注",
"name": "comment",
"in": "formData"
},
{
"type": "integer",
"description": "系统厂商 id",
"name": "vendor_id",
"in": "formData",
"required": true
},
{
"type": "integer",
"description": "业务系统 id",
"name": "business_id",
"in": "formData",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\": 200, data: {}, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/meta_databases/{id}": {
"delete": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"meta_databases"
],
"summary": "删除数据源",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "integer",
"description": "数据源 ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
},
"patch": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"meta_databases"
],
"summary": "修改数据源",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "integer",
"description": "数据源 ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "数据源 名称",
"name": "name",
"in": "formData"
},
{
"type": "string",
"description": "数据源 地址",
"name": "host",
"in": "formData"
},
{
"type": "integer",
"description": "数据源 端口号",
"name": "port",
"in": "formData"
},
{
"type": "string",
"description": "数据源 数据库名称",
"name": "db_name",
"in": "formData"
},
{
"type": "string",
"description": "数据源 用户名",
"name": "username",
"in": "formData"
},
{
"type": "string",
"description": "数据源 密码",
"name": "password",
"in": "formData"
},
{
"type": "string",
"description": "数据源 备注",
"name": "comment",
"in": "formData"
},
{
"type": "integer",
"description": "系统厂商 id",
"name": "vendor_id",
"in": "formData"
},
{
"type": "integer",
"description": "业务系统 id",
"name": "business_id",
"in": "formData"
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/meta_databases/{id}/meta_tables": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"meta_tables"
],
"summary": "元数据列表",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "integer",
"description": "数据源 ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"basic\" : {}, \"msg\": \"ok\" }",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/users": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"users"
],
"summary": "用户列表",
"responses": {
"200": {
"description": "{\"code\" : 200, \"data\" : {}, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
},
"post": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"users"
],
"summary": "新增用户",
"parameters": [
{
"type": "string",
"description": "用户 用户名",
"name": "username",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "用户 密码",
"name": "password",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "用户 真实姓名",
"name": "nickname",
"in": "formData",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, data: {}, \"msg\" : \"ok\"}",
"schema": { "schema": {
"type": "string" "type": "string"
} }
@ -602,11 +103,29 @@ var doc = `{
"name": "Authorization", "name": "Authorization",
"in": "header", "in": "header",
"required": true "required": true
},
{
"type": "string",
"description": "系统厂商名称",
"name": "name",
"in": "query"
},
{
"type": "integer",
"description": "页码",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "每页数量",
"name": "page_size",
"in": "query"
} }
], ],
"responses": { "responses": {
"200": { "200": {
"description": "{\"code\" : 200, \"data\" : {}, \"msg\" : \"ok\"}", "description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
"schema": { "schema": {
"type": "string" "type": "string"
} }
@ -633,22 +152,18 @@ var doc = `{
"required": true "required": true
}, },
{ {
"type": "string", "description": "Vendor模型",
"description": "系统厂商 名称", "name": "data",
"name": "name", "in": "body",
"in": "formData", "required": true,
"required": true "schema": {
}, "$ref": "#/definitions/basic.CreateVendorRequest"
{ }
"type": "integer",
"description": "系统厂商 云端id",
"name": "c_id",
"in": "formData"
} }
], ],
"responses": { "responses": {
"200": { "200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}", "description": "{\"success\":true,\"data\":{},\"msg\":\"创建成功\"}",
"schema": { "schema": {
"type": "string" "type": "string"
} }
@ -686,7 +201,7 @@ var doc = `{
], ],
"responses": { "responses": {
"200": { "200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}", "description": "{\"success\":true,\"data\":{},\"msg\":\"删除成功\"}",
"schema": { "schema": {
"type": "string" "type": "string"
} }
@ -720,21 +235,18 @@ var doc = `{
"required": true "required": true
}, },
{ {
"type": "string", "description": "Vendor模型",
"description": "系统厂商 名称", "name": "data",
"name": "name", "in": "body",
"in": "formData" "required": true,
}, "schema": {
{ "$ref": "#/definitions/basic.UpdateVendorRequest"
"type": "integer", }
"description": "系统厂商 云端id",
"name": "c_id",
"in": "formData"
} }
], ],
"responses": { "responses": {
"200": { "200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}", "description": "{\"success\":true,\"data\":{},\"msg\":\"更新成功\"}",
"schema": { "schema": {
"type": "string" "type": "string"
} }
@ -742,6 +254,64 @@ var doc = `{
} }
} }
} }
},
"definitions": {
"basic.CreateVendorRequest": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
},
"uuid": {
"type": "integer"
}
}
},
"basic.UpdateVendorRequest": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"uuid": {
"type": "integer"
}
}
},
"v1.AuthRequest": {
"type": "object",
"required": [
"username"
],
"properties": {
"password": {
"type": "string"
},
"username": {
"type": "string"
}
}
},
"v1.RegisterRequest": {
"type": "object",
"required": [
"username"
],
"properties": {
"nickname": {
"type": "string"
},
"password": {
"type": "string"
},
"username": {
"type": "string"
}
}
}
} }
}` }`

View File

@ -9,7 +9,7 @@
"basePath": "/api", "basePath": "/api",
"paths": { "paths": {
"/v1/auth": { "/v1/auth": {
"get": { "post": {
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -19,18 +19,13 @@
"summary": "用户验证", "summary": "用户验证",
"parameters": [ "parameters": [
{ {
"type": "string", "description": "用户名,密码",
"description": "用户 用户名", "name": "data",
"name": "username", "in": "body",
"in": "query", "required": true,
"required": true "schema": {
}, "$ref": "#/definitions/v1.AuthRequest"
{ }
"type": "string",
"description": "用户 密码",
"name": "password",
"in": "query",
"required": true
} }
], ],
"responses": { "responses": {
@ -43,523 +38,29 @@
} }
} }
}, },
"/v1/businesses": { "/v1/register": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"businesses"
],
"summary": "业务系统列表",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"data\" : {}, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
},
"post": { "post": {
"consumes": [ "consumes": [
"multipart/form-data" "application/json"
], ],
"produces": [ "produces": [
"application/json" "application/json"
], ],
"tags": [ "summary": "注册用户",
"businesses"
],
"summary": "新增业务系统",
"parameters": [ "parameters": [
{ {
"type": "string", "description": "用户名",
"description": "auth by /auth", "name": "data",
"name": "Authorization", "in": "body",
"in": "header", "required": true,
"required": true
},
{
"type": "string",
"description": "业务系统 名称",
"name": "name",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "业务系统 描述",
"name": "desc",
"in": "formData"
},
{
"type": "integer",
"description": "业务系统 云端id",
"name": "c_id",
"in": "formData"
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/v1.RegisterRequest"
} }
} }
}
}
},
"/v1/businesses/{id}": {
"delete": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"businesses"
],
"summary": "删除业务系统",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "integer",
"description": "业务系统 ID",
"name": "id",
"in": "path",
"required": true
}
], ],
"responses": { "responses": {
"200": { "200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}", "description": "{\"success\":true,\"data\":{},\"msg\":\"创建成功\"}",
"schema": {
"type": "string"
}
}
}
},
"patch": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"businesses"
],
"summary": "修改业务系统",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "integer",
"description": "业务系统 ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "业务系统 名称",
"name": "name",
"in": "formData"
},
{
"type": "string",
"description": "业务系统 描述",
"name": "desc",
"in": "formData"
},
{
"type": "string",
"description": "业务系统 云端id",
"name": "c_id",
"in": "formData"
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/meta_databases": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"meta_databases"
],
"summary": "数据源列表",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"basic\" : {}, \"msg\": \"ok\" }",
"schema": {
"type": "string"
}
}
}
},
"post": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"meta_databases"
],
"summary": "新增数据源",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "string",
"description": "数据源 名称",
"name": "name",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "数据源 地址",
"name": "host",
"in": "formData",
"required": true
},
{
"type": "integer",
"description": "数据源 端口号",
"name": "port",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "数据源 数据库名称",
"name": "db_name",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "数据源 用户名",
"name": "username",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "数据源 密码",
"name": "password",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "数据源 备注",
"name": "comment",
"in": "formData"
},
{
"type": "integer",
"description": "系统厂商 id",
"name": "vendor_id",
"in": "formData",
"required": true
},
{
"type": "integer",
"description": "业务系统 id",
"name": "business_id",
"in": "formData",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\": 200, data: {}, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/meta_databases/{id}": {
"delete": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"meta_databases"
],
"summary": "删除数据源",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "integer",
"description": "数据源 ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
},
"patch": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"meta_databases"
],
"summary": "修改数据源",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "integer",
"description": "数据源 ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "数据源 名称",
"name": "name",
"in": "formData"
},
{
"type": "string",
"description": "数据源 地址",
"name": "host",
"in": "formData"
},
{
"type": "integer",
"description": "数据源 端口号",
"name": "port",
"in": "formData"
},
{
"type": "string",
"description": "数据源 数据库名称",
"name": "db_name",
"in": "formData"
},
{
"type": "string",
"description": "数据源 用户名",
"name": "username",
"in": "formData"
},
{
"type": "string",
"description": "数据源 密码",
"name": "password",
"in": "formData"
},
{
"type": "string",
"description": "数据源 备注",
"name": "comment",
"in": "formData"
},
{
"type": "integer",
"description": "系统厂商 id",
"name": "vendor_id",
"in": "formData"
},
{
"type": "integer",
"description": "业务系统 id",
"name": "business_id",
"in": "formData"
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/meta_databases/{id}/meta_tables": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"meta_tables"
],
"summary": "元数据列表",
"parameters": [
{
"type": "string",
"description": "auth by /auth",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "integer",
"description": "数据源 ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"basic\" : {}, \"msg\": \"ok\" }",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/users": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"users"
],
"summary": "用户列表",
"responses": {
"200": {
"description": "{\"code\" : 200, \"data\" : {}, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
},
"post": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"users"
],
"summary": "新增用户",
"parameters": [
{
"type": "string",
"description": "用户 用户名",
"name": "username",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "用户 密码",
"name": "password",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "用户 真实姓名",
"name": "nickname",
"in": "formData",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, data: {}, \"msg\" : \"ok\"}",
"schema": { "schema": {
"type": "string" "type": "string"
} }
@ -586,11 +87,29 @@
"name": "Authorization", "name": "Authorization",
"in": "header", "in": "header",
"required": true "required": true
},
{
"type": "string",
"description": "系统厂商名称",
"name": "name",
"in": "query"
},
{
"type": "integer",
"description": "页码",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "每页数量",
"name": "page_size",
"in": "query"
} }
], ],
"responses": { "responses": {
"200": { "200": {
"description": "{\"code\" : 200, \"data\" : {}, \"msg\" : \"ok\"}", "description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
"schema": { "schema": {
"type": "string" "type": "string"
} }
@ -617,22 +136,18 @@
"required": true "required": true
}, },
{ {
"type": "string", "description": "Vendor模型",
"description": "系统厂商 名称", "name": "data",
"name": "name", "in": "body",
"in": "formData", "required": true,
"required": true "schema": {
}, "$ref": "#/definitions/basic.CreateVendorRequest"
{ }
"type": "integer",
"description": "系统厂商 云端id",
"name": "c_id",
"in": "formData"
} }
], ],
"responses": { "responses": {
"200": { "200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}", "description": "{\"success\":true,\"data\":{},\"msg\":\"创建成功\"}",
"schema": { "schema": {
"type": "string" "type": "string"
} }
@ -670,7 +185,7 @@
], ],
"responses": { "responses": {
"200": { "200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}", "description": "{\"success\":true,\"data\":{},\"msg\":\"删除成功\"}",
"schema": { "schema": {
"type": "string" "type": "string"
} }
@ -704,21 +219,18 @@
"required": true "required": true
}, },
{ {
"type": "string", "description": "Vendor模型",
"description": "系统厂商 名称", "name": "data",
"name": "name", "in": "body",
"in": "formData" "required": true,
}, "schema": {
{ "$ref": "#/definitions/basic.UpdateVendorRequest"
"type": "integer", }
"description": "系统厂商 云端id",
"name": "c_id",
"in": "formData"
} }
], ],
"responses": { "responses": {
"200": { "200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}", "description": "{\"success\":true,\"data\":{},\"msg\":\"更新成功\"}",
"schema": { "schema": {
"type": "string" "type": "string"
} }
@ -726,5 +238,63 @@
} }
} }
} }
},
"definitions": {
"basic.CreateVendorRequest": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
},
"uuid": {
"type": "integer"
}
}
},
"basic.UpdateVendorRequest": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"uuid": {
"type": "integer"
}
}
},
"v1.AuthRequest": {
"type": "object",
"required": [
"username"
],
"properties": {
"password": {
"type": "string"
},
"username": {
"type": "string"
}
}
},
"v1.RegisterRequest": {
"type": "object",
"required": [
"username"
],
"properties": {
"nickname": {
"type": "string"
},
"password": {
"type": "string"
},
"username": {
"type": "string"
}
}
}
} }
} }

View File

@ -1,4 +1,41 @@
basePath: /api basePath: /api
definitions:
basic.CreateVendorRequest:
properties:
name:
type: string
uuid:
type: integer
required:
- name
type: object
basic.UpdateVendorRequest:
properties:
name:
type: string
uuid:
type: integer
type: object
v1.AuthRequest:
properties:
password:
type: string
username:
type: string
required:
- username
type: object
v1.RegisterRequest:
properties:
nickname:
type: string
password:
type: string
username:
type: string
required:
- username
type: object
info: info:
contact: {} contact: {}
description: This is a data_govern use golang description: This is a data_govern use golang
@ -6,20 +43,16 @@ info:
version: "1.0" version: "1.0"
paths: paths:
/v1/auth: /v1/auth:
get: post:
consumes: consumes:
- application/json - application/json
parameters: parameters:
- description: 用户 用户 - description: 用户,密码
in: query in: body
name: username name: data
required: true required: true
type: string schema:
- description: 用户 密码 $ref: '#/definitions/v1.AuthRequest'
in: query
name: password
required: true
type: string
produces: produces:
- application/json - application/json
responses: responses:
@ -28,355 +61,25 @@ paths:
schema: schema:
type: string type: string
summary: 用户验证 summary: 用户验证
/v1/businesses: /v1/register:
get:
consumes:
- application/json
parameters:
- description: auth by /auth
in: header
name: Authorization
required: true
type: string
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "data" : {}, "msg" : "ok"}'
schema:
type: string
summary: 业务系统列表
tags:
- businesses
post: post:
consumes:
- multipart/form-data
parameters:
- description: auth by /auth
in: header
name: Authorization
required: true
type: string
- description: 业务系统 名称
in: formData
name: name
required: true
type: string
- description: 业务系统 描述
in: formData
name: desc
type: string
- description: 业务系统 云端id
in: formData
name: c_id
type: integer
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "msg" : "ok"}'
schema:
type: string
summary: 新增业务系统
tags:
- businesses
/v1/businesses/{id}:
delete:
consumes: consumes:
- application/json - application/json
parameters: parameters:
- description: auth by /auth - description: 用户名
in: header in: body
name: Authorization name: data
required: true required: true
type: string schema:
- description: 业务系统 ID $ref: '#/definitions/v1.RegisterRequest'
in: path
name: id
required: true
type: integer
produces: produces:
- application/json - application/json
responses: responses:
"200": "200":
description: '{"code" : 200, "msg" : "ok"}' description: '{"success":true,"data":{},"msg":"创建成功"}'
schema: schema:
type: string type: string
summary: 删除业务系统 summary: 注册用户
tags:
- businesses
patch:
consumes:
- multipart/form-data
parameters:
- description: auth by /auth
in: header
name: Authorization
required: true
type: string
- description: 业务系统 ID
in: path
name: id
required: true
type: integer
- description: 业务系统 名称
in: formData
name: name
type: string
- description: 业务系统 描述
in: formData
name: desc
type: string
- description: 业务系统 云端id
in: formData
name: c_id
type: string
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "msg" : "ok"}'
schema:
type: string
summary: 修改业务系统
tags:
- businesses
/v1/meta_databases:
get:
consumes:
- application/json
parameters:
- description: auth by /auth
in: header
name: Authorization
required: true
type: string
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "basic" : {}, "msg": "ok" }'
schema:
type: string
summary: 数据源列表
tags:
- meta_databases
post:
consumes:
- multipart/form-data
parameters:
- description: auth by /auth
in: header
name: Authorization
required: true
type: string
- description: 数据源 名称
in: formData
name: name
required: true
type: string
- description: 数据源 地址
in: formData
name: host
required: true
type: string
- description: 数据源 端口号
in: formData
name: port
required: true
type: integer
- description: 数据源 数据库名称
in: formData
name: db_name
required: true
type: string
- description: 数据源 用户名
in: formData
name: username
required: true
type: string
- description: 数据源 密码
in: formData
name: password
required: true
type: string
- description: 数据源 备注
in: formData
name: comment
type: string
- description: 系统厂商 id
in: formData
name: vendor_id
required: true
type: integer
- description: 业务系统 id
in: formData
name: business_id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: '{"code": 200, data: {}, "msg" : "ok"}'
schema:
type: string
summary: 新增数据源
tags:
- meta_databases
/v1/meta_databases/{id}:
delete:
consumes:
- application/json
parameters:
- description: auth by /auth
in: header
name: Authorization
required: true
type: string
- description: 数据源 ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "msg" : "ok"}'
schema:
type: string
summary: 删除数据源
tags:
- meta_databases
patch:
consumes:
- multipart/form-data
parameters:
- description: auth by /auth
in: header
name: Authorization
required: true
type: string
- description: 数据源 ID
in: path
name: id
required: true
type: integer
- description: 数据源 名称
in: formData
name: name
type: string
- description: 数据源 地址
in: formData
name: host
type: string
- description: 数据源 端口号
in: formData
name: port
type: integer
- description: 数据源 数据库名称
in: formData
name: db_name
type: string
- description: 数据源 用户名
in: formData
name: username
type: string
- description: 数据源 密码
in: formData
name: password
type: string
- description: 数据源 备注
in: formData
name: comment
type: string
- description: 系统厂商 id
in: formData
name: vendor_id
type: integer
- description: 业务系统 id
in: formData
name: business_id
type: integer
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "msg" : "ok"}'
schema:
type: string
summary: 修改数据源
tags:
- meta_databases
/v1/meta_databases/{id}/meta_tables:
get:
consumes:
- application/json
parameters:
- description: auth by /auth
in: header
name: Authorization
required: true
type: string
- description: 数据源 ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "basic" : {}, "msg": "ok" }'
schema:
type: string
summary: 元数据列表
tags:
- meta_tables
/v1/users:
get:
consumes:
- application/json
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "data" : {}, "msg" : "ok"}'
schema:
type: string
summary: 用户列表
tags:
- users
post:
consumes:
- multipart/form-data
parameters:
- description: 用户 用户名
in: formData
name: username
required: true
type: string
- description: 用户 密码
in: formData
name: password
required: true
type: string
- description: 用户 真实姓名
in: formData
name: nickname
required: true
type: string
produces:
- application/json
responses:
"200":
description: '{"code" : 200, data: {}, "msg" : "ok"}'
schema:
type: string
summary: 新增用户
tags:
- users
/v1/vendors: /v1/vendors:
get: get:
consumes: consumes:
@ -387,11 +90,23 @@ paths:
name: Authorization name: Authorization
required: true required: true
type: string type: string
- description: 系统厂商名称
in: query
name: name
type: string
- description: 页码
in: query
name: page
type: integer
- description: 每页数量
in: query
name: page_size
type: integer
produces: produces:
- application/json - application/json
responses: responses:
"200": "200":
description: '{"code" : 200, "data" : {}, "msg" : "ok"}' description: '{"success":true,"data":{},"msg":"获取成功"}'
schema: schema:
type: string type: string
summary: 系统厂商列表 summary: 系统厂商列表
@ -406,20 +121,17 @@ paths:
name: Authorization name: Authorization
required: true required: true
type: string type: string
- description: 系统厂商 名称 - description: Vendor模型
in: formData in: body
name: name name: data
required: true required: true
type: string schema:
- description: 系统厂商 云端id $ref: '#/definitions/basic.CreateVendorRequest'
in: formData
name: c_id
type: integer
produces: produces:
- application/json - application/json
responses: responses:
"200": "200":
description: '{"code" : 200, "msg" : "ok"}' description: '{"success":true,"data":{},"msg":"创建成功"}'
schema: schema:
type: string type: string
summary: 新增系统厂商 summary: 新增系统厂商
@ -444,7 +156,7 @@ paths:
- application/json - application/json
responses: responses:
"200": "200":
description: '{"code" : 200, "msg" : "ok"}' description: '{"success":true,"data":{},"msg":"删除成功"}'
schema: schema:
type: string type: string
summary: 删除系统厂商 summary: 删除系统厂商
@ -464,19 +176,17 @@ paths:
name: id name: id
required: true required: true
type: integer type: integer
- description: 系统厂商 名称 - description: Vendor模型
in: formData in: body
name: name name: data
type: string required: true
- description: 系统厂商 云端id schema:
in: formData $ref: '#/definitions/basic.UpdateVendorRequest'
name: c_id
type: integer
produces: produces:
- application/json - application/json
responses: responses:
"200": "200":
description: '{"code" : 200, "msg" : "ok"}' description: '{"success":true,"data":{},"msg":"更新成功"}'
schema: schema:
type: string type: string
summary: 修改系统厂商 summary: 修改系统厂商

View File

@ -1,7 +1,7 @@
/* /*
* @Date: 2021-03-21 19:54:57 * @Date: 2021-03-21 19:54:57
* @LastEditors: viletyy * @LastEditors: viletyy
* @LastEditTime: 2021-03-23 00:50:00 * @LastEditTime: 2021-03-24 11:05:16
* @FilePath: /potato/middleware/jwt.go * @FilePath: /potato/middleware/jwt.go
*/ */
package middleware package middleware
@ -24,6 +24,7 @@ func JWT() gin.HandlerFunc {
"error": "请求参数错误", "error": "请求参数错误",
}) })
c.Abort() c.Abort()
return
} else { } else {
claims, err := utils.ParseToken(token) claims, err := utils.ParseToken(token)
if err != nil { if err != nil {
@ -31,11 +32,13 @@ func JWT() gin.HandlerFunc {
"error": "token验证失败", "error": "token验证失败",
}) })
c.Abort() c.Abort()
return
} else if time.Now().Unix() > claims.ExpiresAt { } else if time.Now().Unix() > claims.ExpiresAt {
c.JSON(http.StatusBadRequest, gin.H{ c.JSON(http.StatusBadRequest, gin.H{
"error": "token已超时", "error": "token已超时",
}) })
c.Abort() c.Abort()
return
} }
if claims != nil { if claims != nil {
userId := claims.UserId userId := claims.UserId
@ -46,12 +49,14 @@ func JWT() gin.HandlerFunc {
"error": "token鉴权失败", "error": "token鉴权失败",
}) })
c.Abort() c.Abort()
return
} }
} else { } else {
c.JSON(http.StatusBadRequest, gin.H{ c.JSON(http.StatusBadRequest, gin.H{
"error": "token鉴权失败", "error": "token鉴权失败",
}) })
c.Abort() c.Abort()
return
} }
} }

View File

@ -19,7 +19,7 @@ type BusinessSearch struct {
type Business struct { type Business struct {
global.Model global.Model
Name string `json:"name" binding:"required"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
Uuid int `json:"uuid"` Uuid int `json:"uuid"`
} }

View File

@ -1,7 +1,7 @@
/* /*
* @Date: 2021-03-21 19:54:57 * @Date: 2021-03-21 19:54:57
* @LastEditors: viletyy * @LastEditors: viletyy
* @LastEditTime: 2021-03-22 23:54:39 * @LastEditTime: 2021-03-24 11:10:19
* @FilePath: /potato/models/basic/meta_database.go * @FilePath: /potato/models/basic/meta_database.go
*/ */
package basic package basic
@ -20,18 +20,18 @@ type MetaDatabaseSearch struct {
type MetaDatabase struct { type MetaDatabase struct {
global.Model global.Model
Name string `json:"name" binding:"required"` Name string `json:"name"`
Adapter string `json:"adapter" binding:"required"` Adapter string `json:"adapter"`
Host string `json:"host" binding:"required"` Host string `json:"host"`
Port string `json:"port" binding:"required"` Port string `json:"port"`
DbName string `json:"db_name" binding:"required"` DbName string `json:"db_name"`
Username string `json:"username" binding:"required"` Username string `json:"username"`
Password string `json:"password" binding:"required"` Password string `json:"password"`
LastConnectTime time.Time `json:"last_connect_time"` LastConnectTime time.Time `json:"last_connect_time"`
Usable bool `json:"usable"` Usable bool `json:"usable"`
Comment string `json:"comment"` Comment string `json:"comment"`
VendorId int64 `json:"vendor_id" binding:"required"` VendorId int64 `json:"vendor_id"`
BusinessId int64 `json:"business_id" binding:"required"` BusinessId int64 `json:"business_id"`
Vendor Vendor Vendor Vendor
Business Business Business Business
} }

View File

@ -1,7 +1,7 @@
/* /*
* @Date: 2021-03-21 19:54:57 * @Date: 2021-03-21 19:54:57
* @LastEditors: viletyy * @LastEditors: viletyy
* @LastEditTime: 2021-03-22 23:52:13 * @LastEditTime: 2021-03-24 11:16:27
* @FilePath: /potato/models/basic/vendor.go * @FilePath: /potato/models/basic/vendor.go
*/ */
package basic package basic
@ -19,15 +19,15 @@ type VendorSearch struct {
type Vendor struct { type Vendor struct {
global.Model global.Model
Name string `json:"name" binding:"require"` Name string `json:"name"`
Uuid int `json:"uuid"` Uuid int `json:"uuid"`
} }
func GetVendors(search *VendorSearch) (searchResult utils.SearchResult, err error) { func GetVendors(search *VendorSearch) (searchResult utils.SearchResult, err error) {
var vendors []Vendor var vendors []Vendor
offset := search.PageInfo.PageSize * (search.PageInfo.Page - 1) offset := search.PageInfo.PageSize * (search.PageInfo.Page - 1)
limit := search.PageInfo.Page limit := search.PageInfo.PageSize
db := global.GO_DB.Where(search.Vendor) db := global.GO_DB.Model(&Vendor{}).Where(search.Vendor)
err = db.Count(&searchResult.Total).Error err = db.Count(&searchResult.Total).Error
if err != nil { if err != nil {
return return
@ -42,7 +42,7 @@ func GetVendors(search *VendorSearch) (searchResult utils.SearchResult, err erro
return return
} }
func GetVendorById(id int) (vendor Vendor, err error) { func GetVendorById(id interface{}) (vendor Vendor, err error) {
err = global.GO_DB.Where("id = ?", id).First(&vendor).Error err = global.GO_DB.Where("id = ?", id).First(&vendor).Error
return return
} }
@ -52,12 +52,12 @@ func GetVendorByName(name string) (vendor Vendor, err error) {
return return
} }
func GetVendorByUuid(uuid int64) (vendor Vendor, err error) { func GetVendorByUuid(uuid interface{}) (vendor Vendor, err error) {
err = global.GO_DB.Where("uuid = ?", uuid).First(&vendor).Error err = global.GO_DB.Where("uuid = ?", uuid).First(&vendor).Error
return return
} }
func ExistVendorById(id int) bool { func ExistVendorById(id interface{}) bool {
var vendor Vendor var vendor Vendor
global.GO_DB.Where("id = ?", id).First(&vendor) global.GO_DB.Where("id = ?", id).First(&vendor)
@ -71,7 +71,7 @@ func ExistVendorByName(name string) bool {
return vendor.ID > 0 return vendor.ID > 0
} }
func ExistVendorByUuid(uuid int64) bool { func ExistVendorByUuid(uuid interface{}) bool {
var vendor Vendor var vendor Vendor
global.GO_DB.Where("uuid = ?", uuid).First(&vendor) global.GO_DB.Where("uuid = ?", uuid).First(&vendor)

View File

@ -1,7 +1,7 @@
/* /*
* @Date: 2021-03-21 19:54:57 * @Date: 2021-03-21 19:54:57
* @LastEditors: viletyy * @LastEditors: viletyy
* @LastEditTime: 2021-03-23 00:50:38 * @LastEditTime: 2021-03-24 11:23:01
* @FilePath: /potato/routers/basic.go * @FilePath: /potato/routers/basic.go
*/ */
package routers package routers
@ -22,7 +22,7 @@ func V1InitBasicRouter() {
vendors := V1RouterGroup.Group("/vendors") vendors := V1RouterGroup.Group("/vendors")
{ {
vendors.GET("", basic.GetVendors) vendors.GET("", basic.GetVendors)
vendors.POST("", basic.AddVendor) vendors.POST("", basic.CreateVendor)
vendors.PATCH("/:id", basic.UpdateVendor) vendors.PATCH("/:id", basic.UpdateVendor)
vendors.DELETE("/:id", basic.DeleteVendor) vendors.DELETE("/:id", basic.DeleteVendor)
} }

View File

@ -1,7 +1,7 @@
/* /*
* @Date: 2021-03-21 19:54:57 * @Date: 2021-03-21 19:54:57
* @LastEditors: viletyy * @LastEditors: viletyy
* @LastEditTime: 2021-03-23 00:50:54 * @LastEditTime: 2021-03-23 14:39:19
* @FilePath: /potato/routers/router.go * @FilePath: /potato/routers/router.go
*/ */
package routers package routers
@ -32,7 +32,8 @@ func InitRouter() *gin.Engine {
Engine.Use(middleware.CORS()) Engine.Use(middleware.CORS())
Engine.GET("/api/v1/auth", v1.GetUserAuth) Engine.POST("/api/v1/auth", v1.Auth)
Engine.POST("/api/v1/register", v1.Register)
Engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) Engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
V1InitModule() V1InitModule()
@ -42,7 +43,5 @@ func InitRouter() *gin.Engine {
func V1InitModule() { func V1InitModule() {
V1RouterGroup.Use(middleware.JWT()) V1RouterGroup.Use(middleware.JWT())
users := V1RouterGroup.Group("users")
users.POST("", v1.AddUser)
V1InitBasicRouter() V1InitBasicRouter()
} }

35
utils/helper.go Normal file
View File

@ -0,0 +1,35 @@
/*
* @Date: 2021-03-24 10:18:40
* @LastEditors: viletyy
* @LastEditTime: 2021-03-24 10:30:27
* @FilePath: /potato/utils/helper.go
*/
package utils
import "strconv"
func ToString(i interface{}) string {
switch i.(type) {
case string:
return i.(string)
case int:
return strconv.Itoa(i.(int))
case int64:
return strconv.FormatInt(i.(int64), 10)
}
return ""
}
func ToInt(i interface{}) int {
switch i.(type) {
case string:
result, err := strconv.Atoi(i.(string))
if err != nil {
return 0
}
return result
case int64:
return int(i.(int64))
}
return 0
}

15
utils/paginator.go Normal file
View File

@ -0,0 +1,15 @@
/*
* @Date: 2021-03-24 10:12:24
* @LastEditors: viletyy
* @LastEditTime: 2021-03-24 10:30:58
* @FilePath: /potato/utils/paginator.go
*/
package utils
import "github.com/gin-gonic/gin"
func GetPageInfo(c *gin.Context) (page, pageSize int) {
page = ToInt(c.DefaultQuery("page", "1"))
pageSize = ToInt(c.DefaultQuery("page_size", "10"))
return
}