From e24027043ee4c5d8a9aa933fb3f1743d7bbc7477 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Tue, 12 Mar 2024 17:19:36 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20ReadFrom?= =?UTF-8?q?Cache()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/templates/configs_/settings.txt | 4 +- .../grpc_client/grpc_client_table_cache.go_ | 13 ++- .../grpc_client_table_cache_test.go_ | 3 +- .../grpc_client_table_update_test.go_ | 108 ------------------ .../db_crud_tables/db_crud_tables.go | 21 ++-- .../grpc_client_tables/grpc_client_tables.go | 25 +++- .../grpc_server_tables/grpc_server_tables.go | 9 +- 7 files changed, 50 insertions(+), 133 deletions(-) diff --git a/bin/templates/configs_/settings.txt b/bin/templates/configs_/settings.txt index 8201f02..39d8843 100644 --- a/bin/templates/configs_/settings.txt +++ b/bin/templates/configs_/settings.txt @@ -226,5 +226,5 @@ NEED_CREATE_CACHE_TEST_FILES=true #TEMPLATES_GRPC_CLIENT_TABLES_CACHE_FILENAME - short filename of "grpc_client_table_cache.go_" file TEMPLATES_GRPC_CLIENT_TABLES_CACHE_FILENAME="grpc_client_table_cache.go_" -#TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME - short filename of "grpc_client_table_cache.go_" file -TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME="grpc_client_table_cache.go_" \ No newline at end of file +#TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME - short filename of "grpc_client_table_cache_test.go_" file +TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME="grpc_client_table_cache_test.go_" \ No newline at end of file diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_cache.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_cache.go_ index 86d425b..fa0635f 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_cache.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_cache.go_ @@ -14,7 +14,8 @@ import ( ) // ReadFromCache - возвращает модель из БД -func (crud Crud_GRPC) ReadFromCache(m *lawsuit_status_types.LawsuitStatusType) error { +func (crud Crud_GRPC) ReadFromCache(ID int64) (lawsuit_status_types.LawsuitStatusType, error) { + Otvet := lawsuit_status_types.LawsuitStatusType{} var err error // подключение @@ -24,7 +25,7 @@ func (crud Crud_GRPC) ReadFromCache(m *lawsuit_status_types.LawsuitStatusType) e var versionModel = crud.GetVersionModel() Request := &grpc_proto.RequestId{} - Request.ID = int64(m.ID) + Request.ID = ID Request.VersionModel = versionModel ctxMain := context.Background() @@ -42,15 +43,15 @@ func (crud Crud_GRPC) ReadFromCache(m *lawsuit_status_types.LawsuitStatusType) e if grpc_client.IsErrorModelVersion(err) == true { log.Panic(err) } - return err + return Otvet, err } // ответ sModel := Response.ModelString - err = json.Unmarshal([]byte(sModel), m) + err = json.Unmarshal([]byte(sModel), &Otvet) if err != nil { - return err + return Otvet, err } - return err + return Otvet, err } diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_cache_test.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_cache_test.go_ index f3fdd47..981302f 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_cache_test.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_cache_test.go_ @@ -14,8 +14,7 @@ func TestReadFromCache(t *testing.T) { crud := Crud_GRPC{} Otvet := lawsuit_status_types.LawsuitStatusType{} - Otvet.ID = Postgres_ID_Test - err := crud.ReadFromCache(&Otvet) + Otvet, err := crud.ReadFromCache(Postgres_ID_Test) if err != nil { t.Error("ReadFromCache() error: ", err) 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_ index a863aaf..1553372 100644 --- 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_ @@ -6,111 +6,3 @@ import ( "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/create_files/db_crud_tables/db_crud_tables.go b/internal/create_files/db_crud_tables/db_crud_tables.go index 6f090cb..f25fe5a 100644 --- a/internal/create_files/db_crud_tables/db_crud_tables.go +++ b/internal/create_files/db_crud_tables/db_crud_tables.go @@ -54,7 +54,7 @@ func CreateAllFiles(MapAll map[string]*types.Table) error { } //тестовые файлы db update - err = CreateTestFilesUpdateEveryColumn(Table1) + err = CreateFilesUpdateEveryColumnTest(Table1) if err != nil { log.Error("CreateTestFiles() table: ", Table1.Name, " error: ", err) return err @@ -637,8 +637,8 @@ func FindTextUpdateEveryColumn1(TextCrudUpdateFunc string, Table1 *types.Table, return Otvet } -// CreateTestFilesUpdateEveryColumn - создаёт 1 файл в папке grpc_client -func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { +// CreateFilesUpdateEveryColumnTest - создаёт 1 файл в папке grpc_client +func CreateFilesUpdateEveryColumnTest(Table1 *types.Table) error { var err error TableName := strings.ToLower(Table1.Name) @@ -692,7 +692,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { ModelTableURL := create_files.FindModelTableURL(TableName) TextCrud = create_files.AddImport(TextCrud, ModelTableURL) - TextCrud = create_files.ConvertRequestIdToAlias(TextCrud, Table1) + //TextCrud = create_files.ConvertRequestIdToAlias(TextCrud, Table1) } //создание текста @@ -874,11 +874,11 @@ func CreateFilesCacheTest(Table1 *types.Table) error { if config.Settings.USE_DEFAULT_TEMPLATE == true { TextCache = create_files.DeleteTemplateRepositoryImports(TextCache) - DBConstantsURL := create_files.FindDBConstantsURL() - TextCache = create_files.AddImport(TextCache, DBConstantsURL) - - ModelTableURL := create_files.FindModelTableURL(TableName) - TextCache = create_files.AddImport(TextCache, ModelTableURL) + //DBConstantsURL := create_files.FindDBConstantsURL() + //TextCache = create_files.AddImport(TextCache, DBConstantsURL) + // + //ModelTableURL := create_files.FindModelTableURL(TableName) + //TextCache = create_files.AddImport(TextCache, ModelTableURL) //TextCache = create_files.ConvertRequestIdToAlias(TextCache, Table1) } @@ -895,6 +895,9 @@ func CreateFilesCacheTest(Table1 *types.Table) error { //удаление пустых строк TextCache = create_files.DeleteEmptyLines(TextCache) + //SkipNow() если нет строк в БД + TextCache = create_files.AddSkipNow(TextCache, Table1) + //запись файла err = os.WriteFile(FilenameReadyCache, []byte(TextCache), constants.FILE_PERMISSIONS) 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 5e1f16a..af79f5e 100644 --- a/internal/create_files/grpc_client_tables/grpc_client_tables.go +++ b/internal/create_files/grpc_client_tables/grpc_client_tables.go @@ -778,8 +778,30 @@ func CreateFiles_GRPC_Client_Cache_Test(Table1 *types.Table) error { ModelTableName := create_files.FindModelTableURL(TableName) TextGRPCClient = create_files.AddImport(TextGRPCClient, ModelTableName) + + ////proto + //RepositoryGRPCProtoURL := create_files.FindProtoURL() + //TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCProtoURL) + // + ////nrpc client + //RepositoryNRPCClientlURL := create_files.FindNRPClientURL() + //TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryNRPCClientlURL) + // + ////grpc_nrpc + //GRPC_NRPC_URL := create_files.Find_GRPC_NRPC_URL() + //TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPC_NRPC_URL) + // + ////constants GRPC + //RepositoryGRPCConstantsURL := create_files.FindGRPCConstantsURL() + //TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCConstantsURL) } + //создание текста + ModelName := Table1.NameGo + TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) + TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) + TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient + // замена ID на PrimaryKey TextGRPCClient = create_files.ReplacePrimaryKeyID(TextGRPCClient, Table1) @@ -795,9 +817,6 @@ func CreateFiles_GRPC_Client_Cache_Test(Table1 *types.Table) error { //удаление пустых строк TextGRPCClient = create_files.DeleteEmptyLines(TextGRPCClient) - //добавим комментарий в начало файла - TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient - //запись файла err = os.WriteFile(FilenameReadyCache, []byte(TextGRPCClient), constants.FILE_PERMISSIONS) diff --git a/internal/create_files/grpc_server_tables/grpc_server_tables.go b/internal/create_files/grpc_server_tables/grpc_server_tables.go index 0c5d13f..33f3329 100644 --- a/internal/create_files/grpc_server_tables/grpc_server_tables.go +++ b/internal/create_files/grpc_server_tables/grpc_server_tables.go @@ -750,13 +750,16 @@ func CreateFilesCacheTest(Table1 *types.Table) error { TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer - if config.Settings.USE_DEFAULT_TEMPLATE == true { - TextGRPCServer = create_files.ConvertRequestIdToAlias(TextGRPCServer, Table1) - } + //if config.Settings.USE_DEFAULT_TEMPLATE == true { + // TextGRPCServer = create_files.ConvertRequestIdToAlias(TextGRPCServer, Table1) + //} //удаление пустого импорта TextGRPCServer = create_files.DeleteEmptyImport(TextGRPCServer) + //SkipNow() + TextGRPCServer = create_files.AddSkipNow(TextGRPCServer, Table1) + //запись файла err = os.WriteFile(FilenameReadyCache, []byte(TextGRPCServer), constants.FILE_PERMISSIONS)