mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-30 07:58:51 +00:00
feat: instance domain APIs with relational tables (#11051)
# Which Problems Are Solved This PR implements the endpoints listed in https://github.com/zitadel/zitadel/issues/10444 . # How the Problems Are Solved The implementation follows the same pattern as the Instance one. The `Add` and `Remove` are implementing the `Commander` interface, while `List` Domains endpoints are implementing the `Querier` interace. The PR adds also some forgotten calls to the relational logic for the Instance API. The commits are identifiable by the label `instance:` prepended to them. This is the complete list: bafce01b0 , 6fe7257ab , e27bc9c34 , 8133ede73 , fde667953 , a3e1135ed , ee1a6f9c1 # Additional Context - Closes #10444 --------- Co-authored-by: Elio Bischof <[email protected]> Co-authored-by: Lebogang Phoshoko <[email protected]> Co-authored-by: Wim Van Laer <[email protected]> Co-authored-by: Max Peintner <[email protected]> Co-authored-by: Gayathri Vijayan <[email protected]>
This commit is contained in:
co-authored by
Elio Bischof
Lebogang Phoshoko
Wim Van Laer
Max Peintner
Gayathri Vijayan
parent
d79bfe6eba
commit
b339a3e696
@@ -2,7 +2,11 @@ package domain
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/muhlemmer/gu"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
@@ -20,6 +24,8 @@ type DeleteInstanceCommand struct {
|
||||
// InstanceName is public for testing purposes
|
||||
// do not use this field
|
||||
InstanceName string
|
||||
|
||||
DeleteTime *time.Time
|
||||
}
|
||||
|
||||
// RequiresTransaction implements [Transactional].
|
||||
@@ -46,6 +52,9 @@ func (d *DeleteInstanceCommand) Execute(ctx context.Context, opts *InvokeOpts) (
|
||||
|
||||
instanceToDelete, err := instanceRepo.Get(ctx, opts.DB(), database.WithCondition(instanceRepo.IDCondition(d.ID)))
|
||||
if err != nil {
|
||||
if errors.Is(err, &database.NoRowFoundError{}) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -58,18 +67,22 @@ func (d *DeleteInstanceCommand) Execute(ctx context.Context, opts *InvokeOpts) (
|
||||
|
||||
deletedRows, err := instanceRepo.Delete(ctx, opts.DB(), instanceToDelete.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
if errors.Is(err, &database.NoRowFoundError{}) {
|
||||
return nil
|
||||
}
|
||||
return zerrors.ThrowInternal(err, "DOM-caF4Vs", "Errors.Instance.Delete")
|
||||
}
|
||||
|
||||
if deletedRows > 1 {
|
||||
err = zerrors.ThrowInternalf(nil, "DOM-Od04Jx", "expecting 1 row deleted, got %d", deletedRows)
|
||||
return err
|
||||
return zerrors.ThrowInternal(nil, "DOM-Od04Jx", "Errors.Instsance.DeleteMismatch")
|
||||
}
|
||||
|
||||
if deletedRows < 1 {
|
||||
err = zerrors.ThrowNotFound(nil, "DOM-daglwD", "instance not found")
|
||||
return nil
|
||||
}
|
||||
|
||||
d.DeleteTime = gu.Ptr(time.Now())
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -85,7 +98,7 @@ func (d *DeleteInstanceCommand) Validate(ctx context.Context, opts *InvokeOpts)
|
||||
}
|
||||
|
||||
if authZErr := opts.Permissions.CheckInstancePermission(ctx, InstanceWritePermission); authZErr != nil {
|
||||
return zerrors.ThrowPermissionDenied(authZErr, "DOM-Yz8f1X", "permission denied")
|
||||
return zerrors.ThrowPermissionDenied(authZErr, "DOM-Yz8f1X", "Errors.PermissionDenied")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user