5 Commits

Author SHA1 Message Date
b26de27165 fix: create method 2025-03-12 16:20:10 +07:00
50edeb07ca fix: readme 2025-03-12 16:15:37 +07:00
31c5c49589 fix: sorting method generation 2025-03-12 16:08:36 +07:00
51d8531792 upd: README.md 2025-03-12 16:01:53 +07:00
da19da2d63 update: README.md 2025-03-12 15:58:34 +07:00
3 changed files with 5 additions and 3 deletions

View File

@@ -3,7 +3,7 @@
## Install ## Install
```shell ```shell
go install git.gogacoder.ru/NTO/crudgen/cmd/crudgen@v1.0.7 go install git.gogacoder.ru/NTO/crudgen/cmd/crudgen@v1.0.14
``` ```
## Run ## Run

View File

@@ -2,7 +2,7 @@ package internal
const CreateRawTemplate = `func (service *{{.ServiceName}}) Create(item {{.EntityType}}) ({{.EntityType}}, error) { const CreateRawTemplate = `func (service *{{.ServiceName}}) Create(item {{.EntityType}}) ({{.EntityType}}, error) {
utils.ReplaceEmptySlicesWithNil(&item) utils.ReplaceEmptySlicesWithNil(&item)
err := dal.Author.Create(&item) err := dal.{{.EntityType}}.Create(&item)
if err != nil { if err != nil {
return item, err return item, err
} }
@@ -58,3 +58,5 @@ const CountRawTemplate = `func (service *{{.ServiceName}}) Count() (int64, error
const SortedByOrderTemplate = `func (service *{{.ServiceName}}) SortedByOrder(fieldsSortOrder map[string]string) ([]*{{.EntityType}}, error) { const SortedByOrderTemplate = `func (service *{{.ServiceName}}) SortedByOrder(fieldsSortOrder map[string]string) ([]*{{.EntityType}}, error) {
return utils.SortByOrder(fieldsSortOrder, {{.EntityType}}{}) return utils.SortByOrder(fieldsSortOrder, {{.EntityType}}{})
}` }`
var implementedMethods = []string{CreateMethod, GetAllMethod, GetByIdMethod, UpdateMethod, DeleteMethod, CountMethod, SortedByOrderMethod}

View File

@@ -244,7 +244,7 @@ func ImplementCrudMethods(modelName string, serviceName string, file *dst.File,
EntityPlural: ToPlural(modelName), EntityPlural: ToPlural(modelName),
} }
for _, methodName := range []string{CreateMethod, GetAllMethod, GetByIdMethod, UpdateMethod, DeleteMethod, CountMethod} { for _, methodName := range implementedMethods {
methodCode := GenerateCrudMethodCode(methodName, templateContext) methodCode := GenerateCrudMethodCode(methodName, templateContext)
methodDecl, err := MethodCodeToDeclaration(methodCode) methodDecl, err := MethodCodeToDeclaration(methodCode)
fmt.Printf("%s\n", methodCode) fmt.Printf("%s\n", methodCode)