diff --git a/bin/templates/db/db.go_ b/bin/templates/db/db.go_ index 9e7493b..0f89690 100644 --- a/bin/templates/db/db.go_ +++ b/bin/templates/db/db.go_ @@ -258,42 +258,42 @@ func (crud Crud_DB) Restore_ctx(ctx context.Context, m *model.LawsuitStatusType) return err } -//// Find_ByExtID - находит запись в БД по ext_id и connection_id -//func Find_ByExtID(ext_id int64, connection_id int64) (model.LawsuitStatusType, error) { -// var Otvet model.LawsuitStatusType -// var err error -// -// if ext_id <= 0 { -// err = errors.New("Error: ext_id <=0") -// return Otvet, err -// } -// -// // -// ctxMain := context.Background() -// ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) -// defer ctxCancelFunc() -// -// Otvet, err = Find_ByExtID_ctx(ctx, ext_id, connection_id) -// -// return Otvet, err -//} -// -//// Find_ByExtID_ctx - находит запись в БД по ext_id и connection_id -//func Find_ByExtID_ctx(ctx context.Context, ext_id int64, connection_id int64) (model.LawsuitStatusType, error) { -// var Otvet model.LawsuitStatusType -// var err error -// //log.Trace("start Find_ByExtID() ", TableName, " ext_id: ", ext_id) -// -// if ext_id <= 0 { -// err = errors.New("Error: ext_id <=0") -// return Otvet, err -// } -// -// db := postgres_gorm.GetConnection() -// db.WithContext(ctx) -// -// tx := db.Where("ext_id = ?", ext_id).Where("connection_id = ?", connection_id).First(&Otvet) -// err = tx.Error -// -// return Otvet, err -//} +// Find_ByExtID - находит запись в БД по ext_id и connection_id +func Find_ByExtID(ext_id int64, connection_id int64) (model.LawsuitStatusType, error) { + var Otvet model.LawsuitStatusType + var err error + + if ext_id <= 0 { + err = errors.New("Error: ext_id <=0") + return Otvet, err + } + + // + ctxMain := context.Background() + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS)) + defer ctxCancelFunc() + + Otvet, err = Find_ByExtID_ctx(ctx, ext_id, connection_id) + + return Otvet, err +} + +// Find_ByExtID_ctx - находит запись в БД по ext_id и connection_id +func Find_ByExtID_ctx(ctx context.Context, ext_id int64, connection_id int64) (model.LawsuitStatusType, error) { + var Otvet model.LawsuitStatusType + var err error + //log.Trace("start Find_ByExtID() ", TableName, " ext_id: ", ext_id) + + if ext_id <= 0 { + err = errors.New("Error: ext_id <=0") + return Otvet, err + } + + db := postgres_gorm.GetConnection() + db.WithContext(ctx) + + tx := db.Where("ext_id = ?", ext_id).Where("connection_id = ?", connection_id).First(&Otvet) + err = tx.Error + + return Otvet, err +} diff --git a/bin/templates/db/db_test.go_ b/bin/templates/db/db_test.go_ index 576b026..d3cbf5c 100644 --- a/bin/templates/db/db_test.go_ +++ b/bin/templates/db/db_test.go_ @@ -95,17 +95,17 @@ func TestDelete(t *testing.T) { } -//func TestFind_ByExtID(t *testing.T) { -// config.LoadEnv() -// postgres_gorm.Connect() -// defer postgres_gorm.CloseConnection() -// -// Otvet, err := Find_ByExtID(1, constants.CONNECTION_ID_TEST) -// if err != nil { -// t.Error("TestFind_ByExtID() error: ", err) -// } -// -// if Otvet.ID == 0 { -// t.Error("TestFind_ByExtID() error: ID =0") -// } -//} +func TestFind_ByExtID(t *testing.T) { + config.LoadEnv() + postgres_gorm.Connect() + defer postgres_gorm.CloseConnection() + + Otvet, err := Find_ByExtID(1, constants.CONNECTION_ID_TEST) + if err != nil { + t.Error("TestFind_ByExtID() error: ", err) + } + + if Otvet.ID == 0 { + t.Error("TestFind_ByExtID() error: ID =0") + } +} diff --git a/bin/templates/grpc_client/grpc_client.go_ b/bin/templates/grpc_client/grpc_client.go_ index 1e673e4..f1445c3 100644 --- a/bin/templates/grpc_client/grpc_client.go_ +++ b/bin/templates/grpc_client/grpc_client.go_ @@ -280,3 +280,43 @@ func (crud Crud_GRPC) Restore(m *model.LawsuitStatusType) error { return err } + +// Find_ByExtID - находит модель в БД по ext_id и connection_id +func (crud Crud_GRPC) Find_ByExtID(e *model.LawsuitStatusType) error { + //подключение + if grpc_client.Client == nil { + grpc_client.Connect() + } + + //подготовка запроса + var VersionModel = crud.GetVersionModel() + + Request := &grpc_proto.RequestExtId{} + Request.ExtId = e.ExtID + Request.ConnectionId = e.ConnectionID + Request.VersionModel = VersionModel + + ctxMain := context.Background() + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_SECONDS)) + defer ctxCancelFunc() + + //запрос + Response, err := grpc_client.Client.LawsuitStatusType_FindByExtId(ctx, Request) + if err != nil { + sError := err.Error() + if sError[0:len(constants.TEXT_ERROR_MODEL_VERSION)] == constants.TEXT_ERROR_MODEL_VERSION { + log.Panic("table: ", TableName, " error: ", err) + } + return err + } + + //ответ + sModel := Response.ModelString + err = json.Unmarshal([]byte(sModel), e) + if err != nil { + return err + } + + return err +} + diff --git a/bin/templates/grpc_client/grpc_client_test.go_ b/bin/templates/grpc_client/grpc_client_test.go_ index 21aa736..abc7136 100644 --- a/bin/templates/grpc_client/grpc_client_test.go_ +++ b/bin/templates/grpc_client/grpc_client_test.go_ @@ -150,3 +150,24 @@ func TestDelete(t *testing.T) { } } } + +func TestFindByExtID(t *testing.T) { + config.LoadEnv() + grpc_client.Connect() + defer grpc_client.CloseConnection() + + crud := Crud_GRPC{} + Otvet := model.LawsuitStatusType{} + Otvet.ExtID = 1 + Otvet.ConnectionID = constants.CONNECTION_ID_TEST + err := crud.Find_ByExtID(&Otvet) + + if err != nil { + t.Error("TestFindByExtID() error: ", err) + } + + if Otvet.ID == 0 { + t.Error("TestFindByExtID() error: ID =0") + } +} + diff --git a/bin/templates/grpc_server/grpc_server.go_ b/bin/templates/grpc_server/grpc_server.go_ index 3784fef..41e7fb2 100644 --- a/bin/templates/grpc_server/grpc_server.go_ +++ b/bin/templates/grpc_server/grpc_server.go_ @@ -6,8 +6,8 @@ import ( "gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/grpc/grpc_proto" ) -// LawsuitStatusTypes_Read - читает и возвращает модель из БД -func (s *ServerGRPC) LawsuitStatusTypes_Read(ctx context.Context, Request *grpc_proto.RequestId) (*grpc_proto.Response, error) { +// LawsuitStatusType_Read - читает и возвращает модель из БД +func (s *ServerGRPC) LawsuitStatusType_Read(ctx context.Context, Request *grpc_proto.RequestId) (*grpc_proto.Response, error) { var Otvet grpc_proto.Response var err error @@ -37,8 +37,8 @@ func (s *ServerGRPC) LawsuitStatusTypes_Read(ctx context.Context, Request *grpc_ return &Otvet, err } -// LawsuitStatusTypes_Delete - записывает в БД is_deleted = true и возвращает модель из БД -func (s *ServerGRPC) LawsuitStatusTypes_Delete(ctx context.Context, Request *grpc_proto.RequestId) (*grpc_proto.Response, error) { +// LawsuitStatusType_Delete - записывает в БД is_deleted = true и возвращает модель из БД +func (s *ServerGRPC) LawsuitStatusType_Delete(ctx context.Context, Request *grpc_proto.RequestId) (*grpc_proto.Response, error) { var Otvet grpc_proto.Response var err error @@ -68,8 +68,8 @@ func (s *ServerGRPC) LawsuitStatusTypes_Delete(ctx context.Context, Request *grp return &Otvet, err } -// LawsuitStatusTypes_Restore - записывает в БД is_deleted = false и возвращает модель из БД -func (s *ServerGRPC) LawsuitStatusTypes_Restore(ctx context.Context, Request *grpc_proto.RequestId) (*grpc_proto.Response, error) { +// LawsuitStatusType_Restore - записывает в БД is_deleted = false и возвращает модель из БД +func (s *ServerGRPC) LawsuitStatusType_Restore(ctx context.Context, Request *grpc_proto.RequestId) (*grpc_proto.Response, error) { var Otvet grpc_proto.Response var err error @@ -99,8 +99,8 @@ func (s *ServerGRPC) LawsuitStatusTypes_Restore(ctx context.Context, Request *gr return &Otvet, err } -// LawsuitStatusTypes_Create - создаёт новую запись в БД -func (s *ServerGRPC) LawsuitStatusTypes_Create(ctx context.Context, Request *grpc_proto.RequestModel) (*grpc_proto.Response, error) { +// LawsuitStatusType_Create - создаёт новую запись в БД +func (s *ServerGRPC) LawsuitStatusType_Create(ctx context.Context, Request *grpc_proto.RequestModel) (*grpc_proto.Response, error) { var Otvet grpc_proto.Response var err error @@ -135,8 +135,8 @@ func (s *ServerGRPC) LawsuitStatusTypes_Create(ctx context.Context, Request *grp return &Otvet, err } -// LawsuitStatusTypes_Update - обновляет новую запись в БД -func (s *ServerGRPC) LawsuitStatusTypes_Update(ctx context.Context, Request *grpc_proto.RequestModel) (*grpc_proto.Response, error) { +// LawsuitStatusType_Update - обновляет новую запись в БД +func (s *ServerGRPC) LawsuitStatusType_Update(ctx context.Context, Request *grpc_proto.RequestModel) (*grpc_proto.Response, error) { var Otvet grpc_proto.Response var err error @@ -171,8 +171,8 @@ func (s *ServerGRPC) LawsuitStatusTypes_Update(ctx context.Context, Request *grp return &Otvet, err } -// LawsuitStatusTypes_Save - записывает (создаёт или обновляет) запись в БД -func (s *ServerGRPC) LawsuitStatusTypes_Save(ctx context.Context, Request *grpc_proto.RequestModel) (*grpc_proto.Response, error) { +// LawsuitStatusType_Save - записывает (создаёт или обновляет) запись в БД +func (s *ServerGRPC) LawsuitStatusType_Save(ctx context.Context, Request *grpc_proto.RequestModel) (*grpc_proto.Response, error) { var Otvet grpc_proto.Response var err error @@ -206,3 +206,36 @@ func (s *ServerGRPC) LawsuitStatusTypes_Save(ctx context.Context, Request *grpc_ return &Otvet, err } + +// LawsuitStatusType_FindByExtID - возвращает запись из БД по ext_id и connection_id +func (s *ServerGRPC) LawsuitStatusType_FindByExtID(ctx context.Context, Request *grpc_proto.RequestExtId) (*grpc_proto.Response, error) { + var Otvet grpc_proto.Response + var err error + + //проверим совпадения версии модели + VersionServer := model.LawsuitStatusType{}.GetStructVersion() + VersionClient := Request.VersionModel + if VersionServer != VersionClient { + err = ErrorModelVersion(model.Employee{}) + return &Otvet, err + } + + //запрос в БД + Model := &model.LawsuitStatusType{} + Model.ExtID = Request.ExtId + Model.ConnectionID = Request.ConnectionId + err = Model.Find_ByExtID() + if err != nil { + return &Otvet, err + } + + //заполяем ответ + ModelString, err := Model.GetJSON() + if err != nil { + return &Otvet, err + } + Otvet.ModelString = ModelString + + return &Otvet, err +} + diff --git a/bin/templates/grpc_server/grpc_server_test.go_ b/bin/templates/grpc_server/grpc_server_test.go_ index db5daf4..77b4c7c 100644 --- a/bin/templates/grpc_server/grpc_server_test.go_ +++ b/bin/templates/grpc_server/grpc_server_test.go_ @@ -12,7 +12,7 @@ import ( // LawsuitStatusType_ID_Test - ID таблицы для тестирования const LawsuitStatusType_ID_Test = 1 -func Test_server_LawsuitStatusTypes_Read(t *testing.T) { +func Test_server_LawsuitStatusType_Read(t *testing.T) { //t.SkipNow() config.LoadEnv() crud_starter.InitCrudTransport_DB() @@ -23,7 +23,7 @@ func Test_server_LawsuitStatusTypes_Read(t *testing.T) { Request.VersionModel = model.LawsuitStatusType{}.GetStructVersion() server1 := &ServerGRPC{} - Otvet, err := server1.LawsuitStatusTypes_Read(ctx, &Request) + Otvet, err := server1.LawsuitStatusType_Read(ctx, &Request) if err != nil { t.Error("Test_server_LawsuitStatusType_Read() error: ", err) } @@ -32,7 +32,7 @@ func Test_server_LawsuitStatusTypes_Read(t *testing.T) { } } -func Test_server_LawsuitStatusTypes_Delete(t *testing.T) { +func Test_server_LawsuitStatusType_Delete(t *testing.T) { config.LoadEnv() crud_starter.InitCrudTransport_DB() @@ -42,17 +42,17 @@ func Test_server_LawsuitStatusTypes_Delete(t *testing.T) { Request.VersionModel = model.LawsuitStatusType{}.GetStructVersion() server1 := &ServerGRPC{} - Otvet, err := server1.LawsuitStatusTypes_Delete(ctx, &Request) + Otvet, err := server1.LawsuitStatusType_Delete(ctx, &Request) if err != nil { t.Error("Test_server_LawsuitStatusType_Delete() error: ", err) } if Otvet.ModelString == "" { t.Error("Test_server_LawsuitStatusType_Delete() error: ModelString=''") } - Otvet, err = server1.LawsuitStatusTypes_Restore(ctx, &Request) + Otvet, err = server1.LawsuitStatusType_Restore(ctx, &Request) } -func Test_server_LawsuitStatusTypes_Create(t *testing.T) { +func Test_server_LawsuitStatusType_Create(t *testing.T) { config.LoadEnv() crud_starter.InitCrudTransport_DB() @@ -71,7 +71,7 @@ func Test_server_LawsuitStatusTypes_Create(t *testing.T) { ctx := context.Background() server1 := &ServerGRPC{} - Otvet, err := server1.LawsuitStatusTypes_Create(ctx, &RequestModel) + Otvet, err := server1.LawsuitStatusType_Create(ctx, &RequestModel) if err == nil { t.Error("Test_server_LawsuitStatusType_Create() error: ", err) } @@ -80,7 +80,7 @@ func Test_server_LawsuitStatusTypes_Create(t *testing.T) { } } -func Test_server_LawsuitStatusTypes_Update(t *testing.T) { +func Test_server_LawsuitStatusType_Update(t *testing.T) { config.LoadEnv() crud_starter.InitCrudTransport_DB() @@ -90,7 +90,7 @@ func Test_server_LawsuitStatusTypes_Update(t *testing.T) { Request.VersionModel = model.LawsuitStatusType{}.GetStructVersion() server1 := &ServerGRPC{} - Response1, err := server1.LawsuitStatusTypes_Read(ctx, &Request) + Response1, err := server1.LawsuitStatusType_Read(ctx, &Request) if err != nil { t.Error("Test_server_LawsuitStatusType_Update() error: ", err) return @@ -106,7 +106,7 @@ func Test_server_LawsuitStatusTypes_Update(t *testing.T) { RequestModel.VersionModel = model.LawsuitStatusType{}.GetStructVersion() RequestModel.ModelString = ModelString - Otvet, err := server1.LawsuitStatusTypes_Update(ctx, &RequestModel) + Otvet, err := server1.LawsuitStatusType_Update(ctx, &RequestModel) if err != nil { t.Error("Test_server_LawsuitStatusType_Update() error: ", err) } @@ -116,7 +116,7 @@ func Test_server_LawsuitStatusTypes_Update(t *testing.T) { } -func Test_server_LawsuitStatusTypes_Save(t *testing.T) { +func Test_server_LawsuitStatusType_Save(t *testing.T) { config.LoadEnv() crud_starter.InitCrudTransport_DB() @@ -128,7 +128,7 @@ func Test_server_LawsuitStatusTypes_Save(t *testing.T) { Request.VersionModel = model.LawsuitStatusType{}.GetStructVersion() server1 := &ServerGRPC{} - Response1, err := server1.LawsuitStatusTypes_Read(ctx, &Request) + Response1, err := server1.LawsuitStatusType_Read(ctx, &Request) if err != nil { t.Error("Test_server_LawsuitStatusType_Save() error: ", err) return @@ -142,7 +142,7 @@ func Test_server_LawsuitStatusTypes_Save(t *testing.T) { RequestModel.VersionModel = model.LawsuitStatusType{}.GetStructVersion() RequestModel.ModelString = ModelString - Otvet, err := server1.LawsuitStatusTypes_Save(ctx, &RequestModel) + Otvet, err := server1.LawsuitStatusType_Save(ctx, &RequestModel) if err != nil { t.Error("Test_server_LawsuitStatusType_Save() error: ", err) } @@ -151,3 +151,24 @@ func Test_server_LawsuitStatusTypes_Save(t *testing.T) { } } + +func Test_server_LawsuitStatusType_FindByExtID(t *testing.T) { + config.LoadEnv() + crud_starter.InitCrudTransport_DB() + + ctx := context.Background() + Request := grpc_proto.RequestExtId{} + Request.ExtId = 1 + Request.ConnectionId = 3 + Request.VersionModel = model.Employee{}.GetStructVersion() + + server1 := &ServerGRPC{} + Otvet, err := server1.LawsuitStatusType_FindByExtId(ctx, &Request) + if err != nil { + t.Error("Test_server_LawsuitStatusType_FindByExtId() error: ", err) + } + if Otvet.ModelString == "" { + t.Error("Test_server_LawsuitStatusType_FindByExtId() error: ModelString=''") + } +} + diff --git a/bin/templates/model/model.go_ b/bin/templates/model/model.go_ index 74db479..a324f75 100644 --- a/bin/templates/model/model.go_ +++ b/bin/templates/model/model.go_ @@ -26,6 +26,7 @@ type ICrud_LawsuitStatusType interface { Create(*LawsuitStatusType) error Delete(*LawsuitStatusType) error Restore(*LawsuitStatusType) error + Find_ByExtID(*LawsuitStatusType) error } // TableName - возвращает имя таблицы в БД, нужен для gorm @@ -135,6 +136,13 @@ func (m *LawsuitStatusType) Restore() error { return err } +// Find_ByExtID - находит объект по ExtID +func (m *LawsuitStatusType) Find_ByExtID() error { + err := crud_LawsuitStatusType.Find_ByExtID(m) + + return err +} + // SetCrudInterface - заполняет интерфейс crud: DB, GRPC, NRPC func (m LawsuitStatusType) SetCrudInterface(crud ICrud_LawsuitStatusType) { crud_LawsuitStatusType = crud diff --git a/bin/templates/nrpc_client/nrpc_client.go_ b/bin/templates/nrpc_client/nrpc_client.go_ index 934663a..984e09f 100644 --- a/bin/templates/nrpc_client/nrpc_client.go_ +++ b/bin/templates/nrpc_client/nrpc_client.go_ @@ -254,3 +254,39 @@ func (crud Crud_NRPC) Restore(l *model.LawsuitStatusType) error { return err } + +// Find_ByExtID - находит модель в БД по ext_id и connection_id +func (crud Crud_NRPC) Find_ByExtID(e *model.LawsuitStatusType) error { + //подключение + if nrpc_client.Client == nil { + nrpc_client.Connect() + } + + //подготовка запроса + var VersionModel = crud.GetVersionModel() + + Request := &grpc_proto.RequestExtId{} + Request.ExtId = e.ExtID + Request.ConnectionId = e.ConnectionID + Request.VersionModel = VersionModel + + //запрос + Response, err := nrpc_client.Client.LawsuitStatusType_FindByExtId(Request) + if err != nil { + sError := err.Error() + if sError[0:len(constants.TEXT_ERROR_MODEL_VERSION)] == constants.TEXT_ERROR_MODEL_VERSION { + log.Panic("table: ", TableName, " error: ", err) + } + return err + } + + //ответ + sModel := Response.ModelString + err = json.Unmarshal([]byte(sModel), e) + if err != nil { + return err + } + + return err +} + diff --git a/bin/templates/nrpc_client/nrpc_client_test.go_ b/bin/templates/nrpc_client/nrpc_client_test.go_ index d923c39..d56ab3d 100644 --- a/bin/templates/nrpc_client/nrpc_client_test.go_ +++ b/bin/templates/nrpc_client/nrpc_client_test.go_ @@ -150,3 +150,24 @@ func TestDelete(t *testing.T) { } } } + +func TestFindByExtID(t *testing.T) { + config.LoadEnv() + nrpc_client.Connect() + defer nrpc_client.CloseConnection() + + crud := Crud_NRPC{} + Otvet := model.LawsuitStatusType{} + Otvet.ExtID = 1 + Otvet.ConnectionID = constants.CONNECTION_ID_TEST + err := crud.Find_ByExtID(&Otvet) + + if err != nil { + t.Error("TestFindByExtId() error: ", err) + } + + if Otvet.ID == 0 { + t.Error("TestFindByExtId() error: ID =0") + } +} + diff --git a/internal/create_files/db/db.go b/internal/create_files/db/db.go index 9331ef3..a19fb0e 100644 --- a/internal/create_files/db/db.go +++ b/internal/create_files/db/db.go @@ -78,6 +78,7 @@ func CreateFiles(Table1 *types.Table) error { TextDB = DeleteFuncRestoreCtx(TextDB, Table1) } TextDB = DeleteFuncFind_byExtID(TextDB, Table1) + TextDB = DeleteFuncFind_byExtIDCtx(TextDB, Table1) TextDB = AddTextOmit(TextDB, Table1) //запись файла @@ -124,12 +125,10 @@ func CreateTestFiles(Table1 *types.Table) error { TextDB = constants.TEXT_GENERATED + TextDB if config.Settings.HAS_IS_DELETED == true { - TextDB = DeleteFuncDelete(TextDB, Table1) - TextDB = DeleteFuncDeleteCtx(TextDB, Table1) - TextDB = DeleteFuncRestore(TextDB, Table1) - TextDB = DeleteFuncRestoreCtx(TextDB, Table1) + TextDB = DeleteFuncTestDelete(TextDB, Table1) + TextDB = DeleteFuncTestRestore(TextDB, Table1) } - TextDB = DeleteFuncFind_byExtID(TextDB, Table1) + TextDB = DeleteFuncTestFind_byExtID(TextDB, Table1) //запись файла err = os.WriteFile(FilenameReadyDB, []byte(TextDB), constants.FILE_PERMISSIONS) @@ -197,23 +196,34 @@ func DeleteFuncRestoreCtx(Text string, Table1 *types.Table) string { func DeleteFuncFind_byExtID(Text string, Table1 *types.Table) string { Otvet := Text - // - _, ok := Table1.MapColumns["ext_id"] + //если есть обе колонки - ничего не делаем + ok := create_files.Has_Column_ExtID_ConnectionID(Table1) if ok == true { return Otvet } // - _, ok = Table1.MapColumns["connection_id"] - if ok == true { - return Otvet - } - Otvet = create_files.DeleteFuncFromComment(Text, "\n// Find_ByExtID ") return Otvet } +// DeleteFuncFind_byExtIDCtx - удаляет функцию Find_ByExtID_ctx() +func DeleteFuncFind_byExtIDCtx(Text string, Table1 *types.Table) string { + Otvet := Text + + //если есть обе колонки - ничего не делаем + ok := create_files.Has_Column_ExtID_ConnectionID(Table1) + if ok == true { + return Otvet + } + + // + Otvet = create_files.DeleteFuncFromComment(Text, "\n// Find_ByExtID_ctx ") + + return Otvet +} + // DeleteFuncTestDelete - удаляет функцию Delete() func DeleteFuncTestDelete(Text string, Table1 *types.Table) string { Otvet := Text @@ -246,18 +256,13 @@ func DeleteFuncTestRestore(Text string, Table1 *types.Table) string { func DeleteFuncTestFind_byExtID(Text string, Table1 *types.Table) string { Otvet := Text - // - _, ok := Table1.MapColumns["ext_id"] + //если есть обе колонки - ничего не делаем + ok := create_files.Has_Column_ExtID_ConnectionID(Table1) if ok == true { return Otvet } // - _, ok = Table1.MapColumns["connection_id"] - if ok == true { - return Otvet - } - Otvet = create_files.DeleteFuncFromFuncName(Otvet, "TestFind_ByExtID") return Otvet diff --git a/internal/create_files/grpc_client/grpc_client.go b/internal/create_files/grpc_client/grpc_client.go index 16af7a5..b123e79 100644 --- a/internal/create_files/grpc_client/grpc_client.go +++ b/internal/create_files/grpc_client/grpc_client.go @@ -123,12 +123,10 @@ func CreateTestFiles(Table1 *types.Table) error { TextDB = constants.TEXT_GENERATED + TextDB if config.Settings.HAS_IS_DELETED == true { - TextDB = DeleteFuncDelete(TextDB, ModelName, Table1) - //TextDB = DeleteFuncDeleteCtx(TextDB, ModelName, Table1) - TextDB = DeleteFuncRestore(TextDB, ModelName, Table1) - //TextDB = DeleteFuncRestoreCtx(TextDB, ModelName, Table1) + TextDB = DeleteFuncTestDelete(TextDB, ModelName, Table1) + TextDB = DeleteFuncTestRestore(TextDB, ModelName, Table1) } - TextDB = DeleteFuncFind_byExtID(TextDB, ModelName, Table1) + TextDB = DeleteFuncTestFind_byExtID(TextDB, ModelName, Table1) //запись файла err = os.WriteFile(FilenameReadyGRPCClient, []byte(TextDB), constants.FILE_PERMISSIONS) @@ -196,18 +194,13 @@ func DeleteFuncRestoreCtx(Text, ModelName string, Table1 *types.Table) string { func DeleteFuncFind_byExtID(Text, ModelName string, Table1 *types.Table) string { Otvet := Text - // - _, ok := Table1.MapColumns["ext_id"] + //если есть обе колонки - ничего не делаем + ok := create_files.Has_Column_ExtID_ConnectionID(Table1) if ok == true { return Otvet } // - _, ok = Table1.MapColumns["connection_id"] - if ok == true { - return Otvet - } - Otvet = create_files.DeleteFuncFromComment(Text, "\n// Find_ByExtID ") return Otvet @@ -245,19 +238,14 @@ func DeleteFuncTestRestore(Text, ModelName string, Table1 *types.Table) string { func DeleteFuncTestFind_byExtID(Text, ModelName string, Table1 *types.Table) string { Otvet := Text - // - _, ok := Table1.MapColumns["ext_id"] + //если есть обе колонки - ничего не делаем + ok := create_files.Has_Column_ExtID_ConnectionID(Table1) if ok == true { return Otvet } // - _, ok = Table1.MapColumns["connection_id"] - if ok == true { - return Otvet - } - - Otvet = create_files.DeleteFuncFromFuncName(Otvet, "TestFind_ByExtID") + Otvet = create_files.DeleteFuncFromFuncName(Otvet, "TestFindByExtID") return Otvet } diff --git a/internal/create_files/grpc_server/grpc_server.go b/internal/create_files/grpc_server/grpc_server.go index 3eb38af..6f338a3 100644 --- a/internal/create_files/grpc_server/grpc_server.go +++ b/internal/create_files/grpc_server/grpc_server.go @@ -105,12 +105,10 @@ func CreateTestFiles(Table1 *types.Table) error { TextDB = constants.TEXT_GENERATED + TextDB if config.Settings.HAS_IS_DELETED == true { - TextDB = DeleteFuncDelete(TextDB, ModelName, Table1) - TextDB = DeleteFuncDeleteCtx(TextDB, ModelName, Table1) - TextDB = DeleteFuncRestore(TextDB, ModelName, Table1) - TextDB = DeleteFuncRestoreCtx(TextDB, ModelName, Table1) + TextDB = DeleteFuncTestDelete(TextDB, ModelName, Table1) + TextDB = DeleteFuncTestRestore(TextDB, ModelName, Table1) } - TextDB = DeleteFuncFind_byExtID(TextDB, ModelName, Table1) + TextDB = DeleteFuncTestFind_byExtID(TextDB, ModelName, Table1) //запись файла err = os.WriteFile(FilenameReadyGRPCServer, []byte(TextDB), constants.FILE_PERMISSIONS) @@ -178,19 +176,14 @@ func DeleteFuncRestoreCtx(Text, ModelName string, Table1 *types.Table) string { func DeleteFuncFind_byExtID(Text, ModelName string, Table1 *types.Table) string { Otvet := Text - // - _, ok := Table1.MapColumns["ext_id"] + //если есть обе колонки - ничего не делаем + ok := create_files.Has_Column_ExtID_ConnectionID(Table1) if ok == true { return Otvet } // - _, ok = Table1.MapColumns["connection_id"] - if ok == true { - return Otvet - } - - Otvet = create_files.DeleteFuncFromComment(Text, "\n// "+ModelName+"_Find_ByExtID ") + Otvet = create_files.DeleteFuncFromComment(Text, "\n// "+ModelName+"_FindByExtID ") return Otvet } @@ -227,19 +220,14 @@ func DeleteFuncTestRestore(Text, ModelName string, Table1 *types.Table) string { func DeleteFuncTestFind_byExtID(Text, ModelName string, Table1 *types.Table) string { Otvet := Text - // - _, ok := Table1.MapColumns["ext_id"] + //если есть обе колонки - ничего не делаем + ok := create_files.Has_Column_ExtID_ConnectionID(Table1) if ok == true { return Otvet } // - _, ok = Table1.MapColumns["connection_id"] - if ok == true { - return Otvet - } - - Otvet = create_files.DeleteFuncFromFuncName(Otvet, "Test_server_"+ModelName+"Find_ByExtID") + Otvet = create_files.DeleteFuncFromFuncName(Otvet, "Test_server_"+ModelName+"_FindByExtID") return Otvet } diff --git a/internal/create_files/model/model.go b/internal/create_files/model/model.go index b14cd97..8187506 100644 --- a/internal/create_files/model/model.go +++ b/internal/create_files/model/model.go @@ -309,14 +309,14 @@ func DeleteFuncFind_byExtID(TextModel, Modelname string, Table1 *types.Table) st Otvet := TextModel // - _, ok := Table1.MapColumns["ext_id"] - if ok == true { - return Otvet - } + _, ok1 := Table1.MapColumns["ext_id"] + //if ok == false { + // return Otvet + //} // - _, ok = Table1.MapColumns["connection_id"] - if ok == true { + _, ok2 := Table1.MapColumns["connection_id"] + if ok1 == true && ok2 == true { return Otvet } diff --git a/internal/create_files/nrpc_client/nrpc_client.go b/internal/create_files/nrpc_client/nrpc_client.go index acdd095..beab1b6 100644 --- a/internal/create_files/nrpc_client/nrpc_client.go +++ b/internal/create_files/nrpc_client/nrpc_client.go @@ -123,12 +123,10 @@ func CreateTestFiles(Table1 *types.Table) error { TextDB = constants.TEXT_GENERATED + TextDB if config.Settings.HAS_IS_DELETED == true { - TextDB = DeleteFuncDelete(TextDB, ModelName, Table1) - //TextDB = DeleteFuncDeleteCtx(TextDB, ModelName, Table1) - TextDB = DeleteFuncRestore(TextDB, ModelName, Table1) - //TextDB = DeleteFuncRestoreCtx(TextDB, ModelName, Table1) + TextDB = DeleteFuncTestDelete(TextDB, ModelName, Table1) + TextDB = DeleteFuncTestRestore(TextDB, ModelName, Table1) } - TextDB = DeleteFuncFind_byExtID(TextDB, ModelName, Table1) + TextDB = DeleteFuncTestFind_byExtID(TextDB, ModelName, Table1) //запись файла err = os.WriteFile(FilenameReadyNRPCClient, []byte(TextDB), constants.FILE_PERMISSIONS) @@ -196,18 +194,13 @@ func DeleteFuncRestoreCtx(Text, ModelName string, Table1 *types.Table) string { func DeleteFuncFind_byExtID(Text, ModelName string, Table1 *types.Table) string { Otvet := Text - // - _, ok := Table1.MapColumns["ext_id"] + //если есть обе колонки - ничего не делаем + ok := create_files.Has_Column_ExtID_ConnectionID(Table1) if ok == true { return Otvet } // - _, ok = Table1.MapColumns["connection_id"] - if ok == true { - return Otvet - } - Otvet = create_files.DeleteFuncFromComment(Text, "\n// Find_ByExtID ") return Otvet @@ -245,19 +238,15 @@ func DeleteFuncTestRestore(Text, ModelName string, Table1 *types.Table) string { func DeleteFuncTestFind_byExtID(Text, ModelName string, Table1 *types.Table) string { Otvet := Text - // - _, ok := Table1.MapColumns["ext_id"] + //если есть обе колонки - ничего не делаем + ok := create_files.Has_Column_ExtID_ConnectionID(Table1) if ok == true { return Otvet } // - _, ok = Table1.MapColumns["connection_id"] - if ok == true { - return Otvet - } - Otvet = create_files.DeleteFuncFromFuncName(Otvet, "TestFind_ByExtID") + Otvet = create_files.DeleteFuncFromFuncName(Otvet, "TestFindByExtID") return Otvet }