diff --git a/bin/templates/configs_/settings.txt b/bin/templates/configs_/settings.txt index 5a6f439..6958f6a 100644 --- a/bin/templates/configs_/settings.txt +++ b/bin/templates/configs_/settings.txt @@ -151,6 +151,9 @@ PREFIX_TABLE="table_" #PREFIX_MODEL - filename prefix for view model files PREFIX_MODEL="" +#PREFIX_CLIENT_GRPC - filename prefix for grpc client files +PREFIX_CLIENT_GRPC="grpc_" + #COMMENT_MODEL_STRUCT - fill comments to every model structure COMMENT_MODEL_STRUCT="модель для таблицы " diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ index 8ac572e..fdd2db5 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ @@ -13,7 +13,7 @@ import ( "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" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc_nrpc" - "log" + "github.com/ManyakRus/starter/log" "sync" "time" ) diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_func.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_func.go_ new file mode 100644 index 0000000..16c10f0 --- /dev/null +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_func.go_ @@ -0,0 +1,34 @@ +// Read - изменяет 1 поле Name в базе данных +func (crud Crud_GRPC) Read(m *lawsuit_status_types.LawsuitStatusType) error { + var err error + + // подключение + grpc_client.Connect_GRPC_NRPC() + + // подготовка запроса + var versionModel = crud.GetVersionModel() + + Request := &grpc_proto.RequestId{} + Request.ID = m.ID + Request.VersionModel = versionModel + + ctxMain := context.Background() + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(grpc_constants.GetTimeoutSeconds())) + defer ctxCancelFunc() + + // запрос + if grpc_nrpc.NeedNRPC == true { + _, err = nrpc_client.Client.LawsuitStatusType_Read(Request) + } else { + _, err = grpc_client.Client.LawsuitStatusType_Read(ctx, Request) + } + if err != nil { + sError := err.Error() + if len(sError) >= len(grpc_constants.TEXT_ERROR_MODEL_VERSION) && sError[0:len(grpc_constants.TEXT_ERROR_MODEL_VERSION)] == grpc_constants.TEXT_ERROR_MODEL_VERSION { + log.Panic("table: ", TableName, " error: ", err) + } + return err + } + + return err +} diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_func_test.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_func_test.go_ new file mode 100644 index 0000000..8e67a24 --- /dev/null +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_update_func_test.go_ @@ -0,0 +1,14 @@ +func TestCrud_GRPC_Read(t *testing.T) { + config_main.LoadEnv() + grpc_client.Connect() + defer grpc_client.CloseConnection() + + crud := Crud_GRPC{} + Otvet := lawsuit_status_types.LawsuitStatusType{} + Otvet.ID = Postgres_ID_Test + err := crud.Read(&Otvet) + + if err != nil { + t.Error("TestRead() error: ", err) + } +} diff --git a/internal/config/config.go b/internal/config/config.go index ab99711..3156abc 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -62,11 +62,12 @@ type SettingsINI struct { 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 - PREFIX_TABLE string READY_ALIAS_FILENAME string NEED_CREATE_UPDATE_EVERY_COLUMN bool } @@ -179,6 +180,7 @@ func FillSettings() { Settings.TEMPLATES_ALIAS_FILENAME = os.Getenv("TEMPLATES_ALIAS_FILENAME") Settings.READY_ALIAS_FILENAME = os.Getenv("READY_ALIAS_FILENAME") Settings.NEED_CREATE_UPDATE_EVERY_COLUMN = BoolFromString(os.Getenv("NEED_CREATE_UPDATE_EVERY_COLUMN")) + Settings.PREFIX_CLIENT_GRPC = os.Getenv("PREFIX_CLIENT_GRPC") } diff --git a/internal/constants/constants.go b/internal/constants/constants.go index ea4098b..542841a 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -50,3 +50,6 @@ const MODEL_TABLE_UPDATE_FILENAME = "model_table_update.go_" const SERVER_GRPC_TABLE_UPDATE_FUNC_FILENAME = "server_grpc_table_update_func.go_" const SERVER_GRPC_TABLE_UPDATE_FUNC_TEST_FILENAME = "server_grpc_table_update_func_test.go_" + +const GRPC_CLIENT_TABLE_UPDATE_FUNC_FILENAME = "grpc_client_table_update_func.go_" +const GRPC_CLIENT_TABLE_UPDATE_FUNC_TEST_FILENAME = "grpc_client_table_update_func_test.go_" diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index 8692014..3fd358b 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -412,7 +412,8 @@ func FindCrudFunctionsURL() string { return Otvet } -func FindTextDefaultValue(Column1 *types.Column) string { +// FindTextDefaultGORMValue - возвращает значение по умолчанию для столбца Column1 для тегов в GORM +func FindTextDefaultGORMValue(Column1 *types.Column) string { var Otvet string ColumnName := Column1.Name @@ -444,6 +445,22 @@ func FindTextDefaultValue(Column1 *types.Column) string { return Otvet } +// FindTextDefaultValue - возвращает значение по умолчанию для типа +func FindTextDefaultValue(Type_go string) string { + var Otvet string + + switch Type_go { + case "string": + Otvet = `""` + case "int", "int32", "int64", "float32", "float64", "uint", "uint32", "uint64": + Otvet = "0" + case "time.Time": + Otvet = "time.Time{}" + } + + return Otvet +} + // FindURL_Alias - возвращает URL репозитория с пакетом "alias" func FindURL_Alias() string { Otvet := "" @@ -937,3 +954,29 @@ func FindTextProtobufRequest(TypeGo string) (string, string) { return Otvet, TextRequestFieldName } + +// ConvertIdToAlias - заменяет ID на Alias +func ConvertIdToAlias(Text string, Table1 *types.Table) string { + Otvet := Text + + TableName := Table1.Name + IDName, _ := FindPrimaryKeyNameType(Table1) + TextConvert, ok := types.MapConvertID[TableName+"."+IDName] + if ok == false { + return Otvet + } + + Otvet = strings.ReplaceAll(Otvet, "Request.ID", TextConvert+"(Request.ID)") + if TextConvert[:6] != "alias." { + return Otvet + } + + URL := FindURL_Alias() + if URL == "" { + return Otvet + } + + Otvet = AddImport(Otvet, URL) + + return Otvet +} diff --git a/internal/create_files/db_tables/db_tables.go b/internal/create_files/db_tables/db_tables.go index 6633fae..c6a416d 100644 --- a/internal/create_files/db_tables/db_tables.go +++ b/internal/create_files/db_tables/db_tables.go @@ -216,7 +216,7 @@ func FindTextColumn(TextModel string, Table1 *types.Table, Column1 *types.Column //Column1.TypeGo = Type_go TextDefaultValue := "" if Column1.IsIdentity == false { - TextDefaultValue = create_files.FindTextDefaultValue(Column1) + TextDefaultValue = create_files.FindTextDefaultGORMValue(Column1) } TextPrimaryKey := FindTextPrimaryKey(Column1.IsIdentity) Description := Column1.Description 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 968bfe9..2dee5a4 100644 --- a/internal/create_files/grpc_client_tables/grpc_client_tables.go +++ b/internal/create_files/grpc_client_tables/grpc_client_tables.go @@ -9,6 +9,7 @@ import ( "github.com/ManyakRus/starter/log" "github.com/ManyakRus/starter/micro" "os" + "sort" "strings" ) @@ -39,6 +40,24 @@ func CreateAllFiles(MapAll map[string]*types.Table) error { return err } } + + // + if config.Settings.NEED_CREATE_UPDATE_EVERY_COLUMN == true { + //файлы grpc_client update + err = CreateFilesUpdateEveryColumn(Table1) + if err != nil { + log.Error("CreateFilesUpdateEveryColumn() table: ", Table1.Name, " error: ", err) + return err + } + + //тестовые файлы grpc_client update + err = CreateTestFilesUpdateEveryColumn(Table1) + if err != nil { + log.Error("CreateTestFilesUpdateEveryColumn() table: ", Table1.Name, " error: ", err) + return err + } + + } } return err @@ -333,3 +352,261 @@ func DeleteFuncTestFind_byExtID(Text, ModelName string, Table1 *types.Table) str return Otvet } + +// CreateFilesUpdateEveryColumn - создаёт 1 файл в папке grpc_server +func CreateFilesUpdateEveryColumn(Table1 *types.Table) error { + var err error + + TableName := strings.ToLower(Table1.Name) + + //чтение файлов + DirBin := micro.ProgramDir_bin() + DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() + DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile() + 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 + DirReadyTable := DirReadyGRPC_Client + FilenameReadyGRPC_ClientUpdate := DirReadyTable + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_update.go" + + //создадим папку готовых файлов + folders.CreateFolder(DirReadyTable) + + bytes, err := os.ReadFile(FilenameTemplateGRPC_Client) + if err != nil { + log.Panic("ReadFile() ", FilenameTemplateGRPC_Client, " error: ", err) + } + TextGRPCServerUpdateFunc := string(bytes) + + TextGRPC_Client := "package " + config.Settings.TEMPLATE_FOLDERNAME_GRPC + "\n\n" + TextGRPC_Client = TextGRPC_Client + `import ( + "context" + "time" + "github.com/ManyakRus/starter/log" + ) + +` + + //заменим импорты + //if config.Settings.USE_DEFAULT_TEMPLATE == true { + ProtoURL := create_files.FindProtoURL() + TextGRPC_Client = create_files.AddImport(TextGRPC_Client, ProtoURL) + + GRPCClientURL := create_files.FindGRPClientURL() + TextGRPC_Client = create_files.AddImport(TextGRPC_Client, GRPCClientURL) + + GRPCConstantsURL := create_files.FindGRPCConstantsURL() + TextGRPC_Client = create_files.AddImport(TextGRPC_Client, GRPCConstantsURL) + + GRPC_NRPC_URL := create_files.Find_GRPC_NRPC_URL() + TextGRPC_Client = create_files.AddImport(TextGRPC_Client, GRPC_NRPC_URL) + + NRPCClientURL := create_files.FindNRPClientURL() + TextGRPC_Client = create_files.AddImport(TextGRPC_Client, NRPCClientURL) + + ModelTableURL := create_files.FindModelTableURL(TableName) + TextGRPC_Client = create_files.AddImport(TextGRPC_Client, ModelTableURL) + + TextGRPC_Client = create_files.ConvertIdToAlias(TextGRPC_Client, Table1) + //} + + //создание текста + TextUpdateEveryColumn := FindTextUpdateEveryColumn(TextGRPCServerUpdateFunc, Table1) + // пустой файл не нужен + if TextUpdateEveryColumn == "" { + return err + } + + //ModelName := Table1.NameGo + //TextGRPC_Client = strings.ReplaceAll(TextGRPC_Client, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) + //TextGRPC_Client = strings.ReplaceAll(TextGRPC_Client, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) + TextGRPC_Client = TextGRPC_Client + TextUpdateEveryColumn + + TextGRPC_Client = config.Settings.TEXT_MODULE_GENERATED + TextGRPC_Client + + //удаление пустого импорта + TextGRPC_Client = create_files.DeleteEmptyImport(TextGRPC_Client) + TextGRPC_Client = create_files.DeleteEmptyLines(TextGRPC_Client) + + //запись файла + err = os.WriteFile(FilenameReadyGRPC_ClientUpdate, []byte(TextGRPC_Client), constants.FILE_PERMISSIONS) + + return err +} + +// FindTextUpdateEveryColumn - возвращает текст для всех таблиц +func FindTextUpdateEveryColumn(TextGRPCServerUpdateFunc string, Table1 *types.Table) string { + Otvet := "" + + //сортировка по названию таблиц + keys := make([]string, 0, len(Table1.MapColumns)) + for k := range Table1.MapColumns { + keys = append(keys, k) + } + sort.Strings(keys) + + //найдём новый текст для каждой таблицы + for _, key1 := range keys { + Column1, ok := Table1.MapColumns[key1] + if ok == false { + log.Panic("FindTextProtoTable1_UpdateEveryColumn() Table1.MapColumns[key1] = false") + } + if create_files.Is_Common_Сolumn(Column1) == true { + continue + } + + TextColumn1 := FindTextUpdateEveryColumn1(TextGRPCServerUpdateFunc, Table1, Column1) + Otvet = Otvet + TextColumn1 + "\n\n" + + } + + return Otvet +} + +// FindTextUpdateEveryColumn1 - возвращает текст для одной таблицы +func FindTextUpdateEveryColumn1(TextGRPCServerUpdateFunc string, Table1 *types.Table, Column1 *types.Column) string { + Otvet := TextGRPCServerUpdateFunc + + ModelName := Table1.NameGo + ColumnName := Column1.NameGo + FuncName := "Update_" + ColumnName + TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Column1.TypeGo) + + Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL+"_Read", ModelName+"_"+FuncName) + Otvet = strings.ReplaceAll(Otvet, " Read ", " "+FuncName+" ") + Otvet = strings.ReplaceAll(Otvet, " Read(", " "+FuncName+"(") + Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) + Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) + Otvet = strings.ReplaceAll(Otvet, "grpc_proto.RequestId", "grpc_proto."+TextRequest) + Otvet = strings.ReplaceAll(Otvet, "ColumnName", ColumnName) + Otvet = strings.ReplaceAll(Otvet, "Model.ID", "Model."+ColumnName) + Otvet = strings.ReplaceAll(Otvet, "Request.ID", "Request."+TextRequestFieldName) + Otvet = strings.ReplaceAll(Otvet, " Name ", " "+ColumnName+" ") + Otvet = strings.ReplaceAll(Otvet, "m.ID", "m."+ColumnName) + + return Otvet +} + +// CreateTestFilesUpdateEveryColumn - создаёт 1 файл в папке grpc_server +func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { + var err error + + TableName := strings.ToLower(Table1.Name) + + //чтение файлов + DirBin := micro.ProgramDir_bin() + DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() + DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile() + 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 + DirReadyTable := DirReadyGRPC_Client + FilenameReadyGRPC_ClientUpdate := DirReadyTable + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_update_test.go" + + //создадим папку готовых файлов + folders.CreateFolder(DirReadyTable) + + bytes, err := os.ReadFile(FilenameTemplateGRPC_Client) + if err != nil { + log.Panic("ReadFile() ", FilenameTemplateGRPC_Client, " error: ", err) + } + TextGRPCServerUpdateFunc := string(bytes) + + TextGRPCClient := "package " + config.Settings.TEMPLATE_FOLDERNAME_GRPC + "\n\n" + TextGRPCClient = TextGRPCClient + `import ( + "testing" + "github.com/ManyakRus/starter/config_main" + ) + +` + + //заменим импорты + //if config.Settings.USE_DEFAULT_TEMPLATE == true { + GRPCClientURL := create_files.FindGRPClientURL() + TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPCClientURL) + + ModelTableURL := create_files.FindModelTableURL(TableName) + TextGRPCClient = create_files.AddImport(TextGRPCClient, ModelTableURL) + + TextGRPCClient = create_files.ConvertIdToAlias(TextGRPCClient, Table1) + //} + + //создание текста + TextUpdateEveryColumn := FindTextUpdateEveryColumnTest(TextGRPCServerUpdateFunc, Table1) + // пустой файл не нужен + if TextUpdateEveryColumn == "" { + return err + } + //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 = TextGRPCClient + TextUpdateEveryColumn + + TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient + + //удаление пустого импорта + TextGRPCClient = create_files.DeleteEmptyImport(TextGRPCClient) + TextGRPCClient = create_files.DeleteEmptyLines(TextGRPCClient) + + //запись файла + err = os.WriteFile(FilenameReadyGRPC_ClientUpdate, []byte(TextGRPCClient), constants.FILE_PERMISSIONS) + + return err +} + +// FindTextUpdateEveryColumnTest - возвращает текст для всех таблиц +func FindTextUpdateEveryColumnTest(TextGRPCServerUpdateFunc string, Table1 *types.Table) string { + Otvet := "" + + //сортировка по названию таблиц + keys := make([]string, 0, len(Table1.MapColumns)) + for k := range Table1.MapColumns { + keys = append(keys, k) + } + sort.Strings(keys) + + //найдём новый текст для каждой таблицы + for _, key1 := range keys { + Column1, ok := Table1.MapColumns[key1] + if ok == false { + log.Panic("FindTextProtoTable1_UpdateEveryColumn() Table1.MapColumns[key1] = false") + } + if create_files.Is_Common_Сolumn(Column1) == true { + continue + } + + TextColumn1 := FindTextUpdateEveryColumnTest1(TextGRPCServerUpdateFunc, Table1, Column1) + Otvet = Otvet + TextColumn1 + "\n\n" + + } + + return Otvet +} + +// FindTextUpdateEveryColumnTest1 - возвращает текст для одной таблицы +func FindTextUpdateEveryColumnTest1(TextGRPCServerUpdateFunc string, Table1 *types.Table, Column1 *types.Column) string { + Otvet := TextGRPCServerUpdateFunc + + ModelName := Table1.NameGo + ColumnName := Column1.NameGo + FuncName := "Update_" + ColumnName + TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Column1.TypeGo) + DefaultValue := create_files.FindTextDefaultValue(Column1.TypeGo) + + Otvet = strings.ReplaceAll(Otvet, " TestCrud_GRPC_Read(", " TestCrud_GRPC_"+FuncName+"(") + Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) + Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) + Otvet = strings.ReplaceAll(Otvet, "grpc_proto.RequestId", "grpc_proto."+TextRequest) + Otvet = strings.ReplaceAll(Otvet, "ColumnName", ColumnName) + Otvet = strings.ReplaceAll(Otvet, "Model.ID", "Model."+ColumnName) + Otvet = strings.ReplaceAll(Otvet, "Request.ID", "Request."+TextRequestFieldName) + Otvet = strings.ReplaceAll(Otvet, "Otvet.ID", "Otvet."+ColumnName) + Otvet = strings.ReplaceAll(Otvet, "Postgres_ID_Test", DefaultValue) + Otvet = strings.ReplaceAll(Otvet, "TestRead(", "Test"+FuncName+"(") + Otvet = strings.ReplaceAll(Otvet, "Otvet.ID == 0", "Otvet."+ColumnName+" == "+DefaultValue) + Otvet = strings.ReplaceAll(Otvet, "error: ID =0", "error: "+ColumnName+" ="+DefaultValue) + + return Otvet +} 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 868f59f..eed6c08 100644 --- a/internal/create_files/grpc_server_tables/grpc_server_tables.go +++ b/internal/create_files/grpc_server_tables/grpc_server_tables.go @@ -52,7 +52,7 @@ func CreateAllFiles(MapAll map[string]*types.Table) error { //тестовые файлы grpc_server update if config.Settings.NEED_CREATE_GRPC_SERVER_TEST == true { - err = CreateFilesUpdateEveryColumnTest(Table1) + err = CreateTestFilesUpdateEveryColumn(Table1) if err != nil { log.Error("CreateTestFiles() table: ", Table1.Name, " error: ", err) return err @@ -115,7 +115,7 @@ func CreateFiles(Table1 *types.Table) error { TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer if config.Settings.USE_DEFAULT_TEMPLATE == true { - TextGRPCServer = ConvertID(TextGRPCServer, Table1) + TextGRPCServer = create_files.ConvertIdToAlias(TextGRPCServer, Table1) //замена импортов на новые URL //TextGRPCServer = create_files.ReplaceServiceURLImports(TextGRPCServer) @@ -338,32 +338,6 @@ func DeleteFuncTestFind_byExtID(Text string, Table1 *types.Table) string { return Otvet } -// ConvertID - заменяет ID на Alias -func ConvertID(Text string, Table1 *types.Table) string { - Otvet := Text - - TableName := Table1.Name - IDName, _ := create_files.FindPrimaryKeyNameType(Table1) - TextConvert, ok := types.MapConvertID[TableName+"."+IDName] - if ok == false { - return Otvet - } - - Otvet = strings.ReplaceAll(Otvet, "Request.ID", TextConvert+"(Request.ID)") - if TextConvert[:6] != "alias." { - return Otvet - } - - URL := create_files.FindURL_Alias() - if URL == "" { - return Otvet - } - - Otvet = create_files.AddImport(Otvet, URL) - - return Otvet -} - // CreateFilesUpdateEveryColumn - создаёт 1 файл в папке grpc_server func CreateFilesUpdateEveryColumn(Table1 *types.Table) error { var err error @@ -408,11 +382,16 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error { ModelURL := create_files.FindModelURL() TextGRPCServer = create_files.AddImport(TextGRPCServer, ModelURL) - TextGRPCServer = ConvertID(TextGRPCServer, Table1) + TextGRPCServer = create_files.ConvertIdToAlias(TextGRPCServer, Table1) //} //создание текста TextUpdateEveryColumn := FindTextUpdateEveryColumn(TextGRPCServerUpdateFunc, Table1) + // пустой файл не нужен + if TextUpdateEveryColumn == "" { + return err + } + //ModelName := Table1.NameGo //TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) //TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) @@ -479,8 +458,8 @@ func FindTextUpdateEveryColumn1(TextGRPCServerUpdateFunc string, Table1 *types.T return Otvet } -// CreateFilesUpdateEveryColumnTest - создаёт 1 файл в папке grpc_server -func CreateFilesUpdateEveryColumnTest(Table1 *types.Table) error { +// CreateTestFilesUpdateEveryColumn - создаёт 1 файл в папке grpc_server +func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { var err error //чтение файлов @@ -526,11 +505,15 @@ func CreateFilesUpdateEveryColumnTest(Table1 *types.Table) error { CrudStarterURL := create_files.FindCrudStarterURL() TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudStarterURL) - TextGRPCServer = ConvertID(TextGRPCServer, Table1) + TextGRPCServer = create_files.ConvertIdToAlias(TextGRPCServer, Table1) //} //создание текста TextUpdateEveryColumn := FindTextUpdateEveryColumnTest(TextGRPCServerUpdateFunc, Table1) + // пустой файл не нужен + if TextUpdateEveryColumn == "" { + return err + } //ModelName := Table1.NameGo //TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) //TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) diff --git a/internal/create_files/model_tables/model_tables.go b/internal/create_files/model_tables/model_tables.go index 8f348c1..3c1ad06 100644 --- a/internal/create_files/model_tables/model_tables.go +++ b/internal/create_files/model_tables/model_tables.go @@ -316,7 +316,7 @@ func FindTextColumn(TextModel string, Table1 *types.Table, Column1 *types.Column //Column1.TypeGo = Type_go TextDefaultValue := "" if Column1.IsIdentity == false { - TextDefaultValue = create_files.FindTextDefaultValue(Column1) + TextDefaultValue = create_files.FindTextDefaultGORMValue(Column1) } TextPrimaryKey := FindTextPrimaryKey(Column1.IsIdentity) Description := Column1.Description