participant.go 756 B

1234567891011121314151617181920212223242526272829303132
  1. package store
  2. import "git.andreafazzi.eu/andrea/probo/models"
  3. type ParticipantStore struct {
  4. *FilterStore[*models.Participant]
  5. }
  6. func NewParticipantStore() *ParticipantStore {
  7. store := new(ParticipantStore)
  8. store.FilterStore = NewFilterStore[*models.Participant]()
  9. return store
  10. }
  11. func (s *ParticipantStore) FilterInGroup(group *models.Group, filter *models.ParticipantFilter) []*models.Participant {
  12. participants := s.ReadAll()
  13. filteredParticipants := s.Filter(participants, func(p *models.Participant) bool {
  14. for pk, pv := range p.Attributes {
  15. for fk, fv := range filter.Attributes {
  16. if pk == fk && pv == fv {
  17. return true
  18. }
  19. }
  20. }
  21. return false
  22. })
  23. group.Participants = filteredParticipants
  24. return group.Participants
  25. }