apiList.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package model
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "gorm.io/gorm"
  5. )
  6. type APIListModel interface {
  7. List(db *gorm.DB, pagination *Pagination) ([]AdmAPIList, error)
  8. Count(db *gorm.DB) (int64, error)
  9. Update(db *gorm.DB, values interface{}) error
  10. Get(db *gorm.DB) (*AdmAPIList, error)
  11. }
  12. type AdmAPIList struct {
  13. Id int64 `gorm:"column:id" json:"id" form:"id"`
  14. ApiNo string `gorm:"column:api_no" json:"api_no" form:"api_no"`
  15. Desc string `gorm:"column:desc" json:"desc" form:"desc"`
  16. Path string `gorm:"column:path" json:"path" form:"path"`
  17. Request string `gorm:"column:request" json:"request" form:"request"`
  18. Response string `gorm:"column:response" json:"response" form:"response"`
  19. RelatedTableIds string `gorm:"column:related_table_ids" json:"related_table_ids" form:"related_table_ids"`
  20. CreatedAt int64 `gorm:"column:created_at" json:"created_at" form:"created_at"`
  21. UpdatedAt int64 `gorm:"column:updated_at" json:"updated_at" form:"updated_at"`
  22. }
  23. type AdmRelatedTableList struct {
  24. TableName string `gorm:"column:table_name" json:"table_name" form:"table_name"`
  25. Desc string `gorm:"column:desc" json:"desc" form:"desc"`
  26. }
  27. type defaultAPIList struct {
  28. tableName string
  29. fields string
  30. }
  31. func NewAPIList() APIListModel {
  32. return &defaultAPIList{
  33. tableName: "t_adm_api_management",
  34. fields: "`id`, `api_no`, `desc`, `path`, `request`, `response`, `created_at`, `updated_at`",
  35. }
  36. }
  37. func (d *defaultAPIList) List(db *gorm.DB, pagination *Pagination) ([]AdmAPIList, error) {
  38. var res []AdmAPIList
  39. err := database.List(db, &res, database.Option{
  40. TableName: d.tableName,
  41. Fields: d.fields,
  42. Limit: pagination.Limit,
  43. OffSet: pagination.Offset,
  44. })
  45. return res, err
  46. }
  47. func (d *defaultAPIList) Count(db *gorm.DB) (int64, error) {
  48. return database.Count(db, database.Option{
  49. TableName: d.tableName,
  50. })
  51. }
  52. func (d *defaultAPIList) Update(db *gorm.DB, values interface{}) error {
  53. return database.Update(db, values, database.Option{
  54. TableName: d.tableName,
  55. })
  56. }
  57. func (d *defaultAPIList) Get(db *gorm.DB) (*AdmAPIList, error) {
  58. var res AdmAPIList
  59. err := database.Get(db, &res, database.Option{
  60. TableName: d.tableName,
  61. Fields: d.fields,
  62. })
  63. return &res, err
  64. }