Skip to content

Commit

Permalink
Merge pull request #176 from LerianStudio/fix/MZ-608
Browse files Browse the repository at this point in the history
Fix/MZ-608
  • Loading branch information
MartinezAvellan authored Oct 30, 2024
2 parents 038aae0 + 61991fc commit 33108bb
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ func (r *AccountPostgreSQLRepository) Find(ctx context.Context, organizationID,
return account.ToEntity(), nil
}

// FindByAlias find account from the database using Organization and Ledger id and Alias.
func (r *AccountPostgreSQLRepository) FindByAlias(ctx context.Context, organizationID, ledgerID, portfolioID uuid.UUID, alias string) (bool, error) {
// FindByAlias find account from the database using Organization and Ledger id and Alias. Returns true and ErrAliasUnavailability error if the alias is already taken.
func (r *AccountPostgreSQLRepository) FindByAlias(ctx context.Context, organizationID, ledgerID uuid.UUID, alias string) (bool, error) {
db, err := r.connection.GetDB()
if err != nil {
return false, err
}

rows, err := db.QueryContext(ctx, "SELECT * FROM account WHERE organization_id = $1 AND ledger_id = $2 AND portfolio_id = $3 AND alias LIKE $4 AND deleted_at IS NULL ORDER BY created_at DESC",
organizationID, ledgerID, portfolioID, alias)
rows, err := db.QueryContext(ctx, "SELECT * FROM account WHERE organization_id = $1 AND ledger_id = $2 AND alias LIKE $3 AND deleted_at IS NULL ORDER BY created_at DESC",
organizationID, ledgerID, alias)
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion components/ledger/internal/app/command/create-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (uc *UseCase) CreateAccount(ctx context.Context, organizationID, ledgerID,
}

if !common.IsNilOrEmpty(cai.Alias) {
_, err := uc.AccountRepo.FindByAlias(ctx, organizationID, ledgerID, portfolioID, *cai.Alias)
_, err := uc.AccountRepo.FindByAlias(ctx, organizationID, ledgerID, *cai.Alias)
if err != nil {
return nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions components/ledger/internal/app/command/update-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func (uc *UseCase) UpdateAccount(ctx context.Context, organizationID, ledgerID,

if common.IsNilOrEmpty(uai.Alias) {
uai.Alias = nil
} else {
_, err := uc.AccountRepo.FindByAlias(ctx, organizationID, ledgerID, *uai.Alias)
if err != nil {
return nil, err
}
}

account := &a.Account{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Repository interface {
Create(ctx context.Context, acc *Account) (*Account, error)
FindAll(ctx context.Context, organizationID, ledgerID uuid.UUID, portfolioID *uuid.UUID, limit, page int) ([]*Account, error)
Find(ctx context.Context, organizationID, ledgerID uuid.UUID, portfolioID *uuid.UUID, id uuid.UUID) (*Account, error)
FindByAlias(ctx context.Context, organizationID, ledgerID, portfolioID uuid.UUID, alias string) (bool, error)
FindByAlias(ctx context.Context, organizationID, ledgerID uuid.UUID, alias string) (bool, error)
ListByIDs(ctx context.Context, organizationID, ledgerID uuid.UUID, portfolioID *uuid.UUID, ids []uuid.UUID) ([]*Account, error)
ListByAlias(ctx context.Context, organizationID, ledgerID, portfolioID uuid.UUID, alias []string) ([]*Account, error)
Update(ctx context.Context, organizationID, ledgerID, portfolioID, id uuid.UUID, acc *Account) (*Account, error)
Expand Down
89 changes: 44 additions & 45 deletions components/ledger/internal/gen/mock/account/account_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 33108bb

Please sign in to comment.