From 5c9d7c72fc463d763e3f04767b2d8a1fdeeac152 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Fri, 7 Jun 2024 16:45:54 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20notifier?= =?UTF-8?q?=20test=20=D0=B1=D0=B5=D0=B7=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/create_files/create_files.go | 86 +++++++++++++++++---------- 1 file changed, 54 insertions(+), 32 deletions(-) diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index c8955b3..0ab4b1f 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -1849,6 +1849,26 @@ func ConvertGolangTypeToProtobufType(Table1 *types.Table, Column1 *types.Column, return Otvet } +// ConvertVariableToProtobufType - возвращает имя переменной + имя колонки, преобразованное в тип protobuf +func ConvertVariableToProtobufType(Table1 *types.Table, Column1 *types.Column, VariableName string) string { + Otvet := "" + + if Column1 == nil { + return Otvet + } + + Otvet = VariableName + + switch Column1.TypeGo { + case "time.Time": + Otvet = "timestamppb.New(" + VariableName + ")" + case "uuid.UUID": + Otvet = VariableName + ".String()" + } + + return Otvet +} + // ConvertProtobufTypeToGolangType - возвращает имя переменной + имя колонки, преобразованное в тип golang из protobuf func ConvertProtobufTypeToGolangType(Table1 *types.Table, Column1 *types.Column, VariableName string) (VariableColumn string, GolangCode string) { RequestColumnName := FindRequestColumnName(Table1, Column1) @@ -2179,16 +2199,16 @@ func FindTextIDMinimum(Column1 *types.Column) string { func Replace_Model_ID_Test(Text string, Table1 *types.Table) string { Otvet := Text - if Table1.PrimaryKeyColumnsCount == 1 { - PrimaryKeyColumn := FindPrimaryKeyColumn(Table1) - if PrimaryKeyColumn == nil { - return Otvet - } - - Otvet = Replace_Model_ID_Test1(Otvet, Table1, PrimaryKeyColumn) - } else { - Otvet = Replace_Model_ID_Test_ManyPK(Otvet, Table1) - } + //if Table1.PrimaryKeyColumnsCount == 1 { + // PrimaryKeyColumn := FindPrimaryKeyColumn(Table1) + // if PrimaryKeyColumn == nil { + // return Otvet + // } + // + // Otvet = Replace_Model_ID_Test1(Otvet, Table1, PrimaryKeyColumn) + //} else { + Otvet = Replace_Model_ID_Test_ManyPK(Otvet, Table1) + //} return Otvet } @@ -2215,7 +2235,8 @@ func Replace_Model_ID_Test_ManyPK(Text string, Table1 *types.Table) string { TextNew = "" for _, Column1 := range MassPK { Name := strings.ToUpper(Column1.NameGo) - Text1 := Table1.NameGo + "_" + Name + "_Test" + VariableName := Table1.NameGo + "_" + Name + "_Test" + Text1 := ConvertVariableToProtobufType(Table1, Column1, VariableName) RequestColumnName := FindRequestColumnName(Table1, Column1) TextNew = TextNew + "\tRequest." + RequestColumnName + " = " + Text1 + "\n" } @@ -2226,7 +2247,8 @@ func Replace_Model_ID_Test_ManyPK(Text string, Table1 *types.Table) string { TextNew = "" for _, Column1 := range MassPK { Name := strings.ToUpper(Column1.NameGo) - Text1 := Table1.NameGo + "_" + Name + "_Test" + VariableName := Table1.NameGo + "_" + Name + "_Test" + Text1 := ConvertVariableToProtobufType(Table1, Column1, VariableName) RequestColumnName := FindRequestColumnName(Table1, Column1) TextNew = TextNew + "\tRequest2." + RequestColumnName + " = " + Text1 + "\n" } @@ -2521,30 +2543,30 @@ func ReplaceOtvetIDEqual0(Text string, Table1 *types.Table) string { func ReplaceModelIDEqual1(Text string, Table1 *types.Table) string { Otvet := Text - if Table1.PrimaryKeyColumnsCount == 1 { - Otvet = ReplaceModelIDEqual1_1(Otvet, Table1) - } else { - Otvet = ReplaceModelIDEqual1_ManyPK(Otvet, Table1) - } + //if Table1.PrimaryKeyColumnsCount == 1 { + // Otvet = ReplaceModelIDEqual1_1(Otvet, Table1) + //} else { + Otvet = ReplaceModelIDEqual1_ManyPK(Otvet, Table1) + //} return Otvet } -// ReplaceModelIDEqual1 - заменяет Otvet.ID = -1 -func ReplaceModelIDEqual1_1(Text string, Table1 *types.Table) string { - Otvet := Text - - PrimaryKeyColumn := FindPrimaryKeyColumn(Table1) - if PrimaryKeyColumn == nil { - return Otvet - } - - Value := FindNegativeValue(PrimaryKeyColumn.TypeGo) - - Otvet = strings.ReplaceAll(Otvet, "m.ID = -1", "m.ID = "+Value) - - return Otvet -} +//// ReplaceModelIDEqual1 - заменяет Otvet.ID = -1 +//func ReplaceModelIDEqual1_1(Text string, Table1 *types.Table) string { +// Otvet := Text +// +// PrimaryKeyColumn := FindPrimaryKeyColumn(Table1) +// if PrimaryKeyColumn == nil { +// return Otvet +// } +// +// Value := FindNegativeValue(PrimaryKeyColumn.TypeGo) +// +// Otvet = strings.ReplaceAll(Otvet, "m.ID = -1", "m.ID = "+Value) +// +// return Otvet +//} // ReplaceModelIDEqual1_ManyPK - заменяет m.ID = -1 func ReplaceModelIDEqual1_ManyPK(Text string, Table1 *types.Table) string {