|
@@ -1,7 +1,9 @@
|
|
|
package store
|
|
|
|
|
|
import (
|
|
|
+ "math/rand"
|
|
|
"os"
|
|
|
+ "strconv"
|
|
|
|
|
|
"git.andreafazzi.eu/andrea/probo/lib/models"
|
|
|
"github.com/gocarina/gocsv"
|
|
@@ -34,6 +36,9 @@ func (s *ParticipantStore) ImportCSV(path string) ([]*models.Participant, error)
|
|
|
memParticipants := make([]*models.Participant, 0)
|
|
|
|
|
|
for _, p := range participants {
|
|
|
+ if p.Token == "" {
|
|
|
+ p.Token = generateToken()
|
|
|
+ }
|
|
|
memParticipant, err := s.Create(p)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
@@ -45,26 +50,37 @@ func (s *ParticipantStore) ImportCSV(path string) ([]*models.Participant, error)
|
|
|
|
|
|
}
|
|
|
|
|
|
-func (s *ParticipantStore) FilterInGroup(group *models.Group, filter map[string]string) []*models.Participant {
|
|
|
- participants := s.ReadAll()
|
|
|
-
|
|
|
- if filter == nil {
|
|
|
- return participants
|
|
|
+func generateToken() string {
|
|
|
+ // Generate six random numbers from 1 to 9
|
|
|
+ var token string
|
|
|
+ for i := 0; i < 6; i++ {
|
|
|
+ randomNumber := rand.Intn(9) + 1
|
|
|
+ token += strconv.Itoa(randomNumber)
|
|
|
}
|
|
|
|
|
|
- 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 token
|
|
|
+}
|
|
|
|
|
|
- return false
|
|
|
- })
|
|
|
+// func (s *ParticipantStore) FilterInGroup(group *models.Group, filter map[string]string) []*models.Participant {
|
|
|
+// participants := s.ReadAll()
|
|
|
|
|
|
- group.Participants = filteredParticipants
|
|
|
+// if filter == nil {
|
|
|
+// return participants
|
|
|
+// }
|
|
|
|
|
|
- return group.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
|
|
|
+// }
|