From e1012c234ccf8d7c91d63c5416327ebd7c1c2ecd Mon Sep 17 00:00:00 2001 From: gogacoder Date: Wed, 12 Mar 2025 15:57:30 +0700 Subject: [PATCH] feat: sorting --- internal/raw_templates.go | 4 ++++ internal/templates.go | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/raw_templates.go b/internal/raw_templates.go index 64503f6..5df1f7a 100644 --- a/internal/raw_templates.go +++ b/internal/raw_templates.go @@ -54,3 +54,7 @@ const CountRawTemplate = `func (service *{{.ServiceName}}) Count() (int64, error amount, err := dal.{{.EntityType}}.Count() return amount, err }` + +const SortedByOrderTemplate = `func (service *{{.ServiceName}}) SortedByOrder(fieldsSortOrder map[string]string) ([]*{{.EntityType}}, error) { + return utils.SortByOrder(fieldsSortOrder, {{.EntityType}}{}) +}` diff --git a/internal/templates.go b/internal/templates.go index cc56197..c7a15c5 100644 --- a/internal/templates.go +++ b/internal/templates.go @@ -22,12 +22,14 @@ const GetByIdMethod = "GetById" const UpdateMethod = "Update" const DeleteMethod = "Delete" const CountMethod = "Count" +const SortedByOrderMethod = "SortedByOrder" var RawTemplates = map[string]string{ - CreateMethod: CreateRawTemplate, - GetAllMethod: GetAllRawTemplate, - GetByIdMethod: GetByIdRawTemplate, - UpdateMethod: UpdateRawTemplate, - DeleteMethod: DeleteRawTemplate, - CountMethod: CountRawTemplate, + CreateMethod: CreateRawTemplate, + GetAllMethod: GetAllRawTemplate, + GetByIdMethod: GetByIdRawTemplate, + UpdateMethod: UpdateRawTemplate, + DeleteMethod: DeleteRawTemplate, + CountMethod: CountRawTemplate, + SortedByOrderMethod: SortedByOrderTemplate, }