diff --git a/pkg/server/grpc/contract.go b/pkg/server/grpc/contract.go index 86c950a..642831d 100644 --- a/pkg/server/grpc/contract.go +++ b/pkg/server/grpc/contract.go @@ -2,8 +2,8 @@ package grpc import ( "context" - "github.com/kamilsk/form-api/pkg/domain" + "github.com/kamilsk/form-api/pkg/domain" "github.com/kamilsk/form-api/pkg/storage/query" "github.com/kamilsk/form-api/pkg/storage/types" ) @@ -19,4 +19,6 @@ type ProtectedStorage interface { ReadTemplate(context.Context, *types.Token, query.ReadTemplate) (types.Template, error) UpdateTemplate(context.Context, *types.Token, query.UpdateTemplate) (types.Template, error) DeleteTemplate(context.Context, *types.Token, query.DeleteTemplate) (types.Template, error) + ReadInputByID(context.Context, *types.Token, domain.ID) (types.Input, error) + ReadInputByFilter(context.Context, *types.Token, query.InputFilter) ([]types.Input, error) } diff --git a/pkg/server/grpc/mock_storage_test.go b/pkg/server/grpc/mock_storage_test.go index 8cb5934..8cc358f 100644 --- a/pkg/server/grpc/mock_storage_test.go +++ b/pkg/server/grpc/mock_storage_test.go @@ -88,6 +88,32 @@ func (mr *MockProtectedStorageMockRecorder) DeleteTemplate(arg0, arg1, arg2 inte return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteTemplate", reflect.TypeOf((*MockProtectedStorage)(nil).DeleteTemplate), arg0, arg1, arg2) } +// ReadInputByFilter mocks base method +func (m *MockProtectedStorage) ReadInputByFilter(arg0 context.Context, arg1 *types.Token, arg2 query.InputFilter) ([]types.Input, error) { + ret := m.ctrl.Call(m, "ReadInputByFilter", arg0, arg1, arg2) + ret0, _ := ret[0].([]types.Input) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ReadInputByFilter indicates an expected call of ReadInputByFilter +func (mr *MockProtectedStorageMockRecorder) ReadInputByFilter(arg0, arg1, arg2 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadInputByFilter", reflect.TypeOf((*MockProtectedStorage)(nil).ReadInputByFilter), arg0, arg1, arg2) +} + +// ReadInputByID mocks base method +func (m *MockProtectedStorage) ReadInputByID(arg0 context.Context, arg1 *types.Token, arg2 domain.ID) (types.Input, error) { + ret := m.ctrl.Call(m, "ReadInputByID", arg0, arg1, arg2) + ret0, _ := ret[0].(types.Input) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ReadInputByID indicates an expected call of ReadInputByID +func (mr *MockProtectedStorageMockRecorder) ReadInputByID(arg0, arg1, arg2 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadInputByID", reflect.TypeOf((*MockProtectedStorage)(nil).ReadInputByID), arg0, arg1, arg2) +} + // ReadSchema mocks base method func (m *MockProtectedStorage) ReadSchema(arg0 context.Context, arg1 *types.Token, arg2 query.ReadSchema) (types.Schema, error) { ret := m.ctrl.Call(m, "ReadSchema", arg0, arg1, arg2) diff --git a/pkg/storage/protected.go b/pkg/storage/protected.go index b0c00c1..5505f02 100644 --- a/pkg/storage/protected.go +++ b/pkg/storage/protected.go @@ -106,3 +106,25 @@ func (storage *Storage) DeleteTemplate(ctx context.Context, token *types.Token, return storage.exec.TemplateEditor(ctx, conn).Delete(token, data) } + +// ReadInputByID TODO +func (storage *Storage) ReadInputByID(ctx context.Context, token *types.Token, id domain.ID) (types.Input, error) { + conn, closer, err := storage.connection(ctx) + if err != nil { + return types.Input{}, err + } + defer closer() + + return storage.exec.InputReader(ctx, conn).ReadByID(token, id) +} + +// ReadInputByFilter TODO +func (storage *Storage) ReadInputByFilter(ctx context.Context, token *types.Token, filter query.InputFilter) ([]types.Input, error) { + conn, closer, err := storage.connection(ctx) + if err != nil { + return nil, err + } + defer closer() + + return storage.exec.InputReader(ctx, conn).ReadByFilter(token, filter) +}