38 lines
785 B
Go
38 lines
785 B
Go
package store
|
|
|
|
import "git.andreafazzi.eu/andrea/probo/models"
|
|
|
|
type ParticipantStore struct {
|
|
*FilterStore[*models.Participant]
|
|
}
|
|
|
|
func NewParticipantStore() *ParticipantStore {
|
|
store := new(ParticipantStore)
|
|
store.FilterStore = NewFilterStore[*models.Participant]()
|
|
|
|
return store
|
|
}
|
|
|
|
func (s *ParticipantStore) FilterInGroup(group *models.Group, filter map[string]string) []*models.Participant {
|
|
participants := s.ReadAll()
|
|
|
|
if filter == nil {
|
|
return participants
|
|
}
|
|
|
|
filteredParticipants := s.Filter(participants, func(p *models.Participant) bool {
|
|
for pk, pv := range p.Attributes {
|
|
for fk, fv := range filter {
|
|
if pk == fk && pv == fv {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
|
|
return false
|
|
})
|
|
|
|
group.Participants = filteredParticipants
|
|
|
|
return group.Participants
|
|
}
|