1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-12-22 00:36:41 +02:00

сделал STARTER_TABLES_MANUAL_FILENAME

This commit is contained in:
Nikitin Aleksandr 2024-02-08 18:01:03 +03:00
parent abc476711b
commit 4d7b0d3631
10 changed files with 243 additions and 7 deletions

View File

@ -136,6 +136,9 @@ NEED_CREATE_NRPC_SERVER_TEST=true
#NEED_CREATE_NRPC_CLIENT_TEST - fill "true" if you want create NRPC client _test.go files
NEED_CREATE_NRPC_CLIENT_TEST=true
#NEED_CREATE_MANUAL_FILES - fill "true" if you want create "_manual.go" files, intended for user manual changes
NEED_CREATE_MANUAL_FILES=true
#PREFIX_SERVER_GRPC - filename prefix for grpc server files
PREFIX_SERVER_GRPC="server_grpc_"

View File

@ -0,0 +1,12 @@
package crud_starter_lawsuit_status_types
import (
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
)
// SetCrudManualInterface - заполняет интерфейс crud: DB, GRPC, NRPC
func SetCrudManualInterface(crud lawsuit_status_types.ICrud_manual_LawsuitStatusType) {
lawsuit_status_types.Crud_manual_LawsuitStatusType = crud
return
}

View File

@ -0,0 +1,19 @@
package crud_starter_lawsuit_status_types
import (
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/crud/crud_starter_lawsuit_status_types"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing"
)
func TestSetCrudManualInterface(t *testing.T) {
crud := crud_lawsuit_status_types.Crud_DB{}
SetCrudManualInterface(crud)
// Test that the crud variable is set correctly
if employees.Crud_manual_LawsuitStatusType != crud {
t.Errorf("Expected lawsuit_status_types.Crud_manual_LawsuitStatusType to be set to crud, but got %+v", lawsuit_status_types.Crud_manual_LawsuitStatusType)
}
}

View File

