From d6fff184440e5493307dd21a5fae9ae6d38e83ee Mon Sep 17 00:00:00 2001 From: ko_oler <kooler89@gmail.com> Date: Tue, 5 Dec 2023 15:49:54 +0300 Subject: [PATCH] =?UTF-8?q?-=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=B8=D0=BC=D1=8F=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4?= =?UTF-8?q?=D0=B0=20IsWriteAvailable=20=D0=BD=D0=B0=20IsReadAvailable=20-?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B2=20=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D0=BE=D0=B4=20IsSpaceAvailable,=20IsReadAvailable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/spaces/service.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/pkg/spaces/service.go b/pkg/spaces/service.go index 9d4b75a6..2c17dbfa 100644 --- a/pkg/spaces/service.go +++ b/pkg/spaces/service.go @@ -50,27 +50,24 @@ type Spaces interface { Move(ctx context.Context, spaceID, orgID string) (err error) } -func IsSpaceAvailable(ctx context.Context, spcs Spaces, spaceId string) error { - spc, err := spcs.Get(ctx, spaceId) - +func IsSpaceAvailable(ctx context.Context, svc Spaces, spaceID string) error { + sp, err := svc.Get(ctx, spaceID) if err != nil { return errors.Wrap(err, "space not available") } - - if spc.State != StateReady { - return errors.New("space not available") + if sp.State == StateReady || sp.State == StateNew { + return nil } - - return nil + return errors.New("space not available") } -func IsWriteAvailable(ctx context.Context, spcs Spaces, spaceID string) error { - sp, err := spcs.Get(ctx, spaceID) +func IsReadAvailable(ctx context.Context, svc Spaces, spaceID string) error { + sp, err := svc.Get(ctx, spaceID) if err != nil { return errors.Wrap(err, "fail to get space") } - if sp.State == StateMigration { - return errors.Errorf("space '%s' is migrating, fail to do operation", sp.ID) + if sp.State == StateReady || sp.State == StateNew || sp.State == StateMigration { + return nil } - return nil + return errors.Errorf("space '%s' is migrating, fail to do operation", sp.ID) } -- GitLab