From 53212024247b10732486adde7bc8fdcc73392782 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Tue, 20 Feb 2024 16:45:34 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20TEMPLATE?= =?UTF-8?q?S=5FGRPC=5FCLIENT=5FTABLE=5FUPDATE=5FFILENAME?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/templates/configs_/settings.txt | 5 + .../grpc_client/grpc_client_table_update.go_ | 13 ++ .../grpc_client_table_update_test.go_ | 116 ++++++++++++++ internal/config/config.go | 142 ++++++++++-------- .../grpc_client_tables/grpc_client_tables.go | 72 ++++++--- 5 files changed, 260 insertions(+), 88 deletions(-) create mode 100644 bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update.go_ create mode 100644 bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_test.go_ diff --git a/bin/templates/configs_/settings.txt b/bin/templates/configs_/settings.txt index 2c8114b..dde5e45 100644 --- a/bin/templates/configs_/settings.txt +++ b/bin/templates/configs_/settings.txt @@ -202,3 +202,8 @@ TEMPLATES_CRUD_TABLE_UPDATE_FILENAME="crud_table_update.go_" #TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME - short filename of "crud_table_update_test.go_" file TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME="crud_table_update_test.go_" +#TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME - short filename of "grpc_client_table_update.go_" file +TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME="grpc_client_table_update.go_" + +#TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME - short filename of "grpc_client_table_update_test.go_" file +TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME="grpc_client_table_update_test.go_" diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update.go_ new file mode 100644 index 0000000..63d1c37 --- /dev/null +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update.go_ @@ -0,0 +1,13 @@ +package grpc_lawsuit_status_types + +import ( + "context" + "github.com/ManyakRus/starter/log" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_constants" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc_nrpc" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" + "time" +) diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_test.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_test.go_ new file mode 100644 index 0000000..a863aaf --- /dev/null +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_test.go_ @@ -0,0 +1,116 @@ +package grpc_lawsuit_status_types + +import ( + "github.com/ManyakRus/starter/config_main" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" + "testing" +) + +func TestCrud_GRPC_Update_Code(t *testing.T) { + config_main.LoadEnv() + + grpc_client.Connect() + defer grpc_client.CloseConnection() + + crud := Crud_GRPC{} + + //прочитаем из БД + Model := lawsuit_status_types.LawsuitStatusType{} + Model.ID = Postgres_ID_Test + err := crud.Read(&Model) + + if err != nil { + t.Error("TestCrud_GRPC_Update_Code() Read() error: ", err) + } + + //запишем в БД это же значение + Otvet := lawsuit_status_types.LawsuitStatusType{} + Otvet.ID = Model.ID + Otvet.Code = Model.Code + err = crud.Update_Code(&Otvet) + if err != nil { + t.Error("TestCrud_GRPC_Update_Code() Update() error: ", err) + } +} + +func TestCrud_GRPC_Update_Description(t *testing.T) { + config_main.LoadEnv() + + grpc_client.Connect() + defer grpc_client.CloseConnection() + + crud := Crud_GRPC{} + + //прочитаем из БД + Model := lawsuit_status_types.LawsuitStatusType{} + Model.ID = Postgres_ID_Test + err := crud.Read(&Model) + + if err != nil { + t.Error("TestCrud_GRPC_Update_Description() Read() error: ", err) + } + + //запишем в БД это же значение + Otvet := lawsuit_status_types.LawsuitStatusType{} + Otvet.ID = Model.ID + Otvet.Description = Model.Description + err = crud.Update_Description(&Otvet) + if err != nil { + t.Error("TestCrud_GRPC_Update_Description() Update() error: ", err) + } +} + +func TestCrud_GRPC_Update_IsClosed(t *testing.T) { + config_main.LoadEnv() + + grpc_client.Connect() + defer grpc_client.CloseConnection() + + crud := Crud_GRPC{} + + //прочитаем из БД + Model := lawsuit_status_types.LawsuitStatusType{} + Model.ID = Postgres_ID_Test + err := crud.Read(&Model) + + if err != nil { + t.Error("TestCrud_GRPC_Update_IsClosed() Read() error: ", err) + } + + //запишем в БД это же значение + Otvet := lawsuit_status_types.LawsuitStatusType{} + Otvet.ID = Model.ID + Otvet.IsClosed = Model.IsClosed + err = crud.Update_IsClosed(&Otvet) + if err != nil { + t.Error("TestCrud_GRPC_Update_IsClosed() Update() error: ", err) + } +} + +func TestCrud_GRPC_Update_Name(t *testing.T) { + config_main.LoadEnv() + + grpc_client.Connect() + defer grpc_client.CloseConnection() + + crud := Crud_GRPC{} + + //прочитаем из БД + Model := lawsuit_status_types.LawsuitStatusType{} + Model.ID = Postgres_ID_Test + err := crud.Read(&Model) + + if err != nil { + t.Error("TestCrud_GRPC_Update_Name() Read() error: ", err) + } + + //запишем в БД это же значение + Otvet := lawsuit_status_types.LawsuitStatusType{} + Otvet.ID = Model.ID + Otvet.Name = Model.Name + err = crud.Update_Name(&Otvet) + if err != nil { + t.Error("TestCrud_GRPC_Update_Name() Update() error: ", err) + } +} diff --git a/internal/config/config.go b/internal/config/config.go index d10433c..891c80e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -14,71 +14,73 @@ var Settings SettingsINI // SettingsINI - структура для хранения всех нужных переменных окружения type SettingsINI struct { - INCLUDE_TABLES string - EXCLUDE_TABLES string - TEMPLATE_FOLDERNAME string - TEMPLATE_FOLDERNAME_MODEL string - TEMPLATE_FOLDERNAME_DB string - TEMPLATE_FOLDERNAME_CRUD string - TEMPLATE_FOLDERNAME_TABLES string - TEMPLATE_FOLDERNAME_GRPC string - TEMPLATE_FOLDERNAME_GRPC_PROTO string - TEMPLATE_FOLDERNAME_GRPC_SERVER string - TEMPLATE_FOLDERNAME_GRPC_CLIENT string - TEMPLATE_FOLDERNAME_NRPC string - TEMPLATE_FOLDERNAME_NRPC_SERVER string - TEMPLATE_FOLDERNAME_NRPC_CLIENT string - TEMPLATE_FOLDERNAME_GRPC_NRPC string - TEMPLATE_SERVICE_NAME string - TEMPLATE_FOLDERNAME_CRUD_STARTER string - TEMPLATE_FOLDERNAME_ALIAS string - TEMPLATE_FOLDER_CRUD_FUNCTIONS string - TEMPLATE_FOLDERNAME_MAIN string - TEMPLATE_REPOSITORY_URL string - TEMPLATE_EXTERNAL_PROTO_FILENAME string - TEMPLATES_CRUD_FILENAME string - TEMPLATES_CRUD_TEST_FILENAME string - TEMPLATES_ALIAS_FILENAME string - TEMPLATES_CRUD_TABLE_UPDATE_FUNC_FILENAME string - TEMPLATES_CRUD_TABLE_UPDATE_FUNC_TEST_FILENAME string - TEMPLATES_CONVERT_ID_FILENAME string - TEMPLATES_CRUD_FUNCTIONS_RENAME_FILENAME string - TEMPLATES_MODEL_CRUD_DELETE_FUNCTIONS_FILENAME string - TEMPLATES_NAME_REPLACE_FILENAME string - TEMPLATES_NULLABLE_FILENAME string - TEMPLATES_CRUD_TABLE_UPDATE_FILENAME string - TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME string - NEED_CREATE_MODEL_STRUCT bool - NEED_CREATE_MODEL_CRUD bool - NEED_CREATE_DB bool - NEED_CREATE_DB_TEST bool - NEED_CREATE_DB_TABLES bool - NEED_CREATE_GRPC bool - NEED_CREATE_GRPC_SERVER_TEST bool - NEED_CREATE_GRPC_CLIENT_TEST bool - 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 - TEXT_TEMPLATE_TABLENAME string - HAS_IS_DELETED bool - READY_FOLDERNAME string - TEXT_DB_MODIFIED_AT string - TEXT_DB_CREATED_AT string - TEXT_DB_IS_DELETED string - USE_DEFAULT_TEMPLATE bool - PREFIX_SERVER_GRPC string - PREFIX_CLIENT_GRPC string - PREFIX_CRUD string - PREFIX_MODEL string - PREFIX_TABLE string - COMMENT_MODEL_STRUCT string - TEXT_MODULE_GENERATED string - READY_ALIAS_FILENAME string - NEED_CREATE_UPDATE_EVERY_COLUMN bool + INCLUDE_TABLES string + EXCLUDE_TABLES string + TEMPLATE_FOLDERNAME string + TEMPLATE_FOLDERNAME_MODEL string + TEMPLATE_FOLDERNAME_DB string + TEMPLATE_FOLDERNAME_CRUD string + TEMPLATE_FOLDERNAME_TABLES string + TEMPLATE_FOLDERNAME_GRPC string + TEMPLATE_FOLDERNAME_GRPC_PROTO string + TEMPLATE_FOLDERNAME_GRPC_SERVER string + TEMPLATE_FOLDERNAME_GRPC_CLIENT string + TEMPLATE_FOLDERNAME_NRPC string + TEMPLATE_FOLDERNAME_NRPC_SERVER string + TEMPLATE_FOLDERNAME_NRPC_CLIENT string + TEMPLATE_FOLDERNAME_GRPC_NRPC string + TEMPLATE_SERVICE_NAME string + TEMPLATE_FOLDERNAME_CRUD_STARTER string + TEMPLATE_FOLDERNAME_ALIAS string + TEMPLATE_FOLDER_CRUD_FUNCTIONS string + TEMPLATE_FOLDERNAME_MAIN string + TEMPLATE_REPOSITORY_URL string + TEMPLATE_EXTERNAL_PROTO_FILENAME string + TEMPLATES_CRUD_FILENAME string + TEMPLATES_CRUD_TEST_FILENAME string + TEMPLATES_ALIAS_FILENAME string + TEMPLATES_CRUD_TABLE_UPDATE_FUNC_FILENAME string + TEMPLATES_CRUD_TABLE_UPDATE_FUNC_TEST_FILENAME string + TEMPLATES_CONVERT_ID_FILENAME string + TEMPLATES_CRUD_FUNCTIONS_RENAME_FILENAME string + TEMPLATES_MODEL_CRUD_DELETE_FUNCTIONS_FILENAME string + TEMPLATES_NAME_REPLACE_FILENAME string + TEMPLATES_NULLABLE_FILENAME string + TEMPLATES_CRUD_TABLE_UPDATE_FILENAME string + TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME string + TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME string + TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME string + NEED_CREATE_MODEL_STRUCT bool + NEED_CREATE_MODEL_CRUD bool + NEED_CREATE_DB bool + NEED_CREATE_DB_TEST bool + NEED_CREATE_DB_TABLES bool + NEED_CREATE_GRPC bool + NEED_CREATE_GRPC_SERVER_TEST bool + NEED_CREATE_GRPC_CLIENT_TEST bool + 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 + TEXT_TEMPLATE_TABLENAME string + HAS_IS_DELETED bool + READY_FOLDERNAME string + TEXT_DB_MODIFIED_AT string + TEXT_DB_CREATED_AT string + TEXT_DB_IS_DELETED string + USE_DEFAULT_TEMPLATE bool + PREFIX_SERVER_GRPC string + PREFIX_CLIENT_GRPC string + PREFIX_CRUD string + PREFIX_MODEL string + PREFIX_TABLE string + COMMENT_MODEL_STRUCT string + TEXT_MODULE_GENERATED string + READY_ALIAS_FILENAME string + NEED_CREATE_UPDATE_EVERY_COLUMN bool } func Getenv(Name string, IsRequired bool) string { @@ -426,6 +428,16 @@ func FillSettings() { s = Getenv(Name, true) Settings.TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME = s + // + Name = "TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME" + s = Getenv(Name, true) + Settings.TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME = s + + // + Name = "TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME" + s = Getenv(Name, true) + Settings.TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME = s + } // CurrentDirectory - возвращает текущую директорию ОС diff --git a/internal/create_files/grpc_client_tables/grpc_client_tables.go b/internal/create_files/grpc_client_tables/grpc_client_tables.go index 43223ee..e875494 100644 --- a/internal/create_files/grpc_client_tables/grpc_client_tables.go +++ b/internal/create_files/grpc_client_tables/grpc_client_tables.go @@ -372,27 +372,40 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error { DirTemplatesGRPC_Client := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() DirReadyGRPC_Client := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() + config.Settings.PREFIX_CLIENT_GRPC + TableName + micro.SeparatorFile() - FilenameTemplateGRPC_Client := DirTemplatesGRPC_Client + constants.GRPC_CLIENT_TABLE_UPDATE_FUNC_FILENAME + FilenameTemplateGRPC_ClientFunc := DirTemplatesGRPC_Client + constants.GRPC_CLIENT_TABLE_UPDATE_FUNC_FILENAME DirReadyTable := DirReadyGRPC_Client FilenameReadyGRPC_ClientUpdate := DirReadyTable + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_update.go" //создадим папку готовых файлов folders.CreateFolder(DirReadyTable) - bytes, err := os.ReadFile(FilenameTemplateGRPC_Client) + //читаем шаблон файла, только функции + bytes, err := os.ReadFile(FilenameTemplateGRPC_ClientFunc) if err != nil { - log.Panic("ReadFile() ", FilenameTemplateGRPC_Client, " error: ", err) + log.Panic("ReadFile() ", FilenameTemplateGRPC_ClientFunc, " error: ", err) } - TextGRPC_ClientUpdateFunc := string(bytes) + TextGRPC_Client_UpdateFunc := string(bytes) - TextGRPC_Client := "package " + config.Settings.PREFIX_CLIENT_GRPC + TableName + "\n\n" - TextGRPC_Client = TextGRPC_Client + `import ( - "context" - "time" - "github.com/ManyakRus/starter/log" -) + //читаем шаблон файла, без функций + FilenameTemplateCrud := DirTemplatesGRPC_Client + config.Settings.TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME + bytes, err = os.ReadFile(FilenameTemplateCrud) + if err != nil { + log.Panic("ReadFile() ", FilenameTemplateCrud, " error: ", err) + } + TextGRPC_Client := string(bytes) + TextGRPC_Client = TextGRPC_Client + "\n" -` + //заменим имя пакета на новое + TextGRPC_Client = create_files.ReplacePackageName(TextGRPC_Client, DirReadyTable) + + // TextGRPC_Client := "package " + config.Settings.PREFIX_CLIENT_GRPC + TableName + "\n\n" + // TextGRPC_Client = TextGRPC_Client + `import ( + // "context" + // "time" + // "github.com/ManyakRus/starter/log" + //) + // + //` //заменим импорты if config.Settings.USE_DEFAULT_TEMPLATE == true { @@ -418,7 +431,7 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error { } //создание текста - TextUpdateEveryColumn := FindTextUpdateEveryColumn(TextGRPC_ClientUpdateFunc, Table1) + TextUpdateEveryColumn := FindTextUpdateEveryColumn(TextGRPC_Client_UpdateFunc, Table1) // пустой файл не нужен if TextUpdateEveryColumn == "" { return err @@ -517,26 +530,39 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { DirTemplatesGRPC_Client := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() DirReadyGRPC_Client := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() + config.Settings.PREFIX_CLIENT_GRPC + TableName + micro.SeparatorFile() - FilenameTemplateGRPC_Client := DirTemplatesGRPC_Client + constants.GRPC_CLIENT_TABLE_UPDATE_FUNC_TEST_FILENAME + FilenameTemplateGRPC_ClientFunc := DirTemplatesGRPC_Client + constants.GRPC_CLIENT_TABLE_UPDATE_FUNC_TEST_FILENAME DirReadyTable := DirReadyGRPC_Client FilenameReadyGRPC_ClientUpdate := DirReadyTable + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_update_test.go" //создадим папку готовых файлов folders.CreateFolder(DirReadyTable) - bytes, err := os.ReadFile(FilenameTemplateGRPC_Client) + //читаем шаблон файла, только функции + bytes, err := os.ReadFile(FilenameTemplateGRPC_ClientFunc) if err != nil { - log.Panic("ReadFile() ", FilenameTemplateGRPC_Client, " error: ", err) + log.Panic("ReadFile() ", FilenameTemplateGRPC_ClientFunc, " error: ", err) } - TextGRPC_ClientUpdateFunc := string(bytes) + TextGRPC_Client_UpdateFunc := string(bytes) - TextGRPC_Client := "package " + config.Settings.PREFIX_CLIENT_GRPC + TableName + "\n\n" - TextGRPC_Client = TextGRPC_Client + `import ( - "testing" - "github.com/ManyakRus/starter/config_main" -) + //читаем шаблон файла, без функций + FilenameTemplateCrud := DirTemplatesGRPC_Client + config.Settings.TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME + bytes, err = os.ReadFile(FilenameTemplateCrud) + if err != nil { + log.Panic("ReadFile() ", FilenameTemplateCrud, " error: ", err) + } + TextGRPC_Client := string(bytes) + TextGRPC_Client = TextGRPC_Client + "\n" -` + //заменим имя пакета на новое + TextGRPC_Client = create_files.ReplacePackageName(TextGRPC_Client, DirReadyTable) + + // TextGRPC_Client := "package " + config.Settings.PREFIX_CLIENT_GRPC + TableName + "\n\n" + // TextGRPC_Client = TextGRPC_Client + `import ( + // "testing" + // "github.com/ManyakRus/starter/config_main" + //) + // + //` //заменим импорты //if config.Settings.USE_DEFAULT_TEMPLATE == true { @@ -550,7 +576,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { //} //создание текста - TextUpdateEveryColumn := FindTextUpdateEveryColumnTest(TextGRPC_ClientUpdateFunc, Table1) + TextUpdateEveryColumn := FindTextUpdateEveryColumnTest(TextGRPC_Client_UpdateFunc, Table1) // пустой файл не нужен if TextUpdateEveryColumn == "" { return err