diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func.go_ index c2545a8..6017661 100644 --- a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func.go_ +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func.go_ @@ -1,5 +1,5 @@ -// LawsuitStatusType_Read - изменяет колонку ColumnName в базе данных -func (s *ServerGRPC) LawsuitStatusType_Read(ctx context.Context, Request *grpc_proto.RequestId) (*grpc_proto.ResponseEmpty, error) { +// LawsuitStatusType_Update - изменяет колонку ColumnName в базе данных +func (s *ServerGRPC) LawsuitStatusType_Update(ctx context.Context, Request *grpc_proto.RequestId) (*grpc_proto.ResponseEmpty, error) { var Otvet grpc_proto.ResponseEmpty var err error @@ -20,7 +20,8 @@ func (s *ServerGRPC) LawsuitStatusType_Read(ctx context.Context, Request *grpc_p //запрос в БД Model := &lawsuit_status_types.LawsuitStatusType{} Model.ID = Request.ID - err = Model.Read() + Model.ColumnName = Request.FieldName + err = Model.Update() if err != nil { return &Otvet, err } diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func_test.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func_test.go_ index 3aa8193..1d39a64 100644 --- a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func_test.go_ +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_func_test.go_ @@ -1,18 +1,29 @@ -func Test_server_LawsuitStatusType_Read(t *testing.T) { +func Test_server_LawsuitStatusType_Update(t *testing.T) { config_main.LoadEnv() crud_starter.InitCrudTransport_DB() + server1 := &ServerGRPC{} ctx := context.Background() + + //прочитаем из БД Request := grpc_proto.RequestId{} Request.ID = LawsuitStatusType_ID_Test Request.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion() - - server1 := &ServerGRPC{} - Otvet, err := server1.LawsuitStatusType_Read(ctx, &Request) + Model, err := server1.LawsuitStatusType_Read(ctx, &Request) if err != nil { - t.Error("Test_server_LawsuitStatusType_Read() error: ", err) + t.Error("Test_server_LawsuitStatusType_Update() Read() error: ", err) } if Otvet.ModelString == "" { - t.Error("Test_server_LawsuitStatusType_Read() error: ModelString=''") + t.Error("Test_server_LawsuitStatusType_Update() Read() error: ModelString=''") + } + + //запишем в БД это же значение + Request := grpc_proto.RequestString{} + Request.ID = LawsuitStatusType_ID_Test + Request.ColumnName = Model.ColumnName + Request.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion() + _, err := server1.LawsuitStatusType_Update(ctx, &Request) + if err != nil { + t.Error("Test_server_LawsuitStatusType_Update() Update() error: ", err) } } \ No newline at end of file diff --git a/bin/templates/pkg/db/crud/crud_table_update_func_test.go_ b/bin/templates/pkg/db/crud/crud_table_update_func_test.go_ index 6cb58c9..2eccf51 100644 --- a/bin/templates/pkg/db/crud/crud_table_update_func_test.go_ +++ b/bin/templates/pkg/db/crud/crud_table_update_func_test.go_ @@ -1,16 +1,24 @@ -func TestRead(t *testing.T) { +func TestUpdate(t *testing.T) { config_main.LoadEnv() postgres_gorm.Connect() defer postgres_gorm.CloseConnection() + //прочитаем из БД crud := Crud_DB{} - Otvet := lawsuit_status_types.LawsuitStatusType{} - Otvet.ID = Postgres_ID_Test - Otvet.ColumnName = DefaultValue - err := crud.Read(&Otvet) + Model := lawsuit_status_types.LawsuitStatusType{} + Model.ID = Postgres_ID_Test + err := crud.Read(&Model) if err != nil { - t.Error("TestRead() error: ", err) + t.Error("TestUpdate() Read() error: ", err) } + //запишем в БД это же значение + Otvet := lawsuit_status_types.LawsuitStatusType{} + Otvet.ID = Postgres_ID_Test + Otvet.ColumnName = Model.ColumnName + err = crud.Update(&Otvet) + if err != nil { + t.Error("TestUpdate() Update() error: ", err) + } } 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_ index 16c10f0..15c97f2 100644 --- 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_ @@ -1,5 +1,5 @@ -// Read - изменяет 1 поле Name в базе данных -func (crud Crud_GRPC) Read(m *lawsuit_status_types.LawsuitStatusType) error { +// Update - изменяет 1 поле Name в базе данных +func (crud Crud_GRPC) Update(m *lawsuit_status_types.LawsuitStatusType) error { var err error // подключение @@ -10,6 +10,7 @@ func (crud Crud_GRPC) Read(m *lawsuit_status_types.LawsuitStatusType) error { Request := &grpc_proto.RequestId{} Request.ID = m.ID + Request.FieldName = m.ColumnName Request.VersionModel = versionModel ctxMain := context.Background() @@ -18,9 +19,9 @@ func (crud Crud_GRPC) Read(m *lawsuit_status_types.LawsuitStatusType) error { // запрос if grpc_nrpc.NeedNRPC == true { - _, err = nrpc_client.Client.LawsuitStatusType_Read(Request) + _, err = nrpc_client.Client.LawsuitStatusType_Update(Request) } else { - _, err = grpc_client.Client.LawsuitStatusType_Read(ctx, Request) + _, err = grpc_client.Client.LawsuitStatusType_Update(ctx, Request) } if err != nil { sError := err.Error() 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_ index 8e67a24..eefbe42 100644 --- 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_ @@ -1,14 +1,26 @@ -func TestCrud_GRPC_Read(t *testing.T) { +func TestCrud_GRPC_Update(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) + + //прочитаем из БД + Model := lawsuit_status_types.LawsuitStatusType{} + Model.ID = Postgres_ID_Test + err := crud.LawsuitStatusType_Read(&Model) if err != nil { - t.Error("TestRead() error: ", err) + t.Error("TestCrud_GRPC_Update() Read() error: ", err) + } + + //запишем в БД это же значение + Otvet := lawsuit_status_types.LawsuitStatusType{} + Otvet.ID = Model.ID + Otvet.ColumnName = Model.ColumnName + err = crud.LawsuitStatusType_Update(&Otvet) + if err != nil { + t.Error("TestCrud_GRPC_Update() Update() error: ", err) } } diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index b7dfec7..c50ac96 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -957,6 +957,53 @@ func FindTextProtobufRequest(TypeGo string) (string, string) { return Otvet, TextRequestFieldName } +// FindTextProtobufRequest_ID_Type - возвращает имя message из .proto для двух параметров ID + Type,в зависимости от типа, а также название поля +func FindTextProtobufRequest_ID_Type(TypeGo string) (string, string) { + Otvet := "RequestID" + TextRequestFieldName := "ID" + + switch TypeGo { + case "int", "int64": + { + Otvet = "Request_ID_Int64" + TextRequestFieldName = "Int64" + } + + case "int32": + { + Otvet = "Request_ID_Int32" + TextRequestFieldName = "Int32" + } + case "string": + { + Otvet = "Request_ID_String" + TextRequestFieldName = "StringFind" + } + case "time.Time": + { + Otvet = "Request_ID_Date" + TextRequestFieldName = "Date" + } + case "float32": + { + Otvet = "Request_ID_Float32" + TextRequestFieldName = "Float32" + } + case "float64": + { + Otvet = "Request_ID_Float64" + TextRequestFieldName = "Float64" + } + case "bool": + { + Otvet = "Request_ID_Bool" + TextRequestFieldName = "Bool" + } + } + + return Otvet, TextRequestFieldName +} + // ConvertIdToAlias - заменяет ID на Alias func ConvertIdToAlias(Text string, Table1 *types.Table) string { Otvet := Text 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 db57e1b..41881e3 100644 --- a/internal/create_files/db_crud_tables/db_crud_tables.go +++ b/internal/create_files/db_crud_tables/db_crud_tables.go @@ -695,17 +695,15 @@ func FindTextUpdateEveryColumnTest1(TextCrudUpdateFunc string, Table1 *types.Tab 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.Name", "Otvet."+ColumnName) //Otvet = strings.ReplaceAll(Otvet, "Postgres_ID_Test", DefaultValue) - Otvet = strings.ReplaceAll(Otvet, "TestRead(", "Test"+FuncName+"(") - Otvet = strings.ReplaceAll(Otvet, ".Read(", "."+FuncName+"(") + Otvet = strings.ReplaceAll(Otvet, "TestUpdate(", "Test"+FuncName+"(") + Otvet = strings.ReplaceAll(Otvet, ".Update(", "."+FuncName+"(") Otvet = strings.ReplaceAll(Otvet, " DefaultValue", " "+DefaultValue) return Otvet 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 8baf3aa..794305f 100644 --- a/internal/create_files/grpc_client_tables/grpc_client_tables.go +++ b/internal/create_files/grpc_client_tables/grpc_client_tables.go @@ -471,19 +471,17 @@ func FindTextUpdateEveryColumn1(TextGRPC_ClientUpdateFunc string, Table1 *types. ModelName := Table1.NameGo ColumnName := Column1.NameGo FuncName := "Update_" + ColumnName - TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Column1.TypeGo) + TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest_ID_Type(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+"_Update", ModelName+"_"+FuncName) + Otvet = strings.ReplaceAll(Otvet, " Update ", " "+FuncName+" ") + Otvet = strings.ReplaceAll(Otvet, " Update(", " "+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) + Otvet = strings.ReplaceAll(Otvet, "m.ColumnName", "m."+ColumnName) + Otvet = strings.ReplaceAll(Otvet, "Request.FieldName", "Request."+TextRequestFieldName) return Otvet } @@ -592,21 +590,18 @@ func FindTextUpdateEveryColumnTest1(TextGRPC_ClientUpdateFunc string, Table1 *ty ModelName := Table1.NameGo ColumnName := Column1.NameGo FuncName := "Update_" + ColumnName - TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Column1.TypeGo) + TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest_ID_Type(Column1.TypeGo) DefaultValue := create_files.FindTextDefaultValue(Column1.TypeGo) - Otvet = strings.ReplaceAll(Otvet, " TestCrud_GRPC_Read(", " TestCrud_GRPC_"+FuncName+"(") + Otvet = strings.ReplaceAll(Otvet, "TestCrud_GRPC_Update(", "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) + Otvet = strings.ReplaceAll(Otvet, "_Update(", "_"+FuncName+"(") 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 eed6c08..4acae25 100644 --- a/internal/create_files/grpc_server_tables/grpc_server_tables.go +++ b/internal/create_files/grpc_server_tables/grpc_server_tables.go @@ -363,7 +363,7 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error { } TextGRPCServerUpdateFunc := string(bytes) - TextGRPCServer := "package " + config.Settings.TEMPLATE_FOLDERNAME_GRPC + "\n\n" + TextGRPCServer := "package " + config.Settings.PREFIX_CLIENT_GRPC + TableName + "\n\n" TextGRPCServer = TextGRPCServer + `import ( "context" "github.com/ManyakRus/starter/micro" @@ -445,15 +445,16 @@ func FindTextUpdateEveryColumn1(TextGRPCServerUpdateFunc string, Table1 *types.T ModelName := Table1.NameGo ColumnName := Column1.NameGo FuncName := "Update_" + ColumnName - TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Column1.TypeGo) + TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest_ID_Type(Column1.TypeGo) - Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL+"_Read", ModelName+"_"+FuncName) + Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL+"_Update", ModelName+"_"+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, "Request.FieldName", "Request."+TextRequestFieldName) + Otvet = strings.ReplaceAll(Otvet, "Model.ColumnName", "Model."+ColumnName) 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, "Model.Update()", "Model."+FuncName+"()") return Otvet } @@ -483,7 +484,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { } TextGRPCServerUpdateFunc := string(bytes) - TextGRPCServer := "package " + config.Settings.TEMPLATE_FOLDERNAME_GRPC + "\n\n" + TextGRPCServer := "package " + config.Settings.PREFIX_CLIENT_GRPC + TableName + "\n\n" TextGRPCServer = TextGRPCServer + `import ( "context" "github.com/ManyakRus/starter/config_main" @@ -567,15 +568,15 @@ func FindTextUpdateEveryColumnTest1(TextGRPCServerUpdateFunc string, Table1 *typ ModelName := Table1.NameGo ColumnName := Column1.NameGo FuncName := "Update_" + ColumnName - TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Column1.TypeGo) + TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest_ID_Type(Column1.TypeGo) - Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL+"_Read", ModelName+"_"+FuncName) + Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL+"_Update(", ModelName+"_"+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, "grpc_proto.RequestString", "grpc_proto."+TextRequest) + Otvet = strings.ReplaceAll(Otvet, "Model.ColumnName", "Model."+TextRequestFieldName) + Otvet = strings.ReplaceAll(Otvet, "ColumnName", ColumnName) Otvet = strings.ReplaceAll(Otvet, "ColumnName", ColumnName) - Otvet = strings.ReplaceAll(Otvet, "Model.ID", "Model."+ColumnName) - Otvet = strings.ReplaceAll(Otvet, "Request.ID", "Request."+TextRequestFieldName) return Otvet }