自动填充API功能不再需要手动清理垃圾数据

This commit is contained in:
pixel
2020-11-06 14:42:26 +08:00
parent 0a4e81138a
commit 2f97f4b979
6 changed files with 42 additions and 29 deletions
+22
View File
@@ -34,6 +34,28 @@ func DeleteApi(api model.SysApi) (err error) {
return err
}
// @title AutoCreateApi
// @description delete a base api by path and method, 删除基础api
// @param api model.SysApi
// @auth (2020/04/05 20:22)
// @return error
func AutoCreateApi(api model.SysApi) (err error) {
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
var fApi model.SysApi
var txErr error
fxErr := tx.Where("path = ? AND method = ?", api.Path, api.Method).First(&fApi).Error
if errors.Is(fxErr, gorm.ErrRecordNotFound) {
txErr = tx.Create(&api).Error
if txErr != nil{
return txErr
}
}
return nil
})
return err
}
// @title GetInfoList
// @description get apis by pagination, 分页获取数据
// @auth (2020/04/05 20:22)