1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2025-01-06 01:23:15 +02:00

сделал ReadAll()

This commit is contained in:
Nikitin Aleksandr 2024-09-12 17:10:21 +03:00
parent 56530b9e8f
commit 12b7de3330
12 changed files with 173 additions and 2 deletions

View File

@ -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"
)

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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"
)

View File

@ -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"
)

View File

@ -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"
)

View File

@ -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"
)

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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"
)

View File

@ -0,0 +1,6 @@
package lawsuit_status_types
import (
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/db_constants"
)

View File

@ -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
}