correct all comments of functions in service
This commit is contained in:
+38
-34
@@ -9,54 +9,56 @@ import (
|
||||
|
||||
// @title CreateApi
|
||||
// @description create base apis, 新增基础api
|
||||
// @auth (2020/04/05 20:22 )
|
||||
// @param FileMd5 string
|
||||
// @param FileName string
|
||||
// @param FilePath string
|
||||
// @auth (2020/04/05 20:22)
|
||||
// @param api model.SysApi
|
||||
// @return error
|
||||
func CreateApi(a model.SysApi) (err error) {
|
||||
findOne := global.GVA_DB.Where("path = ? AND method = ?", a.Path, a.Method).Find(&model.SysApi{}).Error
|
||||
func CreateApi(api model.SysApi) (err error) {
|
||||
findOne := global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).Find(&model.SysApi{}).Error
|
||||
if findOne == nil {
|
||||
return errors.New("存在相同api")
|
||||
} else {
|
||||
err = global.GVA_DB.Create(&a).Error
|
||||
err = global.GVA_DB.Create(&api).Error
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// @title DeleteApi
|
||||
// @description delete base apis, 删除基础api
|
||||
// @auth (2020/04/05 20:22 )
|
||||
// @description delete a base api, 删除基础api
|
||||
// @param api model.SysApi
|
||||
// @auth (2020/04/05 20:22)
|
||||
// @return error
|
||||
func DeleteApi(a model.SysApi) (err error) {
|
||||
err = global.GVA_DB.Delete(a).Error
|
||||
ClearCasbin(1, a.Path, a.Method)
|
||||
func DeleteApi(api model.SysApi) (err error) {
|
||||
err = global.GVA_DB.Delete(api).Error
|
||||
ClearCasbin(1, api.Path, api.Method)
|
||||
return err
|
||||
}
|
||||
|
||||
// @title GetInfoList
|
||||
// @description get apis by pagination, 分页获取数据
|
||||
// @auth (2020/04/05 20:22 )
|
||||
// @param info PageInfo
|
||||
// @auth (2020/04/05 20:22)
|
||||
// @param api model.SysApi
|
||||
// @param info request.PageInfo
|
||||
// @param order string
|
||||
// @param desc bool
|
||||
// @return err error
|
||||
// @return list interface{}
|
||||
// @return total int
|
||||
func GetAPIInfoList(a model.SysApi, info request.PageInfo, Order string, Desc bool) (err error, list interface{}, total int) {
|
||||
func GetAPIInfoList(api model.SysApi, info request.PageInfo, order string, desc bool) (err error, list interface{}, total int) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
db := global.GVA_DB
|
||||
var apiList []model.SysApi
|
||||
|
||||
if a.Path != "" {
|
||||
db = db.Where("path LIKE ?", "%"+a.Path+"%")
|
||||
if api.Path != "" {
|
||||
db = db.Where("path LIKE ?", "%"+api.Path+"%")
|
||||
}
|
||||
|
||||
if a.Description != "" {
|
||||
db = db.Where("description LIKE ?", "%"+a.Description+"%")
|
||||
if api.Description != "" {
|
||||
db = db.Where("description LIKE ?", "%"+api.Description+"%")
|
||||
}
|
||||
|
||||
if a.Method != "" {
|
||||
db = db.Where("method = ?", a.Method)
|
||||
if api.Method != "" {
|
||||
db = db.Where("method = ?", api.Method)
|
||||
}
|
||||
|
||||
err = db.Find(&apiList).Count(&total).Error
|
||||
@@ -65,12 +67,12 @@ func GetAPIInfoList(a model.SysApi, info request.PageInfo, Order string, Desc bo
|
||||
return err, apiList, total
|
||||
} else {
|
||||
db = db.Limit(limit).Offset(offset)
|
||||
if Order != "" {
|
||||
if order != "" {
|
||||
var OrderStr string
|
||||
if Desc {
|
||||
OrderStr = Order + " desc"
|
||||
if desc {
|
||||
OrderStr = order + " desc"
|
||||
} else {
|
||||
OrderStr = Order
|
||||
OrderStr = order
|
||||
}
|
||||
err = db.Order(OrderStr, true).Find(&apiList).Error
|
||||
} else {
|
||||
@@ -82,7 +84,7 @@ func GetAPIInfoList(a model.SysApi, info request.PageInfo, Order string, Desc bo
|
||||
|
||||
// @title GetAllApis
|
||||
// @description get all apis, 获取所有的api
|
||||
// @auth (2020/04/05 20:22 )
|
||||
// @auth (2020/04/05 20:22)
|
||||
// @return err error
|
||||
// @return apis []SysApi
|
||||
func GetAllApis() (err error, apis []model.SysApi) {
|
||||
@@ -92,7 +94,8 @@ func GetAllApis() (err error, apis []model.SysApi) {
|
||||
|
||||
// @title GetApiById
|
||||
// @description 根据id获取api
|
||||
// @auth (2020/04/05 20:22 )
|
||||
// @auth (2020/04/05 20:22)
|
||||
// @param api model.SysApi
|
||||
// @param id float64
|
||||
// @return error
|
||||
func GetApiById(id float64) (err error, api model.SysApi) {
|
||||
@@ -102,15 +105,16 @@ func GetApiById(id float64) (err error, api model.SysApi) {
|
||||
|
||||
// @title UpdateApi
|
||||
// @description update a base api, update api
|
||||
// @auth (2020/04/05 20:22 )
|
||||
// @auth (2020/04/05 20:22)
|
||||
// @param api model.SysApi
|
||||
// @return error
|
||||
func UpdateApi(a model.SysApi) (err error) {
|
||||
func UpdateApi(api model.SysApi) (err error) {
|
||||
var oldA model.SysApi
|
||||
|
||||
err = global.GVA_DB.Where("id = ?", a.ID).First(&oldA).Error
|
||||
err = global.GVA_DB.Where("id = ?", api.ID).First(&oldA).Error
|
||||
|
||||
if oldA.Path != a.Path || oldA.Method != a.Method {
|
||||
flag := global.GVA_DB.Where("path = ? AND method = ?", a.Path, a.Method).Find(&model.SysApi{}).RecordNotFound()
|
||||
if oldA.Path != api.Path || oldA.Method != api.Method {
|
||||
flag := global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).Find(&model.SysApi{}).RecordNotFound()
|
||||
if !flag {
|
||||
return errors.New("存在相同api路径")
|
||||
}
|
||||
@@ -118,11 +122,11 @@ func UpdateApi(a model.SysApi) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
err = UpdateCasbinApi(oldA.Path, a.Path, oldA.Method, a.Method)
|
||||
err = UpdateCasbinApi(oldA.Path, api.Path, oldA.Method, api.Method)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
err = global.GVA_DB.Save(a).Error
|
||||
err = global.GVA_DB.Save(api).Error
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user