groupTop.go 797 Bytes
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
package group_m

import (
	"git.hilo.cn/hilo-common/domain"
	"gorm.io/gorm"
)

type GroupTop struct {
	Id        uint
	ImGroupId string
}

func (g *GroupTop) PutOnTop(model *domain.Model) error {
	err := model.Db.Model(&GroupTop{}).Where("id > 0").Order("id DESC").UpdateColumn("id", gorm.Expr("id + ?", 1)).Error
	if err != nil {
		return err
	}
	g.Id = 1
	return model.Db.Create(g).Error
}

func (g *GroupTop) Delete(model *domain.Model) error {
	return model.Db.Where(g).Delete(&GroupTop{}).Error
}

func GroupTopGetAll(model *domain.Model) ([]string, error) {
	rows := make([]GroupTop, 0)
	err := model.Db.Order("id").Find(&rows).Error
	if err != nil {
		return nil, err
	}
	result := make([]string, 0)
	for _, i := range rows {
		result = append(result, i.ImGroupId)
	}
	return result, err
}