You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
999 B

  1. package dbModel
  2. import (
  3. "github.com/jinzhu/gorm"
  4. "main/controller/servers"
  5. "main/init/qmsql"
  6. "main/model/modelInterface"
  7. )
  8. type Api struct {
  9. gorm.Model `json:"-"`
  10. AuthorityId uint `json:"-"`
  11. Path string `json:"path"`
  12. Description string `json:"description"`
  13. }
  14. func (a *Api) CreateApi() (err error) {
  15. err = qmsql.DEFAULTDB.Create(a).Error
  16. return err
  17. }
  18. func (a *Api) DeleteApi() (err error) {
  19. err = qmsql.DEFAULTDB.Where("id = ?", a.AuthorityId).Delete(a).Error
  20. return err
  21. }
  22. func (a *Api) EditApi() (err error) {
  23. err = qmsql.DEFAULTDB.Update(a).Error
  24. return err
  25. }
  26. // 分页获取数据 需要分页实现这个接口即可
  27. func (a *Api) GetInfoList(info modelInterface.PageInfo) (err error, list interface{}, total int) {
  28. // 封装分页方法 调用即可 传入 当前的结构体和分页信息
  29. err, db, total := servers.PagingServer(a, info)
  30. if err != nil {
  31. return
  32. } else {
  33. var apiList []Api
  34. err = db.Find(&apiList).Error
  35. return err, apiList, total
  36. }
  37. }