1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-12-22 00:36:41 +02:00

сделал TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME

This commit is contained in:
Nikitin Aleksandr 2024-02-20 16:45:34 +03:00
parent 95a94e1bfd
commit 5321202424
5 changed files with 260 additions and 88 deletions

View File

@ -202,3 +202,8 @@ TEMPLATES_CRUD_TABLE_UPDATE_FILENAME="crud_table_update.go_"
#TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME - short filename of "crud_table_update_test.go_" file
TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME="crud_table_update_test.go_"
#TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME - short filename of "grpc_client_table_update.go_" file
TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME="grpc_client_table_update.go_"
#TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME - short filename of "grpc_client_table_update_test.go_" file
TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME="grpc_client_table_update_test.go_"

View File

@ -0,0 +1,13 @@
package grpc_lawsuit_status_types
import (
"context"
"github.com/ManyakRus/starter/log"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto"
"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_constants"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc_nrpc"
"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"
"time"
)

View File

@ -0,0 +1,116 @@
package grpc_lawsuit_status_types
import (
"github.com/ManyakRus/starter/config_main"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing"
)
func TestCrud_GRPC_Update_Code(t *testing.T) {
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
crud := Crud_GRPC{}
//прочитаем из БД
Model := lawsuit_status_types.LawsuitStatusType{}
Model.ID = Postgres_ID_Test
err := crud.Read(&Model)
if err != nil {
t.Error("TestCrud_GRPC_Update_Code() Read() error: ", err)
}
//запишем в БД это же значение
Otvet := lawsuit_status_types.LawsuitStatusType{}
Otvet.ID = Model.ID
Otvet.Code = Model.Code
err = crud.Update_Code(&Otvet)
if err != nil {
t.Error("TestCrud_GRPC_Update_Code() Update() error: ", err)
}
}
func TestCrud_GRPC_Update_Description(t *testing.T) {
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
crud := Crud_GRPC{}
//прочитаем из БД
Model := lawsuit_status_types.LawsuitStatusType{}
Model.ID = Postgres_ID_Test
err := crud.Read(&Model)
if err != nil {
t.Error("TestCrud_GRPC_Update_Description() Read() error: ", err)
}
//запишем в БД это же значение
Otvet := lawsuit_status_types.LawsuitStatusType{}
Otvet.ID = Model.ID
Otvet.Description = Model.Description
err = crud.Update_Description(&Otvet)
if err != nil {
t.Error("TestCrud_GRPC_Update_Description() Update() error: ", err)
}
}
func TestCrud_GRPC_Update_IsClosed(t *testing.T) {
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
crud := Crud_GRPC{}
//прочитаем из БД
Model := lawsuit_status_types.LawsuitStatusType{}
Model.ID = Postgres_ID_Test
err := crud.Read(&Model)
if err != nil {
t.Error("TestCrud_GRPC_Update_IsClosed() Read() error: ", err)
}
//запишем в БД это же значение
Otvet := lawsuit_status_types.LawsuitStatusType{}
Otvet.ID = Model.ID
Otvet.IsClosed = Model.IsClosed
err = crud.Update_IsClosed(&Otvet)
if err != nil {
t.Error("TestCrud_GRPC_Update_IsClosed() Update() error: ", err)
}
}
func TestCrud_GRPC_Update_Name(t *testing.T) {
config_main.LoadEnv()
grpc_client.Connect()
defer grpc_client.CloseConnection()
crud := Crud_GRPC{}
//прочитаем из БД
Model := lawsuit_status_types.LawsuitStatusType{}
Model.ID = Postgres_ID_Test
err := crud.Read(&Model)
if err != nil {
t.Error("TestCrud_GRPC_Update_Name() Read() error: ", err)
}
//запишем в БД это же значение
Otvet := lawsuit_status_types.LawsuitStatusType{}
Otvet.ID = Model.ID
Otvet.Name = Model.Name
err = crud.Update_Name(&Otvet)
if err != nil {
t.Error("TestCrud_GRPC_Update_Name() Update() error: ", err)
}
}

View File

