1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2025-01-03 01:22:21 +02:00

сделал ReadFromCache()

This commit is contained in:
Nikitin Aleksandr 2024-03-12 17:19:36 +03:00
parent 60096ccaae
commit e24027043e
7 changed files with 50 additions and 133 deletions

View File

@ -226,5 +226,5 @@ NEED_CREATE_CACHE_TEST_FILES=true
#TEMPLATES_GRPC_CLIENT_TABLES_CACHE_FILENAME - short filename of "grpc_client_table_cache.go_" file #TEMPLATES_GRPC_CLIENT_TABLES_CACHE_FILENAME - short filename of "grpc_client_table_cache.go_" file
TEMPLATES_GRPC_CLIENT_TABLES_CACHE_FILENAME="grpc_client_table_cache.go_" TEMPLATES_GRPC_CLIENT_TABLES_CACHE_FILENAME="grpc_client_table_cache.go_"
#TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME - short filename of "grpc_client_table_cache.go_" file #TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME - short filename of "grpc_client_table_cache_test.go_" file
TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME="grpc_client_table_cache.go_" TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME="grpc_client_table_cache_test.go_"

View File

@ -14,7 +14,8 @@ import (
) )
// ReadFromCache - возвращает модель из БД // ReadFromCache - возвращает модель из БД
func (crud Crud_GRPC) ReadFromCache(m *lawsuit_status_types.LawsuitStatusType) error { func (crud Crud_GRPC) ReadFromCache(ID int64) (lawsuit_status_types.LawsuitStatusType, error) {
Otvet := lawsuit_status_types.LawsuitStatusType{}
var err error var err error
// подключение // подключение
@ -24,7 +25,7 @@ func (crud Crud_GRPC) ReadFromCache(m *lawsuit_status_types.LawsuitStatusType) e
var versionModel = crud.GetVersionModel() var versionModel = crud.GetVersionModel()
Request := &grpc_proto.RequestId{} Request := &grpc_proto.RequestId{}
Request.ID = int64(m.ID) Request.ID = ID
Request.VersionModel = versionModel Request.VersionModel = versionModel
ctxMain := context.Background() ctxMain := context.Background()
@ -42,15 +43,15 @@ func (crud Crud_GRPC) ReadFromCache(m *lawsuit_status_types.LawsuitStatusType) e
if grpc_client.IsErrorModelVersion(err) == true { if grpc_client.IsErrorModelVersion(err) == true {
log.Panic(err) log.Panic(err)
} }
return err return Otvet, err
} }
// ответ // ответ
sModel := Response.ModelString sModel := Response.ModelString
err = json.Unmarshal([]byte(sModel), m) err = json.Unmarshal([]byte(sModel), &Otvet)
if err != nil { if err != nil {
return err return Otvet, err
} }
return err return Otvet, err
} }

View File

