Improve sorting

This commit is contained in:
2022-11-01 11:32:13 +01:00
parent 0dd4a723be
commit d028256893
10 changed files with 67 additions and 54 deletions

View File

@@ -0,0 +1,13 @@
package sorting
import (
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
)
type BeneficiariesByName []mobilityaccountsstorage.Account
func (e BeneficiariesByName) Len() int { return len(e) }
func (e BeneficiariesByName) Less(i, j int) bool {
return e[i].Data["first_name"].(string) < e[j].Data["first_name"].(string)
}
func (e BeneficiariesByName) Swap(i, j int) { e[i], e[j] = e[j], e[i] }

11
utils/sorting/events.go Normal file
View File

@@ -0,0 +1,11 @@
package sorting
import (
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
)
type EventsByStartdate []agendastorage.Event
func (e EventsByStartdate) Len() int { return len(e) }
func (e EventsByStartdate) Less(i, j int) bool { return e[i].Startdate.Before(e[j].Startdate) }
func (e EventsByStartdate) Swap(i, j int) { e[i], e[j] = e[j], e[i] }

15
utils/sorting/groups.go Normal file
View File

@@ -0,0 +1,15 @@
package sorting
import (
"strings"
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
)
type GroupsByName []groupstorage.Group
func (a GroupsByName) Len() int { return len(a) }
func (a GroupsByName) Less(i, j int) bool {
return strings.Compare(a[i].Data["name"].(string), a[j].Data["name"].(string)) < 0
}
func (a GroupsByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }