package model import ( "git.getensh.com/common/gopkgsv2/database" "gorm.io/gorm" ) type APIListModel interface { List(db *gorm.DB, pagination *Pagination) ([]AdmAPIList, error) Count(db *gorm.DB) (int64, error) Update(db *gorm.DB, values interface{}) error Get(db *gorm.DB) (*AdmAPIList, error) } type AdmAPIList struct { Id int64 `gorm:"column:id" json:"id" form:"id"` ApiNo string `gorm:"column:api_no" json:"api_no" form:"api_no"` Desc string `gorm:"column:desc" json:"desc" form:"desc"` Path string `gorm:"column:path" json:"path" form:"path"` Request string `gorm:"column:request" json:"request" form:"request"` Response string `gorm:"column:response" json:"response" form:"response"` RelatedTableIds string `gorm:"column:related_table_ids" json:"related_table_ids" form:"related_table_ids"` CreatedAt int64 `gorm:"column:created_at" json:"created_at" form:"created_at"` UpdatedAt int64 `gorm:"column:updated_at" json:"updated_at" form:"updated_at"` } type AdmRelatedTableList struct { TableName string `gorm:"column:table_name" json:"table_name" form:"table_name"` Desc string `gorm:"column:desc" json:"desc" form:"desc"` } type defaultAPIList struct { tableName string fields string } func NewAPIList() APIListModel { return &defaultAPIList{ tableName: "t_adm_api_management", fields: "`id`, `api_no`, `desc`, `path`, `request`, `response`, `created_at`, `updated_at`", } } func (d *defaultAPIList) List(db *gorm.DB, pagination *Pagination) ([]AdmAPIList, error) { var res []AdmAPIList err := database.List(db, &res, database.Option{ TableName: d.tableName, Fields: d.fields, Limit: pagination.Limit, OffSet: pagination.Offset, }) return res, err } func (d *defaultAPIList) Count(db *gorm.DB) (int64, error) { return database.Count(db, database.Option{ TableName: d.tableName, }) } func (d *defaultAPIList) Update(db *gorm.DB, values interface{}) error { return database.Update(db, values, database.Option{ TableName: d.tableName, }) } func (d *defaultAPIList) Get(db *gorm.DB) (*AdmAPIList, error) { var res AdmAPIList err := database.Get(db, &res, database.Option{ TableName: d.tableName, Fields: d.fields, }) return &res, err }