@ -14,71 +14,73 @@ var Settings SettingsINI
// SettingsINI - структура для хранения всех нужных переменных окружения
type SettingsINI struct {
INCLUDE_TABLES string
EXCLUDE_TABLES string
TEMPLATE_FOLDERNAME string
TEMPLATE_FOLDERNAME_MODEL string
TEMPLATE_FOLDERNAME_DB string
TEMPLATE_FOLDERNAME_CRUD string
TEMPLATE_FOLDERNAME_TABLES string
TEMPLATE_FOLDERNAME_GRPC string
TEMPLATE_FOLDERNAME_GRPC_PROTO string
TEMPLATE_FOLDERNAME_GRPC_SERVER string
TEMPLATE_FOLDERNAME_GRPC_CLIENT string
TEMPLATE_FOLDERNAME_NRPC string
TEMPLATE_FOLDERNAME_NRPC_SERVER string
TEMPLATE_FOLDERNAME_NRPC_CLIENT string
TEMPLATE_FOLDERNAME_GRPC_NRPC string
TEMPLATE_SERVICE_NAME string
TEMPLATE_FOLDERNAME_CRUD_STARTER string
TEMPLATE_FOLDERNAME_ALIAS string
TEMPLATE_FOLDER_CRUD_FUNCTIONS string
TEMPLATE_FOLDERNAME_MAIN string
TEMPLATE_REPOSITORY_URL string
TEMPLATE_EXTERNAL_PROTO_FILENAME string
TEMPLATES_CRUD_FILENAME string
TEMPLATES_CRUD_TEST_FILENAME string
TEMPLATES_ALIAS_FILENAME string
TEMPLATES_CRUD_TABLE_UPDATE_FUNC_FILENAME string
TEMPLATES_CRUD_TABLE_UPDATE_FUNC_TEST_FILENAME string
TEMPLATES_CONVERT_ID_FILENAME string
TEMPLATES_CRUD_FUNCTIONS_RENAME_FILENAME string
TEMPLATES_MODEL_CRUD_DELETE_FUNCTIONS_FILENAME string
TEMPLATES_NAME_REPLACE_FILENAME string
TEMPLATES_NULLABLE_FILENAME string
TEMPLATES_CRUD_TABLE_UPDATE_FILENAME string
TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME string
NEED_CREATE_MODEL_STRUCT bool
NEED_CREATE_MODEL_CRUD bool
NEED_CREATE_DB bool
NEED_CREATE_DB_TEST bool
NEED_CREATE_DB_TABLES bool
NEED_CREATE_GRPC bool
NEED_CREATE_GRPC_SERVER_TEST bool
NEED_CREATE_GRPC_CLIENT_TEST bool
NEED_CREATE_NRPC bool
NEED_CREATE_NRPC_SERVER_TEST bool
NEED_CREATE_NRPC_CLIENT_TEST bool
NEED_CREATE_MANUAL_FILES bool
SERVICE_NAME string
SERVICE_REPOSITORY_URL string
TEXT_TEMPLATE_MODEL string
TEXT_TEMPLATE_TABLENAME string
HAS_IS_DELETED bool
READY_FOLDERNAME string
TEXT_DB_MODIFIED_AT string
TEXT_DB_CREATED_AT string
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
READY_ALIAS_FILENAME string
NEED_CREATE_UPDATE_EVERY_COLUMN bool
INCLUDE_TABLES string
EXCLUDE_TABLES string
TEMPLATE_FOLDERNAME string
TEMPLATE_FOLDERNAME_MODEL string
TEMPLATE_FOLDERNAME_DB string
TEMPLATE_FOLDERNAME_CRUD string
TEMPLATE_FOLDERNAME_TABLES string
TEMPLATE_FOLDERNAME_GRPC string
TEMPLATE_FOLDERNAME_GRPC_PROTO string
TEMPLATE_FOLDERNAME_GRPC_SERVER string
TEMPLATE_FOLDERNAME_GRPC_CLIENT string
TEMPLATE_FOLDERNAME_NRPC string
TEMPLATE_FOLDERNAME_NRPC_SERVER string
TEMPLATE_FOLDERNAME_NRPC_CLIENT string
TEMPLATE_FOLDERNAME_GRPC_NRPC string
TEMPLATE_SERVICE_NAME string
TEMPLATE_FOLDERNAME_CRUD_STARTER string
TEMPLATE_FOLDERNAME_ALIAS string
TEMPLATE_FOLDER_CRUD_FUNCTIONS string
TEMPLATE_FOLDERNAME_MAIN string
TEMPLATE_REPOSITORY_URL string
TEMPLATE_EXTERNAL_PROTO_FILENAME string
TEMPLATES_CRUD_FILENAME string
TEMPLATES_CRUD_TEST_FILENAME string
TEMPLATES_ALIAS_FILENAME string
TEMPLATES_CRUD_TABLE_UPDATE_FUNC_FILENAME string
TEMPLATES_CRUD_TABLE_UPDATE_FUNC_TEST_FILENAME string
TEMPLATES_CONVERT_ID_FILENAME string
TEMPLATES_CRUD_FUNCTIONS_RENAME_FILENAME string
TEMPLATES_MODEL_CRUD_DELETE_FUNCTIONS_FILENAME string
TEMPLATES_NAME_REPLACE_FILENAME string
TEMPLATES_NULLABLE_FILENAME string
TEMPLATES_CRUD_TABLE_UPDATE_FILENAME string
TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME string
TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME string
TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME string
NEED_CREATE_MODEL_STRUCT bool
NEED_CREATE_MODEL_CRUD bool
NEED_CREATE_DB bool
NEED_CREATE_DB_TEST bool
NEED_CREATE_DB_TABLES bool
NEED_CREATE_GRPC bool
NEED_CREATE_GRPC_SERVER_TEST bool
NEED_CREATE_GRPC_CLIENT_TEST bool
NEED_CREATE_NRPC bool
NEED_CREATE_NRPC_SERVER_TEST bool
NEED_CREATE_NRPC_CLIENT_TEST bool
NEED_CREATE_MANUAL_FILES bool
SERVICE_NAME string
SERVICE_REPOSITORY_URL string
TEXT_TEMPLATE_MODEL string
TEXT_TEMPLATE_TABLENAME string
HAS_IS_DELETED bool
READY_FOLDERNAME string
TEXT_DB_MODIFIED_AT string
TEXT_DB_CREATED_AT string
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
READY_ALIAS_FILENAME string
NEED_CREATE_UPDATE_EVERY_COLUMN bool
}
func Getenv(Name string, IsRequired bool) string {
@ -426,6 +428,16 @@ func FillSettings() {
s = Getenv(Name, true)
Settings.TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME = s
//
Name = "TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME"
s = Getenv(Name, true)
Settings.TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME = s
//
Name = "TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME"
s = Getenv(Name, true)
Settings.TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME = s
}
// CurrentDirectory - возвращает текущую директорию ОС

View File

@ -372,27 +372,40 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
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
FilenameTemplateGRPC_ClientFunc := 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)
//читаем шаблон файла, только функции
bytes, err := os.ReadFile(FilenameTemplateGRPC_ClientFunc)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateGRPC_Client, " error: ", err)
log.Panic("ReadFile() ", FilenameTemplateGRPC_ClientFunc, " error: ", err)
}
TextGRPC_ClientUpdateFunc := string(bytes)
TextGRPC_Client_UpdateFunc := string(bytes)
TextGRPC_Client := "package " + config.Settings.PREFIX_CLIENT_GRPC + TableName + "\n\n"
TextGRPC_Client = TextGRPC_Client + `import (
"context"
"time"
"github.com/ManyakRus/starter/log"
)
//читаем шаблон файла, без функций
FilenameTemplateCrud := DirTemplatesGRPC_Client + config.Settings.TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME
bytes, err = os.ReadFile(FilenameTemplateCrud)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateCrud, " error: ", err)
}
TextGRPC_Client := string(bytes)
TextGRPC_Client = TextGRPC_Client + "\n"
`
//заменим имя пакета на новое
TextGRPC_Client = create_files.ReplacePackageName(TextGRPC_Client, DirReadyTable)
// TextGRPC_Client := "package " + config.Settings.PREFIX_CLIENT_GRPC + TableName + "\n\n"
// TextGRPC_Client = TextGRPC_Client + `import (
// "context"
// "time"
// "github.com/ManyakRus/starter/log"
//)
//
//`
//заменим импорты
if config.Settings.USE_DEFAULT_TEMPLATE == true {
@ -418,7 +431,7 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
}
//создание текста
TextUpdateEveryColumn := FindTextUpdateEveryColumn(TextGRPC_ClientUpdateFunc, Table1)
TextUpdateEveryColumn := FindTextUpdateEveryColumn(TextGRPC_Client_UpdateFunc, Table1)
// пустой файл не нужен
if TextUpdateEveryColumn == "" {
return err
@ -517,26 +530,39 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
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
FilenameTemplateGRPC_ClientFunc := 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)
//читаем шаблон файла, только функции
bytes, err := os.ReadFile(FilenameTemplateGRPC_ClientFunc)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateGRPC_Client, " error: ", err)
log.Panic("ReadFile() ", FilenameTemplateGRPC_ClientFunc, " error: ", err)
}
TextGRPC_ClientUpdateFunc := string(bytes)
TextGRPC_Client_UpdateFunc := string(bytes)
TextGRPC_Client := "package " + config.Settings.PREFIX_CLIENT_GRPC + TableName + "\n\n"
TextGRPC_Client = TextGRPC_Client + `import (
"testing"
"github.com/ManyakRus/starter/config_main"
)
//читаем шаблон файла, без функций
FilenameTemplateCrud := DirTemplatesGRPC_Client + config.Settings.TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME
bytes, err = os.ReadFile(FilenameTemplateCrud)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateCrud, " error: ", err)
}
TextGRPC_Client := string(bytes)
TextGRPC_Client = TextGRPC_Client + "\n"
`
//заменим имя пакета на новое
TextGRPC_Client = create_files.ReplacePackageName(TextGRPC_Client, DirReadyTable)
// TextGRPC_Client := "package " + config.Settings.PREFIX_CLIENT_GRPC + TableName + "\n\n"
// TextGRPC_Client = TextGRPC_Client + `import (
// "testing"
// "github.com/ManyakRus/starter/config_main"
//)
//
//`
//заменим импорты
//if config.Settings.USE_DEFAULT_TEMPLATE == true {
@ -550,7 +576,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
//}
//создание текста
TextUpdateEveryColumn := FindTextUpdateEveryColumnTest(TextGRPC_ClientUpdateFunc, Table1)
TextUpdateEveryColumn := FindTextUpdateEveryColumnTest(TextGRPC_Client_UpdateFunc, Table1)
// пустой файл не нужен
if TextUpdateEveryColumn == "" {
return err