groupPopular.go 625 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
package group_m

import "git.hilo.cn/hilo-common/domain"

type GroupPopular struct {
	GroupId string
}

func GetPopularWhiteList(model *domain.Model) (map[string]struct{}, error) {
	rows := make([]GroupPopular, 0)
	err := model.Db.Find(&rows).Error
	if err != nil {
		return nil, err
	}

	result := make(map[string]struct{}, 0)
	for _, i := range rows {
		result[i.GroupId] = struct{}{}
	}
	return result, nil
}

func (gp *GroupPopular) Add(model *domain.Model) error {
	return model.Db.Create(gp).Error
}

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