diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_readall.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_readall.go_ new file mode 100644 index 0000000..e56ef85 --- /dev/null +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_readall.go_ @@ -0,0 +1,10 @@ +package server_grpc + +import ( + "context" + "github.com/ManyakRus/starter/postgres_gorm" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/crud/crud_lawsuit_status_types" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" +) + diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_readall_function.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_readall_function.go_ new file mode 100644 index 0000000..aa015ba --- /dev/null +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_readall_function.go_ @@ -0,0 +1,32 @@ +// LawsuitStatusType_ReadAll - находит все строки lawsuit_status_types в БД +func (s *ServerGRPC) LawsuitStatusType_ReadAll(ctx context.Context, Request *grpc_proto.RequestEmpty) (*grpc_proto.ResponseMass, error) { + var Otvet grpc_proto.ResponseMass + var err error + + // проверим совпадения версии модели + VersionServer := lawsuit_status_types.LawsuitStatusType{}.GetStructVersion() + VersionClient := Request.VersionModel + if VersionServer != VersionClient { + err = ErrorModelVersion(lawsuit_status_types.LawsuitStatusType{}) + return &Otvet, err + } + + // запрос в БД + db := postgres_gorm.GetConnection() + Mass, err := crud_lawsuit_status_types.ReadAll_ctx(ctx, db) + if err != nil { + return &Otvet, err + } + + // заполяем ответ + for _, v := range Mass { + ModelString, err := v.GetJSON() + if err != nil { + return &Otvet, err + } + Otvet.MassModelString = append(Otvet.MassModelString, ModelString) + } + + return &Otvet, err +} + diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_readall_function_test.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_readall_function_test.go_ new file mode 100644 index 0000000..9faaf2f --- /dev/null +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_readall_function_test.go_ @@ -0,0 +1,16 @@ +func Test_server_LawsuitStatusType_FindMassBy_FieldNamesWithUnderline(t *testing.T) { + config_main.LoadEnv() + crud_starter.InitCrudTransport_DB() + + ctx := context.Background() + Request := grpc_proto.RequestName{} + Request.RequestFieldName = 0 + Request.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion() + + server1 := &ServerGRPC{} + _, err := server1.LawsuitStatusType_FindMassBy_FieldNamesWithUnderline(ctx, &Request) + if err != nil && crud_func.IsRecordNotFound(err) == false { + t.Error("Test_server_LawsuitStatusType_FindMassBy_FieldNamesWithUnderline() error: ", err) + } +} + diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_readall_test.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_readall_test.go_ new file mode 100644 index 0000000..914cfc9 --- /dev/null +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_readall_test.go_ @@ -0,0 +1,12 @@ +package server_grpc + +import ( + "context" + "github.com/ManyakRus/starter/config_main" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/files" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/crud_func" + "testing" +) + diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_findby.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_findby.go_ index 2b96c28..e8fc095 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_findby.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_findby.go_ @@ -7,6 +7,6 @@ import ( "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client_func" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_constants" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" - "log" + "github.com/ManyakRus/starter/log" ) diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_findmassby.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_findmassby.go_ index 2b96c28..e8fc095 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_findmassby.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_findmassby.go_ @@ -7,6 +7,6 @@ import ( "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client_func" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_constants" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" - "log" + "github.com/ManyakRus/starter/log" ) diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_readall.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_readall.go_ new file mode 100644 index 0000000..e8fc095 --- /dev/null +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_readall.go_ @@ -0,0 +1,12 @@ +package grpc_lawsuit_status_types + +import ( + "context" + "encoding/json" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client_func" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_constants" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" + "github.com/ManyakRus/starter/log" +) + diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_readall_function.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_readall_function.go_ new file mode 100644 index 0000000..e84957a --- /dev/null +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_readall_function.go_ @@ -0,0 +1,45 @@ +// ReadAll - находит все записи в БД +func (crud Crud_GRPC) ReadAll() ([]lawsuit_status_types.LawsuitStatusType, error) { + Otvet := make([]lawsuit_status_types.LawsuitStatusType, 0) + var err error + + // подключение + grpc_client_func.Func_Connect_GRPC_NRPC.Connect_GRPC_NRPC() + + // подготовка запроса + var VersionModel = crud.GetVersionModel() + + Request := &grpc_proto.RequestEmpty{} + Request.VersionModel = VersionModel + + ctxMain := context.Background() + ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(grpc_constants.GetTimeoutSeconds())) + defer ctxCancelFunc() + + // запрос + var Response *grpc_proto.ResponseMass + if grpc_nrpc.NeedNRPC == true { + Response, err = nrpc_client.Client.LawsuitStatusType_ReadAll(Request) + } else { + Response, err = grpc_client_func.Client.LawsuitStatusType_ReadAll(ctx, Request) + } + if err != nil { + if grpc_client_func.IsErrorModelVersion(err) == true { + log.Panic("table: ", TableName, " error: ", err) + } + return Otvet, err + } + + // ответ + var m1 lawsuit_status_types.LawsuitStatusType + for _, v := range Response.MassModelString { + err = json.Unmarshal([]byte(v), &m1) + if err != nil { + return Otvet, err + } + Otvet = append(Otvet, m1) + } + + return Otvet, err +} + diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_readall_function_test.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_readall_function_test.go_ new file mode 100644 index 0000000..f94ddfd --- /dev/null +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_readall_function_test.go_ @@ -0,0 +1,15 @@ +func TestCrud_GRPC_ReadAll(t *testing.T) { + config_main.LoadEnv() + + grpc_client.Connect() + defer grpc_client.CloseConnection() + + crud := grpc_lawsuit_status_types.Crud_GRPC{} + _, err := crud.ReadAll() + + if err != nil && crud_func.IsRecordNotFound(err) == false { + t.Error("TestCrud_GRPC_ReadAll() error: ", err) + } + +} + diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_readall_test.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_readall_test.go_ new file mode 100644 index 0000000..f264d33 --- /dev/null +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_readall_test.go_ @@ -0,0 +1,11 @@ +package grpc_lawsuit_status_types + +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" +) + diff --git a/bin/templates/pkg/object_model/entities/model_table_readall.go_ b/bin/templates/pkg/object_model/entities/model_table_readall.go_ new file mode 100644 index 0000000..4ca0a66 --- /dev/null +++ b/bin/templates/pkg/object_model/entities/model_table_readall.go_ @@ -0,0 +1,6 @@ +package lawsuit_status_types + +import ( + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/db_constants" +) + diff --git a/bin/templates/pkg/object_model/entities/model_table_readall_function.go_ b/bin/templates/pkg/object_model/entities/model_table_readall_function.go_ new file mode 100644 index 0000000..9bf019d --- /dev/null +++ b/bin/templates/pkg/object_model/entities/model_table_readall_function.go_ @@ -0,0 +1,12 @@ +// ReadAll - возвращает все записи таблицы в БД +func (m *LawsuitStatusType) ReadAll() ([]LawsuitStatusType, error) { + Otvet := make([]LawsuitStatusType, 0) + if Crud_manual_LawsuitStatusType == nil { + return Otvet, db_constants.ErrorCrudIsNotInit + } + + Otvet, err := Crud_LawsuitStatusType.ReadAll(m) + + return Otvet, err +} +