Zeus/model/category.go

35 lines
831 B
Go

package model
import (
"bgm/consts"
bgm "bgm/helper"
"fmt"
ctxLogger "github.com/luizsuper/ctxLoggers"
"go.uber.org/zap"
"gorm.io/gorm"
)
type Category struct {
//ID int `json:"id" gorm:"column:id"`
Key int `json:"key" gorm:"column:key"`
Value string `json:"value" gorm:"column:value"`
Gid string `json:"gid" gorm:"column:gid"`
}
func (m *Category) TableName() string {
return "category"
}
func GetCategoryM(page, size int, query bgm.QueryMap, db *gorm.DB) (*[]Category, error) {
i := new([]Category)
db = db.Limit(size).Offset((page - 1) * size)
for k, v := range query {
db = db.Where(fmt.Sprintf("%v = ?", k), v)
}
if err := db.Debug().Find(i).Error; err != nil {
ctxLogger.Info(nil, consts.GetServiceModelErr, zap.String(consts.ErrorReason, err.Error()))
return nil, err
}
return i, nil
}