mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2024-11-24 08:22:42 +02:00
сделал ReadAll()
This commit is contained in:
parent
6b409df4f1
commit
8089fd84c9
@ -1,5 +1,5 @@
|
||||
// LawsuitStatusType_ReadAll - находит все строки lawsuit_status_types в БД
|
||||
func (s *ServerGRPC) LawsuitStatusType_ReadAll(ctx context.Context, Request *grpc_proto.RequestEmpty) (*grpc_proto.ResponseMass, error) {
|
||||
func (s *ServerGRPC) LawsuitStatusType_ReadAll(ctx context.Context, Request *grpc_proto.Request_Empty) (*grpc_proto.ResponseMass, error) {
|
||||
var Otvet grpc_proto.ResponseMass
|
||||
var err error
|
||||
|
||||
|
@ -3,14 +3,13 @@ func Test_server_LawsuitStatusType_FindMassBy_FieldNamesWithUnderline(t *testing
|
||||
crud_starter.InitCrudTransport_DB()
|
||||
|
||||
ctx := context.Background()
|
||||
Request := grpc_proto.RequestName{}
|
||||
Request.RequestFieldName = 0
|
||||
Request := grpc_proto.Request_Empty{}
|
||||
Request.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion()
|
||||
|
||||
server1 := &ServerGRPC{}
|
||||
_, err := server1.LawsuitStatusType_FindMassBy_FieldNamesWithUnderline(ctx, &Request)
|
||||
_, err := server1.LawsuitStatusType_ReadAll(ctx, &Request)
|
||||
if err != nil && crud_func.IsRecordNotFound(err) == false {
|
||||
t.Error("Test_server_LawsuitStatusType_FindMassBy_FieldNamesWithUnderline() error: ", err)
|
||||
t.Error("Test_server_LawsuitStatusType_ReadAll() error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ func (crud Crud_GRPC) ReadAll() ([]lawsuit_status_types.LawsuitStatusType, error
|
||||
// подготовка запроса
|
||||
var VersionModel = crud.GetVersionModel()
|
||||
|
||||
Request := &grpc_proto.RequestEmpty{}
|
||||
Request := &grpc_proto.Request_Empty{}
|
||||
Request.VersionModel = VersionModel
|
||||
|
||||
ctxMain := context.Background()
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"github.com/ManyakRus/starter/config_main"
|
||||
"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/grpc_client"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client/grpc_lawsuit_status_types"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/crud_func"
|
||||
"testing"
|
||||
)
|
||||
|
@ -90,7 +90,7 @@ func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
return err
|
||||
}
|
||||
|
||||
//
|
||||
//FindMassBy
|
||||
err = CreateFiles_FindMassBy(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles_FindMassBy() table: ", Table1.Name, " error: ", err)
|
||||
@ -104,6 +104,19 @@ func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
return err
|
||||
}
|
||||
|
||||
//ReadAll
|
||||
err = CreateFiles_ReadAll(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles_ReadAll() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
//
|
||||
err = CreateFiles_ReadAll_Test(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles_ReadAll_Test() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
|
@ -0,0 +1,276 @@
|
||||
package grpc_client_tables
|
||||
|
||||
import (
|
||||
"github.com/ManyakRus/crud_generator/internal/config"
|
||||
"github.com/ManyakRus/crud_generator/internal/constants"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files"
|
||||
"github.com/ManyakRus/crud_generator/internal/types"
|
||||
"github.com/ManyakRus/starter/log"
|
||||
"github.com/ManyakRus/starter/micro"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CreateFiles_ReadAll - создаёт 1 файл в папке grpc_client
|
||||
func CreateFiles_ReadAll(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
if len(types.MapReadAll) == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
//чтение файлов
|
||||
DirBin := micro.ProgramDir_bin()
|
||||
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||
DirTemplatesGRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||
DirReadyGRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateGRPCClient := DirTemplatesGRPCClient + config.Settings.TEMPLATES_GRPC_CLIENT_TABLES_READALL_FILENAME
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DirReadyTable := DirReadyGRPCClient + micro.SeparatorFile() + config.Settings.PREFIX_CLIENT_GRPC + TableName + micro.SeparatorFile()
|
||||
FilenameReady := DirReadyTable + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_readall.go"
|
||||
|
||||
//создадим каталог
|
||||
ok, err := micro.FileExists(DirReadyTable)
|
||||
if ok == false {
|
||||
err = os.MkdirAll(DirReadyTable, 0777)
|
||||
if err != nil {
|
||||
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
//загрузим шаблон файла
|
||||
bytes, err := os.ReadFile(FilenameTemplateGRPCClient)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateGRPCClient, " error: ", err)
|
||||
}
|
||||
TextGRPCClient := string(bytes)
|
||||
|
||||
//загрузим шаблон файла функции
|
||||
FilenameTemplateGRPCClientFunction := DirTemplatesGRPCClient + config.Settings.TEMPLATES_GRPC_CLIENT_TABLES_READALL_FUNCTION_FILENAME
|
||||
bytes, err = os.ReadFile(FilenameTemplateGRPCClientFunction)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateGRPCClientFunction, " error: ", err)
|
||||
}
|
||||
TextTemplatedFunction := string(bytes)
|
||||
|
||||
//заменим имя пакета на новое
|
||||
TextGRPCClient = create_files.Replace_PackageName(TextGRPCClient, DirReadyTable)
|
||||
|
||||
//ModelName := Table1.NameGo
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextGRPCClient = create_files.Delete_TemplateRepositoryImports(TextGRPCClient)
|
||||
|
||||
ModelTableURL := create_files.Find_ModelTableURL(TableName)
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, ModelTableURL)
|
||||
|
||||
ProtoURL := create_files.Find_ProtoURL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, ProtoURL)
|
||||
|
||||
GRPCClient_func_URL := create_files.Find_GRPCClient_func_URL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPCClient_func_URL)
|
||||
|
||||
GRPCConstantsURL := create_files.Find_GRPCConstantsURL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPCConstantsURL)
|
||||
|
||||
GRPC_NRPC_URL := create_files.Find_GRPC_NRPC_URL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPC_NRPC_URL)
|
||||
|
||||
NRPC_Client_URL := create_files.Find_NRPC_Client_URL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, NRPC_Client_URL)
|
||||
|
||||
}
|
||||
|
||||
//создание функций
|
||||
TextGRPCClientFunc := CreateFiles_ReadAll_Table(Table1, TextTemplatedFunction)
|
||||
if TextGRPCClientFunc == "" {
|
||||
return err
|
||||
}
|
||||
TextGRPCClient = TextGRPCClient + TextGRPCClientFunc
|
||||
|
||||
//создание текста
|
||||
TextGRPCClient = create_files.Replace_TemplateModel_to_Model(TextGRPCClient, Table1.NameGo)
|
||||
TextGRPCClient = create_files.Replace_TemplateTableName_to_TableName(TextGRPCClient, Table1.Name)
|
||||
TextGRPCClient = create_files.AddText_ModuleGenerated(TextGRPCClient)
|
||||
|
||||
//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
|
||||
|
||||
//замена импортов на новые URL
|
||||
TextGRPCClient = create_files.Replace_RepositoryImportsURL(TextGRPCClient)
|
||||
|
||||
//uuid
|
||||
TextGRPCClient = create_files.CheckAndAdd_ImportUUID_FromText(TextGRPCClient)
|
||||
|
||||
//alias
|
||||
TextGRPCClient = create_files.CheckAndAdd_ImportAlias(TextGRPCClient)
|
||||
|
||||
//time
|
||||
TextGRPCClient = create_files.CheckAndAdd_ImportTime_FromText(TextGRPCClient)
|
||||
|
||||
//удаление пустого импорта
|
||||
TextGRPCClient = create_files.Delete_EmptyImport(TextGRPCClient)
|
||||
|
||||
//удаление пустых строк
|
||||
TextGRPCClient = create_files.Delete_EmptyLines(TextGRPCClient)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReady, []byte(TextGRPCClient), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateFiles_ReadAll_Table - создаёт текст всех функций
|
||||
func CreateFiles_ReadAll_Table(Table1 *types.Table, TextTemplateFunction string) string {
|
||||
Otvet := ""
|
||||
|
||||
_, ok := types.MapReadAll[Table1]
|
||||
if ok == false {
|
||||
Otvet = TextTemplateFunction
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet1 := CreateFiles_ReadAll_Table1(Table1, TextTemplateFunction)
|
||||
Otvet = Otvet + Otvet1
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// CreateFiles_ReadAll_Table1 - создаёт текст всех функций
|
||||
func CreateFiles_ReadAll_Table1(Table1 *types.Table, TextTemplateFunction string) string {
|
||||
Otvet := TextTemplateFunction
|
||||
|
||||
//
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// CreateFiles_ReadAll_Test - создаёт 1 файл в папке grpc_client
|
||||
func CreateFiles_ReadAll_Test(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
if len(types.MapReadAll) == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
//чтение файлов
|
||||
DirBin := micro.ProgramDir_bin()
|
||||
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||
DirTemplatesGRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||
DirReadyGRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateGRPCClient := DirTemplatesGRPCClient + config.Settings.TEMPLATES_GRPC_CLIENT_TABLES_READALL_TEST_FILENAME
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DirReadyTable := DirReadyGRPCClient + micro.SeparatorFile() + config.Settings.PREFIX_CLIENT_GRPC + TableName + micro.SeparatorFile() + "tests" + micro.SeparatorFile()
|
||||
FilenameReady := DirReadyTable + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_readall_test.go"
|
||||
|
||||
//создадим каталог
|
||||
ok, err := micro.FileExists(DirReadyTable)
|
||||
if ok == false {
|
||||
err = os.MkdirAll(DirReadyTable, 0777)
|
||||
if err != nil {
|
||||
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
//загрузим шаблон файла
|
||||
bytes, err := os.ReadFile(FilenameTemplateGRPCClient)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateGRPCClient, " error: ", err)
|
||||
}
|
||||
TextGRPCClient := string(bytes)
|
||||
|
||||
//загрузим шаблон файла функции
|
||||
FilenameTemplateGRPCClientFunction := DirTemplatesGRPCClient + config.Settings.TEMPLATES_GRPC_CLIENT_TABLES_READALL_FUNCTION_TEST_FILENAME
|
||||
bytes, err = os.ReadFile(FilenameTemplateGRPCClientFunction)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateGRPCClientFunction, " error: ", err)
|
||||
}
|
||||
TextTemplatedFunction := string(bytes)
|
||||
|
||||
//заменим имя пакета на новое
|
||||
TextGRPCClient = create_files.Replace_PackageName(TextGRPCClient, DirReadyTable)
|
||||
|
||||
//ModelName := Table1.NameGo
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextGRPCClient = create_files.Delete_TemplateRepositoryImports(TextGRPCClient)
|
||||
|
||||
//ModelTableURL := create_files.Find_ModelTableURL(TableName)
|
||||
//TextGRPCClient = create_files.AddImport(TextGRPCClient, ModelTableURL)
|
||||
|
||||
//GRPCClient_func_URL := create_files.Find_GRPCClient_func_URL()
|
||||
//TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPCClient_func_URL)
|
||||
|
||||
GRPClientURL := create_files.Find_GRPClientURL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPClientURL)
|
||||
|
||||
GRPClientTableURL := create_files.Find_GRPCClientTableURL(Table1.Name)
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPClientTableURL)
|
||||
|
||||
CrudFuncURL := create_files.Find_CrudFuncURL(TableName)
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, CrudFuncURL)
|
||||
}
|
||||
|
||||
//создание функций
|
||||
TextGRPCClientFunc := CreateFiles_ReadAll_Test_Table(Table1, TextTemplatedFunction)
|
||||
if TextGRPCClientFunc == "" {
|
||||
return err
|
||||
}
|
||||
TextGRPCClient = TextGRPCClient + TextGRPCClientFunc
|
||||
|
||||
//создание текста
|
||||
TextGRPCClient = create_files.Replace_TemplateModel_to_Model(TextGRPCClient, Table1.NameGo)
|
||||
TextGRPCClient = create_files.Replace_TemplateTableName_to_TableName(TextGRPCClient, Table1.Name)
|
||||
TextGRPCClient = create_files.AddText_ModuleGenerated(TextGRPCClient)
|
||||
|
||||
//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
|
||||
|
||||
//замена импортов на новые URL
|
||||
TextGRPCClient = create_files.Replace_RepositoryImportsURL(TextGRPCClient)
|
||||
|
||||
//uuid
|
||||
TextGRPCClient = create_files.CheckAndAdd_ImportUUID_FromText(TextGRPCClient)
|
||||
|
||||
//alias
|
||||
TextGRPCClient = create_files.CheckAndAdd_ImportAlias(TextGRPCClient)
|
||||
|
||||
//удаление пустого импорта
|
||||
TextGRPCClient = create_files.Delete_EmptyImport(TextGRPCClient)
|
||||
|
||||
//удаление пустых строк
|
||||
TextGRPCClient = create_files.Delete_EmptyLines(TextGRPCClient)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReady, []byte(TextGRPCClient), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateFiles_ReadAll_Test_Table - создаёт текст 1 функции
|
||||
func CreateFiles_ReadAll_Test_Table(Table1 *types.Table, TextTemplateFunction string) string {
|
||||
Otvet := ""
|
||||
|
||||
_, ok := types.MapReadAll[Table1]
|
||||
if ok == false {
|
||||
Otvet = TextTemplateFunction
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet1 := CreateFiles_ReadAll_Test_Table1(Table1, TextTemplateFunction)
|
||||
Otvet = Otvet + Otvet1
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// CreateFiles_ReadAll_Test_Table1 - создаёт текст 1 функции
|
||||
func CreateFiles_ReadAll_Test_Table1(Table1 *types.Table, TextTemplateFunction string) string {
|
||||
Otvet := TextTemplateFunction
|
||||
|
||||
return Otvet
|
||||
}
|
@ -96,6 +96,11 @@ func CreateFileProto(MapAll map[string]*types.Table) error {
|
||||
TextProto, TextProtoNew1 = FindText_FindMassBy(TextProto, Table1)
|
||||
TextProtoNew = TextProtoNew + TextProtoNew1
|
||||
|
||||
//добавим текст ReadAll
|
||||
TextProto, TextProtoNew1 = FindText_ReadAll(TextProto, Table1)
|
||||
TextProtoNew = TextProtoNew + TextProtoNew1
|
||||
|
||||
//
|
||||
if config.Settings.NEED_CREATE_CACHE_API == true {
|
||||
TextProtoNew = TextProtoNew + FindText_ProtoTable1_Cache(TextProto, Table1)
|
||||
}
|
||||
|
41
internal/create_files/protobuf/protobuf_readall.go
Normal file
41
internal/create_files/protobuf/protobuf_readall.go
Normal file
@ -0,0 +1,41 @@
|
||||
package protobuf
|
||||
|
||||
import (
|
||||
"github.com/ManyakRus/crud_generator/internal/types"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// FindText_ReadAll - добавляет текст ReadAll
|
||||
func FindText_ReadAll(TextProto string, Table1 *types.Table) (TextProtoNew string, TextAdd string) {
|
||||
TextProtoNew = TextProto
|
||||
|
||||
TextAdd = ""
|
||||
for Table1, _ := range types.MapReadAll {
|
||||
|
||||
Text1 := FindText_ReadAll1(Table1)
|
||||
|
||||
//проверим такой текст уже есть
|
||||
pos1 := strings.Index(TextProto, Text1)
|
||||
if pos1 >= 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
//
|
||||
TextAdd = TextAdd + Text1
|
||||
}
|
||||
|
||||
return TextProtoNew, TextAdd
|
||||
}
|
||||
|
||||
// FindText_ReadAll1 - находит текст FindBy
|
||||
func FindText_ReadAll1(Table1 *types.Table) string {
|
||||
Otvet := "\n\trpc "
|
||||
|
||||
FuncName := "ReadAll"
|
||||
TextRequest := "Request_Empty"
|
||||
|
||||
//
|
||||
Otvet = Otvet + Table1.NameGo + "_" + FuncName + "(" + TextRequest + ") returns (ResponseMass) {}\n"
|
||||
|
||||
return Otvet
|
||||
}
|
@ -75,34 +75,48 @@ func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
err = CreateFiles_FindBy(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles_FindBy() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
//
|
||||
err = CreateFiles_FindBy(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles_FindBy() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
//
|
||||
err = CreateFiles_FindBy_Test(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles_FindBy_Test() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
//
|
||||
err = CreateFiles_FindBy_Test(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles_FindBy_Test() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
//
|
||||
err = CreateFiles_FindMassBy(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles_FindMassBy() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
//FindMassBy
|
||||
err = CreateFiles_FindMassBy(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles_FindMassBy() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
//
|
||||
err = CreateFiles_FindMassBy_Test(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles_FindMassBy_Test() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
//
|
||||
err = CreateFiles_FindMassBy_Test(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles_FindMassBy_Test() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
//ReadAll
|
||||
err = CreateFiles_ReadAll(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles_ReadAll() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
//
|
||||
err = CreateFiles_ReadAll_Test(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles_ReadAll_Test() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
@ -0,0 +1,261 @@
|
||||
package server_grpc_tables
|
||||
|
||||
import (
|
||||
"github.com/ManyakRus/crud_generator/internal/config"
|
||||
"github.com/ManyakRus/crud_generator/internal/constants"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files"
|
||||
"github.com/ManyakRus/crud_generator/internal/types"
|
||||
"github.com/ManyakRus/starter/log"
|
||||
"github.com/ManyakRus/starter/micro"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CreateFiles_ReadAll - создаёт 1 файл в папке server_grpc
|
||||
func CreateFiles_ReadAll(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
if len(types.MapReadAll) == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
//чтение файлов
|
||||
DirBin := micro.ProgramDir_bin()
|
||||
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||
DirTemplatesGRPCServer := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER + micro.SeparatorFile()
|
||||
DirReadyGRPCServer := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateGRPCServer := DirTemplatesGRPCServer + config.Settings.TEMPLATES_GRPC_SERVER_READALL_FILENAME
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DirReadyTable := DirReadyGRPCServer
|
||||
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_SERVER_GRPC + TableName + "_readall.go"
|
||||
|
||||
//создадим каталог
|
||||
ok, err := micro.FileExists(DirReadyTable)
|
||||
if ok == false {
|
||||
err = os.MkdirAll(DirReadyTable, 0777)
|
||||
if err != nil {
|
||||
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
//загрузим шаблон файла
|
||||
bytes, err := os.ReadFile(FilenameTemplateGRPCServer)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateGRPCServer, " error: ", err)
|
||||
}
|
||||
TextGRPCServer := string(bytes)
|
||||
|
||||
//загрузим шаблон файла функции
|
||||
FilenameTemplateGRPCServerFunction := DirTemplatesGRPCServer + config.Settings.TEMPLATES_GRPC_SERVER_READALL_FUNCTION_FILENAME
|
||||
bytes, err = os.ReadFile(FilenameTemplateGRPCServerFunction)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateGRPCServerFunction, " error: ", err)
|
||||
}
|
||||
TextTemplatedFunction := string(bytes)
|
||||
|
||||
//заменим имя пакета на новое
|
||||
TextGRPCServer = create_files.Replace_PackageName(TextGRPCServer, DirReadyTable)
|
||||
|
||||
//ModelName := Table1.NameGo
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextGRPCServer = create_files.Delete_TemplateRepositoryImports(TextGRPCServer)
|
||||
|
||||
ModelTableURL := create_files.Find_ModelTableURL(TableName)
|
||||
TextGRPCServer = create_files.AddImport(TextGRPCServer, ModelTableURL)
|
||||
|
||||
CrudTableURL := create_files.Find_CrudTableURL(TableName)
|
||||
TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudTableURL)
|
||||
|
||||
ProtoURL := create_files.Find_ProtoURL()
|
||||
TextGRPCServer = create_files.AddImport(TextGRPCServer, ProtoURL)
|
||||
|
||||
}
|
||||
|
||||
//создание функций
|
||||
TextGRPCServerFunc := CreateFiles_ReadAll_Table(Table1, TextTemplatedFunction)
|
||||
if TextGRPCServerFunc == "" {
|
||||
return err
|
||||
}
|
||||
TextGRPCServer = TextGRPCServer + TextGRPCServerFunc
|
||||
|
||||
//создание текста
|
||||
TextGRPCServer = create_files.Replace_TemplateModel_to_Model(TextGRPCServer, Table1.NameGo)
|
||||
TextGRPCServer = create_files.Replace_TemplateTableName_to_TableName(TextGRPCServer, Table1.Name)
|
||||
TextGRPCServer = create_files.AddText_ModuleGenerated(TextGRPCServer)
|
||||
|
||||
//TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
//TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
//TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer
|
||||
|
||||
//замена импортов на новые URL
|
||||
TextGRPCServer = create_files.Replace_RepositoryImportsURL(TextGRPCServer)
|
||||
|
||||
//uuid
|
||||
TextGRPCServer = create_files.CheckAndAdd_ImportUUID_FromText(TextGRPCServer)
|
||||
|
||||
//alias
|
||||
TextGRPCServer = create_files.CheckAndAdd_ImportAlias(TextGRPCServer)
|
||||
|
||||
//удаление пустого импорта
|
||||
TextGRPCServer = create_files.Delete_EmptyImport(TextGRPCServer)
|
||||
|
||||
//удаление пустых строк
|
||||
TextGRPCServer = create_files.Delete_EmptyLines(TextGRPCServer)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReady, []byte(TextGRPCServer), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateFiles_ReadAll_Table - создаёт текст всех функций
|
||||
func CreateFiles_ReadAll_Table(Table1 *types.Table, TextTemplateFunction string) string {
|
||||
Otvet := ""
|
||||
|
||||
_, ok := types.MapReadAll[Table1]
|
||||
if ok == false {
|
||||
Otvet = TextTemplateFunction
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet1 := CreateFiles_ReadAll_Table1(Table1, TextTemplateFunction)
|
||||
Otvet = Otvet + Otvet1
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// CreateFiles_ReadAll_Table1 - создаёт текст всех функций
|
||||
func CreateFiles_ReadAll_Table1(Table1 *types.Table, TextTemplateFunction string) string {
|
||||
Otvet := TextTemplateFunction
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// CreateFiles_ReadAll_Test - создаёт 1 файл в папке server_grpc
|
||||
func CreateFiles_ReadAll_Test(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
if len(types.MapReadAll) == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
//чтение файлов
|
||||
DirBin := micro.ProgramDir_bin()
|
||||
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||
DirTemplatesGRPCServer := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER + micro.SeparatorFile()
|
||||
DirReadyGRPCServer := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateGRPCServer := DirTemplatesGRPCServer + config.Settings.TEMPLATES_GRPC_SERVER_READALL_TEST_FILENAME
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DirReadyTable := DirReadyGRPCServer
|
||||
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_SERVER_GRPC + TableName + "_readall_test.go"
|
||||
|
||||
//создадим каталог
|
||||
ok, err := micro.FileExists(DirReadyTable)
|
||||
if ok == false {
|
||||
err = os.MkdirAll(DirReadyTable, 0777)
|
||||
if err != nil {
|
||||
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
//загрузим шаблон файла
|
||||
bytes, err := os.ReadFile(FilenameTemplateGRPCServer)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateGRPCServer, " error: ", err)
|
||||
}
|
||||
TextGRPCServer := string(bytes)
|
||||
|
||||
//загрузим шаблон файла функции
|
||||
FilenameTemplateGRPCServerFunction := DirTemplatesGRPCServer + config.Settings.TEMPLATES_GRPC_SERVER_READALL_FUNCTION_TEST_FILENAME
|
||||
bytes, err = os.ReadFile(FilenameTemplateGRPCServerFunction)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateGRPCServerFunction, " error: ", err)
|
||||
}
|
||||
TextTemplatedFunction := string(bytes)
|
||||
|
||||
//заменим имя пакета на новое
|
||||
TextGRPCServer = create_files.Replace_PackageName(TextGRPCServer, DirReadyTable)
|
||||
|
||||
//ModelName := Table1.NameGo
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextGRPCServer = create_files.Delete_TemplateRepositoryImports(TextGRPCServer)
|
||||
|
||||
ModelTableURL := create_files.Find_ModelTableURL(TableName)
|
||||
TextGRPCServer = create_files.AddImport(TextGRPCServer, ModelTableURL)
|
||||
|
||||
CrudStarterURL := create_files.Find_CrudStarterURL()
|
||||
TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudStarterURL)
|
||||
|
||||
ProtoURL := create_files.Find_ProtoURL()
|
||||
TextGRPCServer = create_files.AddImport(TextGRPCServer, ProtoURL)
|
||||
|
||||
CrudFuncURL := create_files.Find_CrudFuncURL(TableName)
|
||||
TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudFuncURL)
|
||||
|
||||
}
|
||||
|
||||
//создание функций
|
||||
TextGRPCServerFunc := CreateFiles_ReadAll_Test_Table(Table1, TextTemplatedFunction)
|
||||
if TextGRPCServerFunc == "" {
|
||||
return err
|
||||
}
|
||||
TextGRPCServer = TextGRPCServer + TextGRPCServerFunc
|
||||
|
||||
//создание текста
|
||||
TextGRPCServer = create_files.Replace_TemplateModel_to_Model(TextGRPCServer, Table1.NameGo)
|
||||
TextGRPCServer = create_files.Replace_TemplateTableName_to_TableName(TextGRPCServer, Table1.Name)
|
||||
TextGRPCServer = create_files.AddText_ModuleGenerated(TextGRPCServer)
|
||||
|
||||
//TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
//TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
//TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer
|
||||
|
||||
//замена импортов на новые URL
|
||||
TextGRPCServer = create_files.Replace_RepositoryImportsURL(TextGRPCServer)
|
||||
|
||||
//uuid
|
||||
TextGRPCServer = create_files.CheckAndAdd_ImportUUID_FromText(TextGRPCServer)
|
||||
|
||||
//alias
|
||||
TextGRPCServer = create_files.CheckAndAdd_ImportAlias(TextGRPCServer)
|
||||
|
||||
//удаление пустого импорта
|
||||
TextGRPCServer = create_files.Delete_EmptyImport(TextGRPCServer)
|
||||
|
||||
//удаление пустых строк
|
||||
TextGRPCServer = create_files.Delete_EmptyLines(TextGRPCServer)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReady, []byte(TextGRPCServer), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateFiles_ReadAll_Test_Table - создаёт текст всех функций
|
||||
func CreateFiles_ReadAll_Test_Table(Table1 *types.Table, TextTemplateFunction string) string {
|
||||
Otvet := ""
|
||||
|
||||
_, ok := types.MapReadAll[Table1]
|
||||
if ok == false {
|
||||
Otvet = TextTemplateFunction
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet1 := CreateFiles_ReadAll_Test_Table1(Table1, TextTemplateFunction)
|
||||
Otvet = Otvet + Otvet1
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// CreateFiles_ReadAll_Test_Table1 - создаёт текст всех функций
|
||||
func CreateFiles_ReadAll_Test_Table1(Table1 *types.Table, TextTemplateFunction string) string {
|
||||
Otvet := TextTemplateFunction
|
||||
|
||||
return Otvet
|
||||
}
|
Loading…
Reference in New Issue
Block a user