From f91d22385655dc8cf5a4eb72cab8bcf5b32fdfc2 Mon Sep 17 00:00:00 2001 From: Aravind-2023 <124123923+Aravind-2023@users.noreply.github.com> Date: Fri, 24 Mar 2023 15:43:43 +0530 Subject: [PATCH] after adding condition for deployed time sort (#3108) --- .../helper/AppListingRepositoryQueryBuilder.go | 3 ++- pkg/app/AppListingViewBuilder.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/sql/repository/helper/AppListingRepositoryQueryBuilder.go b/internal/sql/repository/helper/AppListingRepositoryQueryBuilder.go index b167f79565..25c00b3367 100644 --- a/internal/sql/repository/helper/AppListingRepositoryQueryBuilder.go +++ b/internal/sql/repository/helper/AppListingRepositoryQueryBuilder.go @@ -65,7 +65,8 @@ const ( ) const ( - AppNameSortBy SortBy = "appNameSort" + AppNameSortBy SortBy = "appNameSort" + LastDeployedSortBy = "lastDeployedSort" ) func (impl AppListingRepositoryQueryBuilder) BuildJobListingQuery(appIDs []int, statuses []string, sortOrder string) string { diff --git a/pkg/app/AppListingViewBuilder.go b/pkg/app/AppListingViewBuilder.go index 287ece62c2..a4eb86be85 100644 --- a/pkg/app/AppListingViewBuilder.go +++ b/pkg/app/AppListingViewBuilder.go @@ -103,6 +103,20 @@ func (impl *AppListingViewBuilderImpl) BuildView(fetchAppListingRequest FetchApp return appContainersResponses[i].AppName > appContainersResponses[j].AppName }) } + } else if helper.LastDeployedSortBy == fetchAppListingRequest.SortBy { + if fetchAppListingRequest.SortOrder == helper.Asc { + sort.Slice(appContainersResponses, func(i, j int) bool { + deployedTime1 := appContainersResponses[i].AppEnvironmentContainer[0].LastDeployedTime + deployedTime2 := appContainersResponses[j].AppEnvironmentContainer[0].LastDeployedTime + return deployedTime1 > deployedTime2 + }) + } else if fetchAppListingRequest.SortOrder == helper.Desc { + sort.Slice(appContainersResponses, func(i, j int) bool { + deployedTime1 := appContainersResponses[i].AppEnvironmentContainer[0].LastDeployedTime + deployedTime2 := appContainersResponses[j].AppEnvironmentContainer[0].LastDeployedTime + return deployedTime1 < deployedTime2 + }) + } } } return appContainersResponses, nil