@ -47,6 +47,7 @@ type SettingsINI struct {
NEED_CREATE_NRPC bool
NEED_CREATE_NRPC_SERVER_TEST bool
NEED_CREATE_NRPC_CLIENT_TEST bool
NEED_CREATE_MANUAL_FILES bool
SERVICE_NAME string
SERVICE_REPOSITORY_URL string
TEXT_TEMPLATE_MODEL string
@ -167,6 +168,7 @@ func FillSettings() {
Settings.TEMPLATE_FOLDER_CRUD_FUNCTIONS = os.Getenv("TEMPLATE_FOLDER_CRUD_FUNCTIONS")
Settings.TEMPLATE_EXTERNAL_PROTO_FILENAME = os.Getenv("TEMPLATE_EXTERNAL_PROTO_FILENAME")
Settings.TEMPLATE_FOLDERNAME_GRPC_NRPC = os.Getenv("TEMPLATE_FOLDERNAME_GRPC_NRPC")
Settings.NEED_CREATE_MANUAL_FILES = BoolFromString(os.Getenv("NEED_CREATE_MANUAL_FILES"))
}

View File

@ -39,6 +39,10 @@ const MAKEFILE_FILENAME = "Makefile"
const ENV_FILENAME = ".env"
const STARTER_TABLES_FILENAME = "starter_tables.go_"
const STARTER_TABLES_FILENAME_TEST = "starter_tables_test.go_"
const STARTER_TABLES_TEST_FILENAME = "starter_tables_test.go_"
const STARTER_TABLES_MANUAL_FILENAME = "starter_tables_manual.go_"
const STARTER_TABLES_TEST_MANUAL_FILENAME = "starter_tables_manual_test.go_"
const STARTER_TABLES_PREFIX = "crud_starter_"
const CRUD_TABLES_FREFIX = "crud_"
const MODEL_TABLE_MANUAL_FILENAME = "model_table_manual.go_"

View File

@ -32,6 +32,7 @@ func CreateAllFiles(MapAll map[string]*types.Table) error {
return err
}
}
//тестовые файлы starter
if config.Settings.NEED_CREATE_DB_TEST == true {
err = CreateTestFiles(Table1)
@ -40,6 +41,20 @@ func CreateAllFiles(MapAll map[string]*types.Table) error {
return err
}
}
// создание файла manual
if config.Settings.NEED_CREATE_MANUAL_FILES == true {
err = CreateFiles_manual(Table1)
if err != nil {
log.Error("CreateFilesModel_manual() table: ", Table1.Name, " error: ", err)
return err
}
err = CreateFiles_manual_test(Table1)
if err != nil {
log.Error("CreateFiles_manual_test() table: ", Table1.Name, " error: ", err)
return err
}
}
}
return err
@ -119,7 +134,7 @@ func CreateTestFiles(Table1 *types.Table) error {
DirTemplatesDB := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER + micro.SeparatorFile() + "starter_tables" + micro.SeparatorFile()
DirReadyDB := DirReady + config.Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER + micro.SeparatorFile()
FilenameTemplateDB := DirTemplatesDB + constants.STARTER_TABLES_FILENAME_TEST
FilenameTemplateDB := DirTemplatesDB + constants.STARTER_TABLES_TEST_FILENAME
DirReadyTable := DirReadyDB + constants.STARTER_TABLES_PREFIX + TableName
FilenameReadyDB := DirReadyTable + micro.SeparatorFile() + constants.STARTER_TABLES_PREFIX + TableName + "_test.go"
@ -161,3 +176,130 @@ func CreateTestFiles(Table1 *types.Table) error {
return err
}
// CreateFiles_manual - создаёт 1 файл в папке crud_starter
func CreateFiles_manual(Table1 *types.Table) error {
var err error
//чтение файлов
DirBin := micro.ProgramDir_bin()
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
DirTemplatesDB := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER + micro.SeparatorFile() + "starter_tables" + micro.SeparatorFile()
DirReadyDB := DirReady + config.Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER + micro.SeparatorFile()
FilenameTemplateDB := DirTemplatesDB + constants.STARTER_TABLES_MANUAL_FILENAME
TableName := strings.ToLower(Table1.Name)
DirReadyTable := DirReadyDB + constants.STARTER_TABLES_PREFIX + TableName
FilenameReadyManual := DirReadyTable + micro.SeparatorFile() + constants.STARTER_TABLES_PREFIX + TableName + "_manual.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
bytes, err := os.ReadFile(FilenameTemplateDB)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateDB, " error: ", err)
}
TextManual := string(bytes)
//заменим имя пакета на новое
TextManual = create_files.ReplacePackageName(TextManual, DirReadyTable)
//заменим импорты
if config.Settings.USE_DEFAULT_TEMPLATE == true {
TextManual = create_files.DeleteTemplateRepositoryImports(TextManual)
ModelTableURL := create_files.FindModelTableURL(TableName)
TextManual = create_files.AddImport(TextManual, ModelTableURL)
}
//создание текста
ModelName := Table1.NameGo
TextManual = strings.ReplaceAll(TextManual, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
TextManual = strings.ReplaceAll(TextManual, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
TextManual = TextManual
//замена импортов на новые URL
TextManual = create_files.ReplaceServiceURLImports(TextManual)
//удаление пустого импорта
TextManual = create_files.DeleteEmptyImport(TextManual)
//запись файла
err = os.WriteFile(FilenameReadyManual, []byte(TextManual), constants.FILE_PERMISSIONS)
return err
}
// CreateFiles_manual_test - создаёт 1 файл в папке crud_starter
func CreateFiles_manual_test(Table1 *types.Table) error {
var err error
//чтение файлов
DirBin := micro.ProgramDir_bin()
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
DirTemplatesDB := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER + micro.SeparatorFile() + "starter_tables" + micro.SeparatorFile()
DirReadyDB := DirReady + config.Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER + micro.SeparatorFile()
FilenameTemplateDB := DirTemplatesDB + constants.STARTER_TABLES_TEST_MANUAL_FILENAME
TableName := strings.ToLower(Table1.Name)
DirReadyTable := DirReadyDB + constants.STARTER_TABLES_PREFIX + TableName
FilenameReadyManual := DirReadyTable + micro.SeparatorFile() + constants.STARTER_TABLES_PREFIX + TableName + "_manual_test.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
bytes, err := os.ReadFile(FilenameTemplateDB)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateDB, " error: ", err)
}
TextManual := string(bytes)
//заменим имя пакета на новое
TextManual = create_files.ReplacePackageName(TextManual, DirReadyTable)
//заменим импорты
if config.Settings.USE_DEFAULT_TEMPLATE == true {
TextManual = create_files.DeleteTemplateRepositoryImports(TextManual)
//
ModelTableURL := create_files.FindModelTableURL(TableName)
TextManual = create_files.AddImport(TextManual, ModelTableURL)
//
CrudStarterTableURL := create_files.FindCrudStarterTableURL(TableName)
TextManual = create_files.AddImport(TextManual, CrudStarterTableURL)
}
//создание текста
ModelName := Table1.NameGo
TextManual = strings.ReplaceAll(TextManual, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
TextManual = strings.ReplaceAll(TextManual, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
TextManual = TextManual
//замена импортов на новые URL
TextManual = create_files.ReplaceServiceURLImports(TextManual)
//удаление пустого импорта
TextManual = create_files.DeleteEmptyImport(TextManual)
//запись файла
err = os.WriteFile(FilenameReadyManual, []byte(TextManual), constants.FILE_PERMISSIONS)
return err
}

View File

@ -1 +0,0 @@
package model

View File

@ -1,4 +1,4 @@
package model
package model_tables
import (
"errors"
@ -18,6 +18,7 @@ import (
func CreateAllFiles(MapAll map[string]*types.Table) error {
var err error
//для каждой таблицы
for _, table1 := range MapAll {
err = CreateFiles(table1)
if err != nil {
@ -58,10 +59,20 @@ func CreateFiles(Table1 *types.Table) error {
if config.Settings.NEED_CREATE_MODEL_CRUD == true {
err = CreateFilesModel_crud(Table1, DirTemplatesModel, DirReadyModel)
if err != nil {
log.Error("CreateFilesModel_struct() table: ", Table1.Name, " error: ", err)
log.Error("CreateFilesModel_crud() table: ", Table1.Name, " error: ", err)
return err
}
}
// создание файла manual
if config.Settings.NEED_CREATE_MANUAL_FILES == true {
err = CreateFilesModel_manual(Table1, DirTemplatesModel, DirReadyModel)
if err != nil {
log.Error("CreateFilesModel_manual() table: ", Table1.Name, " error: ", err)
return err
}
}
return err
}
@ -453,3 +464,46 @@ func DeleteFromInterfaceFind_ByExtID(TextModel string, Table1 *types.Table) stri
return Otvet
}
// CreateFilesModel_manual - создаёт 1 файл с _manual.go
func CreateFilesModel_manual(Table1 *types.Table, DirTemplatesModel, DirReadyModel string) error {
var err error
//
ModelName := Table1.NameGo
TableName := strings.ToLower(Table1.Name)
FilenameTemplateModel := DirTemplatesModel + constants.MODEL_TABLE_MANUAL_FILENAME
FilenameReadyModel := DirReadyModel + TableName + "_manual.go"
//чтение файла шаблона
bytes, err := os.ReadFile(FilenameTemplateModel)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateModel, " error: ", err)
}
TextModel := string(bytes)
//заменим имя пакета на новое
TextModel = create_files.ReplacePackageName(TextModel, DirReadyModel)
//заменим импорты
if config.Settings.USE_DEFAULT_TEMPLATE == true {
//TextModel = create_files.DeleteTemplateRepositoryImports(TextModel)
}
//создание текста
TextModel = strings.ReplaceAll(TextModel, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
TextModel = strings.ReplaceAll(TextModel, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
//TextModel = config.Settings.TEXT_MODULE_GENERATED + TextModel
//замена импортов на новые URL
TextModel = create_files.ReplaceServiceURLImports(TextModel)
//удаление пустого импорта
TextModel = create_files.DeleteEmptyImport(TextModel)
//запись файла
err = os.WriteFile(FilenameReadyModel, []byte(TextModel), constants.FILE_PERMISSIONS)
return err
}

View File

@ -0,0 +1 @@
package model_tables

View File

@ -13,7 +13,7 @@ import (
"github.com/ManyakRus/crud_generator/internal/create_files/grpc_server_tables"
"github.com/ManyakRus/crud_generator/internal/create_files/main_file"
"github.com/ManyakRus/crud_generator/internal/create_files/makefile"
"github.com/ManyakRus/crud_generator/internal/create_files/model"
"github.com/ManyakRus/crud_generator/internal/create_files/model_tables"
"github.com/ManyakRus/crud_generator/internal/create_files/nrpc_client"
"github.com/ManyakRus/crud_generator/internal/create_files/protobuf"
"github.com/ManyakRus/crud_generator/internal/create_files/server_grpc_func"
@ -51,7 +51,7 @@ func StartFillAll() error {
}
//модель
err = model.CreateAllFiles(MapAll)
err = model_tables.CreateAllFiles(MapAll)
if err != nil {
//log.Error("model.CreateAllFiles() error: ", err)
return err