lista_utenti: add rappresentanti to the user tags.

This commit is contained in:
2022-09-17 22:26:03 +02:00
parent cff45dc92f
commit cd0383245b
4 changed files with 40 additions and 5 deletions
+8 -2
View File
@@ -12,7 +12,8 @@ import (
type jsonListaUtenti struct {
Path string
Macchinisti util.Set[string]
Macchinisti util.Set[string]
Rappresentanti util.Set[string]
}
func newJsonListaUtenti(path string) (Service, error) {
@@ -20,8 +21,12 @@ func newJsonListaUtenti(path string) (Service, error) {
if err != nil {
return nil, err
}
rappresentanti, err := loadRappresentanti()
if err != nil {
return nil, err
}
return &jsonListaUtenti{path, macchinisti}, nil
return &jsonListaUtenti{path, macchinisti, rappresentanti}, nil
}
func (j *jsonListaUtenti) GetUtenti() ([]*model.ListUser, error) {
@@ -37,6 +42,7 @@ func (j *jsonListaUtenti) GetUtenti() ([]*model.ListUser, error) {
}
mergeMacchinisti(users, j.Macchinisti)
mergeRappresentanti(users, j.Rappresentanti)
log.Printf("Caricata lista di %d utenti", len(users))
+23
View File
@@ -44,3 +44,26 @@ func mergeMacchinisti(users []*model.ListUser, macchinisti util.Set[string]) {
}
}
}
func loadRappresentanti() (util.Set[string], error) {
f, err := os.Open("_content/rappresentanti.json")
if err != nil {
return nil, err
}
rappresentanti := []string{}
if err := json.NewDecoder(f).Decode(&rappresentanti); err != nil {
return nil, err
}
return util.NewSet(rappresentanti...), nil
}
func mergeRappresentanti(users []*model.ListUser, rappresentanti util.Set[string]) {
for _, user := range users {
if _, found := rappresentanti[user.Uid]; found {
user.Tags = append(user.Tags, "rappresentante")
}
}
}