From c4427dfd2bd679fc1a62693247c931c4f5aa31b2 Mon Sep 17 00:00:00 2001 From: William Petit Date: Tue, 11 Apr 2023 12:05:51 +0200 Subject: [PATCH] feat(controller,app): sort apps by id --- internal/agent/controller/app/app_repository.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/agent/controller/app/app_repository.go b/internal/agent/controller/app/app_repository.go index d81980a..884963f 100644 --- a/internal/agent/controller/app/app_repository.go +++ b/internal/agent/controller/app/app_repository.go @@ -2,6 +2,7 @@ package app import ( "context" + "sort" "sync" "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) } + sort.Sort(ByID(manifests)) + return manifests, nil } @@ -126,3 +129,9 @@ func NewAppRepository() *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 }