From 02d18175f93c826c6c0940bd72ab048dfcbdce22 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Thu, 29 Oct 2020 08:20:25 +0100 Subject: [PATCH] Fix codegen when search cfg is sorting&&!paging --- pkg/codegen/assets/store_rdbms.gen.go.tpl | 17 ++++++++++++++--- store/rdbms/applications.gen.go | 5 ++++- store/rdbms/compose_charts.gen.go | 5 ++++- store/rdbms/compose_modules.gen.go | 5 ++++- store/rdbms/compose_namespaces.gen.go | 5 ++++- store/rdbms/compose_pages.gen.go | 5 ++++- store/rdbms/compose_records.gen.go | 5 ++++- store/rdbms/messaging_channels.gen.go | 5 ++++- store/rdbms/reminders.gen.go | 5 ++++- store/rdbms/roles.gen.go | 5 ++++- store/rdbms/users.gen.go | 5 ++++- 11 files changed, 54 insertions(+), 13 deletions(-) diff --git a/pkg/codegen/assets/store_rdbms.gen.go.tpl b/pkg/codegen/assets/store_rdbms.gen.go.tpl index bc893de1a..f60b4824b 100644 --- a/pkg/codegen/assets/store_rdbms.gen.go.tpl +++ b/pkg/codegen/assets/store_rdbms.gen.go.tpl @@ -73,13 +73,17 @@ func (s Store) {{ toggleExport .Search.Export "Search" $.Types.Plural }}(ctx con reversedCursor := f.PageCursor != nil && f.PageCursor.Reverse {{ end }} -{{ if $.Search.EnableSorting }} +{{ if and $.Search.EnableSorting $.Search.EnablePaging }} + // Sorting and paging are both enabled in definition yaml file + // {search: {enableSorting:true, enablePaging:true}} + curSort := f.Sort.Clone() + // If paging with reverse cursor, change the sorting // direction for all columns we're sorting by - curSort := f.Sort.Clone() if reversedCursor { curSort.Reverse() } + {{ else if $.Search.EnablePaging }} // Sorting is disabled in definition yaml file // {search: {enableSorting:false}} @@ -93,7 +97,7 @@ func (s Store) {{ toggleExport .Search.Export "Search" $.Types.Plural }}(ctx con {{ end }} return set, f, s.config.ErrorHandler(func() error { - {{- if $.Search.EnablePaging }} + {{- if $.Search.EnablePaging -}} set, err = s.{{ unexport "fetchFullPageOf" $.Types.Plural }}(ctx{{ template "extraArgsCall" . }}, q, curSort, f.PageCursor, f.Limit, {{ if $.Search.EnableFilterCheckFn }}f.Check{{ else }}nil{{ end }},) if err != nil { @@ -114,6 +118,13 @@ func (s Store) {{ toggleExport .Search.Export "Search" $.Types.Plural }}(ctx con f.PageCursor = nil return nil {{- else }} + {{- if $.Search.EnableSorting }} + // Apply sorting expr from filter to query + if q, err = setOrderBy(q, f.Sort, s.sortable{{ export $.Types.Singular }}Columns()...); err != nil { + return err + } + {{ end -}} + set, _, _, err = s.{{ export "query" $.Types.Plural }}(ctx{{ template "extraArgsCall" . }}, q, {{ if $.Search.EnableFilterCheckFn }}f.Check{{else}}nil{{ end }}) return err {{ end }} diff --git a/store/rdbms/applications.gen.go b/store/rdbms/applications.gen.go index a04acbe50..fece9f68f 100644 --- a/store/rdbms/applications.gen.go +++ b/store/rdbms/applications.gen.go @@ -43,9 +43,12 @@ func (s Store) SearchApplications(ctx context.Context, f types.ApplicationFilter // This tells us to flip the descending flag on all used sort keys reversedCursor := f.PageCursor != nil && f.PageCursor.Reverse + // Sorting and paging are both enabled in definition yaml file + // {search: {enableSorting:true, enablePaging:true}} + curSort := f.Sort.Clone() + // If paging with reverse cursor, change the sorting // direction for all columns we're sorting by - curSort := f.Sort.Clone() if reversedCursor { curSort.Reverse() } diff --git a/store/rdbms/compose_charts.gen.go b/store/rdbms/compose_charts.gen.go index 4c84c913b..725c4809c 100644 --- a/store/rdbms/compose_charts.gen.go +++ b/store/rdbms/compose_charts.gen.go @@ -43,9 +43,12 @@ func (s Store) SearchComposeCharts(ctx context.Context, f types.ChartFilter) (ty // This tells us to flip the descending flag on all used sort keys reversedCursor := f.PageCursor != nil && f.PageCursor.Reverse + // Sorting and paging are both enabled in definition yaml file + // {search: {enableSorting:true, enablePaging:true}} + curSort := f.Sort.Clone() + // If paging with reverse cursor, change the sorting // direction for all columns we're sorting by - curSort := f.Sort.Clone() if reversedCursor { curSort.Reverse() } diff --git a/store/rdbms/compose_modules.gen.go b/store/rdbms/compose_modules.gen.go index 4020413c9..51815e35e 100644 --- a/store/rdbms/compose_modules.gen.go +++ b/store/rdbms/compose_modules.gen.go @@ -43,9 +43,12 @@ func (s Store) SearchComposeModules(ctx context.Context, f types.ModuleFilter) ( // This tells us to flip the descending flag on all used sort keys reversedCursor := f.PageCursor != nil && f.PageCursor.Reverse + // Sorting and paging are both enabled in definition yaml file + // {search: {enableSorting:true, enablePaging:true}} + curSort := f.Sort.Clone() + // If paging with reverse cursor, change the sorting // direction for all columns we're sorting by - curSort := f.Sort.Clone() if reversedCursor { curSort.Reverse() } diff --git a/store/rdbms/compose_namespaces.gen.go b/store/rdbms/compose_namespaces.gen.go index 639d731a3..e89c02a0d 100644 --- a/store/rdbms/compose_namespaces.gen.go +++ b/store/rdbms/compose_namespaces.gen.go @@ -43,9 +43,12 @@ func (s Store) SearchComposeNamespaces(ctx context.Context, f types.NamespaceFil // This tells us to flip the descending flag on all used sort keys reversedCursor := f.PageCursor != nil && f.PageCursor.Reverse + // Sorting and paging are both enabled in definition yaml file + // {search: {enableSorting:true, enablePaging:true}} + curSort := f.Sort.Clone() + // If paging with reverse cursor, change the sorting // direction for all columns we're sorting by - curSort := f.Sort.Clone() if reversedCursor { curSort.Reverse() } diff --git a/store/rdbms/compose_pages.gen.go b/store/rdbms/compose_pages.gen.go index 56a58c132..f0e7cd44e 100644 --- a/store/rdbms/compose_pages.gen.go +++ b/store/rdbms/compose_pages.gen.go @@ -43,9 +43,12 @@ func (s Store) SearchComposePages(ctx context.Context, f types.PageFilter) (type // This tells us to flip the descending flag on all used sort keys reversedCursor := f.PageCursor != nil && f.PageCursor.Reverse + // Sorting and paging are both enabled in definition yaml file + // {search: {enableSorting:true, enablePaging:true}} + curSort := f.Sort.Clone() + // If paging with reverse cursor, change the sorting // direction for all columns we're sorting by - curSort := f.Sort.Clone() if reversedCursor { curSort.Reverse() } diff --git a/store/rdbms/compose_records.gen.go b/store/rdbms/compose_records.gen.go index f17f18942..db7afebfa 100644 --- a/store/rdbms/compose_records.gen.go +++ b/store/rdbms/compose_records.gen.go @@ -43,9 +43,12 @@ func (s Store) searchComposeRecords(ctx context.Context, _mod *types.Module, f t // This tells us to flip the descending flag on all used sort keys reversedCursor := f.PageCursor != nil && f.PageCursor.Reverse + // Sorting and paging are both enabled in definition yaml file + // {search: {enableSorting:true, enablePaging:true}} + curSort := f.Sort.Clone() + // If paging with reverse cursor, change the sorting // direction for all columns we're sorting by - curSort := f.Sort.Clone() if reversedCursor { curSort.Reverse() } diff --git a/store/rdbms/messaging_channels.gen.go b/store/rdbms/messaging_channels.gen.go index 4db435870..37cb0d106 100644 --- a/store/rdbms/messaging_channels.gen.go +++ b/store/rdbms/messaging_channels.gen.go @@ -43,9 +43,12 @@ func (s Store) SearchMessagingChannels(ctx context.Context, f types.ChannelFilte // This tells us to flip the descending flag on all used sort keys reversedCursor := f.PageCursor != nil && f.PageCursor.Reverse + // Sorting and paging are both enabled in definition yaml file + // {search: {enableSorting:true, enablePaging:true}} + curSort := f.Sort.Clone() + // If paging with reverse cursor, change the sorting // direction for all columns we're sorting by - curSort := f.Sort.Clone() if reversedCursor { curSort.Reverse() } diff --git a/store/rdbms/reminders.gen.go b/store/rdbms/reminders.gen.go index c7e0e7b3f..482596160 100644 --- a/store/rdbms/reminders.gen.go +++ b/store/rdbms/reminders.gen.go @@ -43,9 +43,12 @@ func (s Store) SearchReminders(ctx context.Context, f types.ReminderFilter) (typ // This tells us to flip the descending flag on all used sort keys reversedCursor := f.PageCursor != nil && f.PageCursor.Reverse + // Sorting and paging are both enabled in definition yaml file + // {search: {enableSorting:true, enablePaging:true}} + curSort := f.Sort.Clone() + // If paging with reverse cursor, change the sorting // direction for all columns we're sorting by - curSort := f.Sort.Clone() if reversedCursor { curSort.Reverse() } diff --git a/store/rdbms/roles.gen.go b/store/rdbms/roles.gen.go index 954a7fe3d..89bce22cd 100644 --- a/store/rdbms/roles.gen.go +++ b/store/rdbms/roles.gen.go @@ -43,9 +43,12 @@ func (s Store) SearchRoles(ctx context.Context, f types.RoleFilter) (types.RoleS // This tells us to flip the descending flag on all used sort keys reversedCursor := f.PageCursor != nil && f.PageCursor.Reverse + // Sorting and paging are both enabled in definition yaml file + // {search: {enableSorting:true, enablePaging:true}} + curSort := f.Sort.Clone() + // If paging with reverse cursor, change the sorting // direction for all columns we're sorting by - curSort := f.Sort.Clone() if reversedCursor { curSort.Reverse() } diff --git a/store/rdbms/users.gen.go b/store/rdbms/users.gen.go index 83ec1c860..c2ccb0d89 100644 --- a/store/rdbms/users.gen.go +++ b/store/rdbms/users.gen.go @@ -43,9 +43,12 @@ func (s Store) SearchUsers(ctx context.Context, f types.UserFilter) (types.UserS // This tells us to flip the descending flag on all used sort keys reversedCursor := f.PageCursor != nil && f.PageCursor.Reverse + // Sorting and paging are both enabled in definition yaml file + // {search: {enableSorting:true, enablePaging:true}} + curSort := f.Sort.Clone() + // If paging with reverse cursor, change the sorting // direction for all columns we're sorting by - curSort := f.Sort.Clone() if reversedCursor { curSort.Reverse() }