Compare commits
6 Commits
43c4fe36c0
...
v1.0.14
| Author | SHA1 | Date | |
|---|---|---|---|
| b26de27165 | |||
| 50edeb07ca | |||
| 31c5c49589 | |||
| 51d8531792 | |||
| da19da2d63 | |||
| e1012c234c |
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
@@ -54,3 +54,9 @@ const CountRawTemplate = `func (service *{{.ServiceName}}) Count() (int64, error
|
|||||||
amount, err := dal.{{.EntityType}}.Count()
|
amount, err := dal.{{.EntityType}}.Count()
|
||||||
return amount, err
|
return amount, err
|
||||||
}`
|
}`
|
||||||
|
|
||||||
|
const SortedByOrderTemplate = `func (service *{{.ServiceName}}) SortedByOrder(fieldsSortOrder map[string]string) ([]*{{.EntityType}}, error) {
|
||||||
|
return utils.SortByOrder(fieldsSortOrder, {{.EntityType}}{})
|
||||||
|
}`
|
||||||
|
|
||||||
|
var implementedMethods = []string{CreateMethod, GetAllMethod, GetByIdMethod, UpdateMethod, DeleteMethod, CountMethod, SortedByOrderMethod}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ const GetByIdMethod = "GetById"
|
|||||||
const UpdateMethod = "Update"
|
const UpdateMethod = "Update"
|
||||||
const DeleteMethod = "Delete"
|
const DeleteMethod = "Delete"
|
||||||
const CountMethod = "Count"
|
const CountMethod = "Count"
|
||||||
|
const SortedByOrderMethod = "SortedByOrder"
|
||||||
|
|
||||||
var RawTemplates = map[string]string{
|
var RawTemplates = map[string]string{
|
||||||
CreateMethod: CreateRawTemplate,
|
CreateMethod: CreateRawTemplate,
|
||||||
@@ -30,4 +31,5 @@ var RawTemplates = map[string]string{
|
|||||||
UpdateMethod: UpdateRawTemplate,
|
UpdateMethod: UpdateRawTemplate,
|
||||||
DeleteMethod: DeleteRawTemplate,
|
DeleteMethod: DeleteRawTemplate,
|
||||||
CountMethod: CountRawTemplate,
|
CountMethod: CountRawTemplate,
|
||||||
|
SortedByOrderMethod: SortedByOrderTemplate,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user