API增删改查忘词嗯

This commit is contained in:
pixel
2019-09-28 16:34:43 +08:00
parent 324d45f1de
commit 3237b8402b
11 changed files with 267 additions and 40 deletions

View File

@@ -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
}