feat(controller,app): sort apps by id

This commit is contained in:
wpetit 2023-04-11 12:05:51 +02:00
parent 280b0fbd50
commit c4427dfd2b
1 changed files with 9 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package app
import ( import (
"context" "context"
"sort"
"sync" "sync"
"forge.cadoles.com/arcad/edge/pkg/app" "forge.cadoles.com/arcad/edge/pkg/app"
@ -77,6 +78,8 @@ func (r *AppRepository) List(ctx context.Context) ([]*app.Manifest, error) {
manifests = append(manifests, manifest) manifests = append(manifests, manifest)
} }
sort.Sort(ByID(manifests))
return manifests, nil return manifests, nil
} }
@ -126,3 +129,9 @@ func NewAppRepository() *AppRepository {
} }
var _ appModule.Repository = &AppRepository{} var _ appModule.Repository = &AppRepository{}
type ByID []*app.Manifest
func (a ByID) Len() int { return len(a) }
func (a ByID) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByID) Less(i, j int) bool { return a[i].ID > a[j].ID }