package repository import ( "context" "next-terminal/server/model" ) var GatewayGroupRepository = new(gatewayGroupRepository) type gatewayGroupRepository struct { baseRepository } func (r gatewayGroupRepository) FindAll(c context.Context) (o []model.GatewayGroup, err error) { err = r.GetDB(c).Order("created asc").Find(&o).Error return } func (r gatewayGroupRepository) Find(c context.Context, pageIndex, pageSize int, keyword string) (o []model.GatewayGroup, total int64, err error) { db := r.GetDB(c).Table("gateway_groups") dbCounter := r.GetDB(c).Table("gateway_groups") if len(keyword) > 0 { db = db.Where("name like ?", "%"+keyword+"%") dbCounter = dbCounter.Where("name like ?", "%"+keyword+"%") } err = dbCounter.Count(&total).Error if err != nil { return nil, 0, err } err = db.Order("created desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&o).Error if o == nil { o = make([]model.GatewayGroup, 0) } return } func (r gatewayGroupRepository) Create(c context.Context, o *model.GatewayGroup) error { return r.GetDB(c).Create(o).Error } func (r gatewayGroupRepository) UpdateById(c context.Context, o *model.GatewayGroup, id string) error { o.ID = id return r.GetDB(c).Updates(o).Error } func (r gatewayGroupRepository) DeleteById(c context.Context, id string) error { return r.GetDB(c).Where("id = ?", id).Delete(&model.GatewayGroup{}).Error } func (r gatewayGroupRepository) FindById(c context.Context, id string) (o model.GatewayGroup, err error) { err = r.GetDB(c).Where("id = ?", id).First(&o).Error return }