@ -14,8 +14,7 @@ func TestReadFromCache(t *testing.T) {
crud := Crud_GRPC{} crud := Crud_GRPC{}
Otvet := lawsuit_status_types.LawsuitStatusType{} Otvet := lawsuit_status_types.LawsuitStatusType{}
Otvet.ID = Postgres_ID_Test Otvet, err := crud.ReadFromCache(Postgres_ID_Test)
err := crud.ReadFromCache(&Otvet)
if err != nil { if err != nil {
t.Error("ReadFromCache() error: ", err) t.Error("ReadFromCache() error: ", err)

View File

@ -6,111 +6,3 @@ import (
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing" "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

@ -54,7 +54,7 @@ func CreateAllFiles(MapAll map[string]*types.Table) error {
} }
//тестовые файлы db update //тестовые файлы db update
err = CreateTestFilesUpdateEveryColumn(Table1) err = CreateFilesUpdateEveryColumnTest(Table1)
if err != nil { if err != nil {
log.Error("CreateTestFiles() table: ", Table1.Name, " error: ", err) log.Error("CreateTestFiles() table: ", Table1.Name, " error: ", err)
return err return err
@ -637,8 +637,8 @@ func FindTextUpdateEveryColumn1(TextCrudUpdateFunc string, Table1 *types.Table,
return Otvet return Otvet
} }
// CreateTestFilesUpdateEveryColumn - создаёт 1 файл в папке grpc_client // CreateFilesUpdateEveryColumnTest - создаёт 1 файл в папке grpc_client
func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { func CreateFilesUpdateEveryColumnTest(Table1 *types.Table) error {
var err error var err error
TableName := strings.ToLower(Table1.Name) TableName := strings.ToLower(Table1.Name)
@ -692,7 +692,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
ModelTableURL := create_files.FindModelTableURL(TableName) ModelTableURL := create_files.FindModelTableURL(TableName)
TextCrud = create_files.AddImport(TextCrud, ModelTableURL) TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
TextCrud = create_files.ConvertRequestIdToAlias(TextCrud, Table1) //TextCrud = create_files.ConvertRequestIdToAlias(TextCrud, Table1)
} }
//создание текста //создание текста
@ -874,11 +874,11 @@ func CreateFilesCacheTest(Table1 *types.Table) error {
if config.Settings.USE_DEFAULT_TEMPLATE == true { if config.Settings.USE_DEFAULT_TEMPLATE == true {
TextCache = create_files.DeleteTemplateRepositoryImports(TextCache) TextCache = create_files.DeleteTemplateRepositoryImports(TextCache)
DBConstantsURL := create_files.FindDBConstantsURL() //DBConstantsURL := create_files.FindDBConstantsURL()
TextCache = create_files.AddImport(TextCache, DBConstantsURL) //TextCache = create_files.AddImport(TextCache, DBConstantsURL)
//
ModelTableURL := create_files.FindModelTableURL(TableName) //ModelTableURL := create_files.FindModelTableURL(TableName)
TextCache = create_files.AddImport(TextCache, ModelTableURL) //TextCache = create_files.AddImport(TextCache, ModelTableURL)
//TextCache = create_files.ConvertRequestIdToAlias(TextCache, Table1) //TextCache = create_files.ConvertRequestIdToAlias(TextCache, Table1)
} }
@ -895,6 +895,9 @@ func CreateFilesCacheTest(Table1 *types.Table) error {
//удаление пустых строк //удаление пустых строк
TextCache = create_files.DeleteEmptyLines(TextCache) TextCache = create_files.DeleteEmptyLines(TextCache)
//SkipNow() если нет строк в БД
TextCache = create_files.AddSkipNow(TextCache, Table1)
//запись файла //запись файла
err = os.WriteFile(FilenameReadyCache, []byte(TextCache), constants.FILE_PERMISSIONS) err = os.WriteFile(FilenameReadyCache, []byte(TextCache), constants.FILE_PERMISSIONS)

View File

@ -778,8 +778,30 @@ func CreateFiles_GRPC_Client_Cache_Test(Table1 *types.Table) error {
ModelTableName := create_files.FindModelTableURL(TableName) ModelTableName := create_files.FindModelTableURL(TableName)
TextGRPCClient = create_files.AddImport(TextGRPCClient, ModelTableName) TextGRPCClient = create_files.AddImport(TextGRPCClient, ModelTableName)
////proto
//RepositoryGRPCProtoURL := create_files.FindProtoURL()
//TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCProtoURL)
//
////nrpc client
//RepositoryNRPCClientlURL := create_files.FindNRPClientURL()
//TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryNRPCClientlURL)
//
////grpc_nrpc
//GRPC_NRPC_URL := create_files.Find_GRPC_NRPC_URL()
//TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPC_NRPC_URL)
//
////constants GRPC
//RepositoryGRPCConstantsURL := create_files.FindGRPCConstantsURL()
//TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCConstantsURL)
} }
//создание текста
ModelName := Table1.NameGo
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
// замена ID на PrimaryKey // замена ID на PrimaryKey
TextGRPCClient = create_files.ReplacePrimaryKeyID(TextGRPCClient, Table1) TextGRPCClient = create_files.ReplacePrimaryKeyID(TextGRPCClient, Table1)
@ -795,9 +817,6 @@ func CreateFiles_GRPC_Client_Cache_Test(Table1 *types.Table) error {
//удаление пустых строк //удаление пустых строк
TextGRPCClient = create_files.DeleteEmptyLines(TextGRPCClient) TextGRPCClient = create_files.DeleteEmptyLines(TextGRPCClient)
//добавим комментарий в начало файла
TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient
//запись файла //запись файла
err = os.WriteFile(FilenameReadyCache, []byte(TextGRPCClient), constants.FILE_PERMISSIONS) err = os.WriteFile(FilenameReadyCache, []byte(TextGRPCClient), constants.FILE_PERMISSIONS)

View File

@ -750,13 +750,16 @@ func CreateFilesCacheTest(Table1 *types.Table) error {
TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer
if config.Settings.USE_DEFAULT_TEMPLATE == true { //if config.Settings.USE_DEFAULT_TEMPLATE == true {
TextGRPCServer = create_files.ConvertRequestIdToAlias(TextGRPCServer, Table1) // TextGRPCServer = create_files.ConvertRequestIdToAlias(TextGRPCServer, Table1)
} //}
//удаление пустого импорта //удаление пустого импорта
TextGRPCServer = create_files.DeleteEmptyImport(TextGRPCServer) TextGRPCServer = create_files.DeleteEmptyImport(TextGRPCServer)
//SkipNow()
TextGRPCServer = create_files.AddSkipNow(TextGRPCServer, Table1)
//запись файла //запись файла
err = os.WriteFile(FilenameReadyCache, []byte(TextGRPCServer), constants.FILE_PERMISSIONS) err = os.WriteFile(FilenameReadyCache, []byte(TextGRPCServer), constants.FILE_PERMISSIONS)