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

@@ -8,9 +8,9 @@ import (
"io"
"net/http"
"sort"
"strings"
"time"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
@@ -19,14 +19,6 @@ import (
"google.golang.org/protobuf/types/known/structpb"
)
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] }
func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Request) {
request := &groupsmanagement.GetGroupsRequest{
@@ -47,7 +39,7 @@ func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Reque
groups = append(groups, g)
}
sort.Sort(GroupsByName(groups))
sort.Sort(sorting.GroupsByName(groups))
h.Renderer.Administration(w, r, groups)
}

View File

@@ -11,6 +11,7 @@ import (
formvalidators "git.coopgo.io/coopgo-apps/parcoursmob/utils/form-validators"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
@@ -21,12 +22,6 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
)
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] }
type EventsForm struct {
Name string `json:"name" validate:"required"`
Type string `json:"type" validate:"required"`
@@ -60,7 +55,7 @@ func (h *ApplicationHandler) AgendaHome(w http.ResponseWriter, r *http.Request)
responses = append(responses, e.ToStorageType())
}
sort.Sort(EventsByStartdate(responses))
sort.Sort(sorting.EventsByStartdate(responses))
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
Groupids: groupids,

View File

@@ -18,6 +18,7 @@ import (
formvalidators "git.coopgo.io/coopgo-apps/parcoursmob/utils/form-validators"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
profilepictures "git.coopgo.io/coopgo-apps/parcoursmob/utils/profile-pictures"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
@@ -40,14 +41,6 @@ type BeneficiariesForm struct {
Gender string `json:"gender"`
}
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] }
func (h *ApplicationHandler) BeneficiariesList(w http.ResponseWriter, r *http.Request) {
accounts, err := h.beneficiaries(r)
@@ -57,7 +50,7 @@ func (h *ApplicationHandler) BeneficiariesList(w http.ResponseWriter, r *http.Re
return
}
sort.Sort(BeneficiariesByName(accounts))
sort.Sort(sorting.BeneficiariesByName(accounts))
cacheid := uuid.NewString()
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)

View File

@@ -7,6 +7,7 @@ import (
"sort"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
"git.coopgo.io/coopgo-platform/groups-management/storage"
@@ -69,7 +70,7 @@ func (h *ApplicationHandler) Dashboard(w http.ResponseWriter, r *http.Request) {
events = append(events, e.ToStorageType())
}
sort.Sort(EventsByStartdate(events))
sort.Sort(sorting.EventsByStartdate(events))
h.Renderer.Dashboard(w, r, accounts, count, count_members, events)

View File

@@ -4,9 +4,11 @@ import (
"context"
"fmt"
"net/http"
"sort"
"time"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
"git.coopgo.io/coopgo-platform/groups-management/storage"
@@ -72,6 +74,8 @@ func (h ApplicationHandler) VehiclesSearch(w http.ResponseWriter, r *http.Reques
return
}
sort.Sort(sorting.BeneficiariesByName(accounts))
h.Renderer.VehiclesSearch(w, r, accounts, searched, vehicles, beneficiary, r.FormValue("startdate"), r.FormValue("enddate"))
}