feat: now one channel can belong to multiple groups (close #153)

This commit is contained in:
JustSong
2023-06-14 12:14:08 +08:00
parent 38668e7331
commit 7f9577a386
2 changed files with 19 additions and 10 deletions

View File

@@ -30,15 +30,18 @@ func GetRandomSatisfiedChannel(group string, model string) (*Channel, error) {
func (channel *Channel) AddAbilities() error {
models_ := strings.Split(channel.Models, ",")
groups_ := strings.Split(channel.Group, ",")
abilities := make([]Ability, 0, len(models_))
for _, model := range models_ {
ability := Ability{
Group: channel.Group,
Model: model,
ChannelId: channel.Id,
Enabled: channel.Status == common.ChannelStatusEnabled,
for _, group := range groups_ {
ability := Ability{
Group: group,
Model: model,
ChannelId: channel.Id,
Enabled: channel.Status == common.ChannelStatusEnabled,
}
abilities = append(abilities, ability)
}
abilities = append(abilities, ability)
}
return DB.Create(&abilities).Error
}