API增删改查忘词嗯
This commit is contained in:
@@ -16,7 +16,7 @@ type Api struct {
|
||||
|
||||
func (a *Api) CreateApi() (err error) {
|
||||
findOne := qmsql.DEFAULTDB.Where("path = ?", a.Path).Find(&Menu{}).Error
|
||||
if findOne != nil {
|
||||
if findOne == nil {
|
||||
return errors.New("存在相同api")
|
||||
} else {
|
||||
err = qmsql.DEFAULTDB.Create(a).Error
|
||||
@@ -29,11 +29,16 @@ func (a *Api) DeleteApi() (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *Api) EditApi() (err error) {
|
||||
err = qmsql.DEFAULTDB.Update(a).Error
|
||||
func (a *Api) UpdataApi() (err error) {
|
||||
err = qmsql.DEFAULTDB.Save(a).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *Api) GetApiById(id float64)(err error,api Api){
|
||||
err = qmsql.DEFAULTDB.Where("id = ?",id).First(&api).Error
|
||||
return
|
||||
}
|
||||
|
||||
// 分页获取数据 需要分页实现这个接口即可
|
||||
func (a *Api) GetInfoList(info modelInterface.PageInfo) (err error, list interface{}, total int) {
|
||||
// 封装分页方法 调用即可 传入 当前的结构体和分页信息
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package dbModel
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/jinzhu/gorm"
|
||||
"main/init/qmsql"
|
||||
)
|
||||
@@ -10,15 +9,15 @@ type ApiAuthority struct {
|
||||
gorm.Model
|
||||
AuthorityId string
|
||||
Authority Authority `gorm:"ForeignKey:AuthorityId;AssociationForeignKey:AuthorityId"` //其实没有关联的必要
|
||||
ApiId string
|
||||
ApiId uint
|
||||
Api Api
|
||||
}
|
||||
|
||||
//创建角色api关联关系
|
||||
func (a *ApiAuthority) SetAuthAndPath(authId string, apis []Api) (err error) {
|
||||
func (a *ApiAuthority) SetAuthAndApi(authId string, apis []Api) (err error) {
|
||||
err = qmsql.DEFAULTDB.Where("authority_id = ?", authId).Delete(&ApiAuthority{}).Error
|
||||
for _, v := range apis {
|
||||
err = qmsql.DEFAULTDB.Create(&ApiAuthority{AuthorityId: authId, ApiId: fmt.Sprintf("%v", v.ID)}).Error
|
||||
err = qmsql.DEFAULTDB.Create(&ApiAuthority{AuthorityId: authId, ApiId: v.ID}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type Authority struct {
|
||||
gorm.Model `json:"-"`
|
||||
gorm.Model
|
||||
AuthorityId string `json:"authorityId" gorm:"not null;unique"`
|
||||
AuthorityName string `json:"authorityName"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user