1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2025-01-04 13:23:00 +02:00
crud_generator/internal/create_files/protobuf/protobuf_findmodelby.go

71 lines
2.0 KiB
Go
Raw Normal View History

2024-10-15 15:39:32 +02:00
package protobuf
import (
"github.com/ManyakRus/crud_generator/internal/create_files"
"github.com/ManyakRus/crud_generator/internal/types"
2024-10-17 13:14:00 +02:00
"github.com/ManyakRus/starter/log"
2024-10-15 15:39:32 +02:00
"strings"
)
// FindText_FindModelBy - возвращает TextProto и текст FindModelBy
2024-10-17 13:14:00 +02:00
func FindText_FindModelBy(MapAll map[string]*types.Table, TextProto string, Table1 *types.Table) (string, string) {
2024-10-15 15:39:32 +02:00
Otvet := TextProto
Otvet2 := ""
for _, TableColumns1 := range types.MassFindModelBy {
if TableColumns1.Table != Table1 {
continue
}
2024-10-17 13:14:00 +02:00
Text1 := FindText_FindModelBy1(MapAll, TableColumns1.Table, TableColumns1.Column)
2024-10-15 15:39:32 +02:00
//проверим такой текст функции уже есть
pos1 := strings.Index(TextProto, Text1)
if pos1 >= 0 {
continue
}
//добавим message
TextMess := AddTextMessageRequestModel_Column(TextProto, TableColumns1.Column)
//проверим такой текст message уже есть
pos1 = strings.Index(TextProto, TextMess)
if pos1 < 0 {
Otvet = TextMess
}
//
Otvet2 = Otvet2 + Text1
}
return Otvet, Otvet2
}
// FindText_FindModelBy1 - находит текст FindModelBy
2024-10-17 13:14:00 +02:00
func FindText_FindModelBy1(MapAll map[string]*types.Table, Table1 *types.Table, Column1 *types.Column) string {
2024-10-15 15:39:32 +02:00
Otvet := "\n\trpc "
TextFields := ""
2024-10-16 14:51:13 +02:00
//TextRequest := "Request_"
2024-10-15 15:39:32 +02:00
Underline := ""
//for _, Column1 := range TableColumns1.Columns {
TextFields = TextFields + Underline + Column1.NameGo_translit
2024-10-16 14:51:13 +02:00
//TextRequest1 := create_files.Convert_GolangTypeNameToProtobufFieldName(Column1.TypeGo)
//TextRequest = TextRequest + Underline + TextRequest1
2024-10-15 15:39:32 +02:00
Underline = "_"
//}
2024-10-16 14:51:13 +02:00
TextRequest := create_files.FindText_ProtobufRequest_Column_ManyPK(Table1, Column1)
2024-10-15 15:39:32 +02:00
2024-10-17 13:14:00 +02:00
//
ForeignTableName := Column1.TableKey
ForeignTable, ok := MapAll[ForeignTableName]
if ok == false {
log.Panic("Table not found: ", ForeignTableName)
}
//
Otvet = Otvet + Table1.NameGo_translit + "_Find" + ForeignTable.NameGo_translit + "By_" + TextFields + "(" + TextRequest + ") returns (Response) {}\n"
2024-10-15 15:39:32 +02:00
return Otvet
}