Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop to Main #117

Merged
merged 77 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
1e9322f
feature: implement get operation by portfolio :sparkles:
andrerussowsky Oct 15, 2024
8bdd216
chore: unit test :wrench:
andrerussowsky Oct 15, 2024
c97138d
chore: postman update :wrench:
andrerussowsky Oct 15, 2024
bc4b697
fix: resolve conflicts :bug:
maxwelbm Oct 16, 2024
3bf9fa9
chore: postman update :wrench:
andrerussowsky Oct 15, 2024
b5d92be
chore(release): 1.16.0-beta.3
lerian-studio Oct 15, 2024
6ebff8a
feat: initialize CLI with root and version commands :sparkles:
maxwelbm Oct 16, 2024
f46e7d0
Merge branch 'develop' into feature/starting-cli-mdz
maxwelbm Oct 16, 2024
6ea0f05
style: fix linting issues across multiple files :gem:
maxwelbm Oct 16, 2024
cfbacc7
test: test unit table simple for command root, version :rotating_light:
maxwelbm Oct 16, 2024
df8826b
Merge branch 'develop' into feature/starting-cli-mdz
maxwelbm Oct 16, 2024
df207d2
Merge pull request #107 from LerianStudio/feature/starting-cli-mdz
maxwelbm Oct 17, 2024
8c31055
chore(release): 1.19.0-beta.1
lerian-studio Oct 17, 2024
981da75
refactor: change message error to full payload :hammer:
ClaudioTessaro Oct 17, 2024
42c6733
Merge branch 'develop' into refactor/MZ-539
MartinezAvellan Oct 17, 2024
2d9de51
Merge pull request #111 from LerianStudio/refactor/MZ-539
MartinezAvellan Oct 17, 2024
8f8911c
chore(release): 1.19.0-beta.2
lerian-studio Oct 17, 2024
270ecfd
feat: adds validation error for invalid path parameters :sparkles:
ClaraTersi Oct 17, 2024
6baa571
feat: implements handler for parsing UUID path parameters :sparkles:
ClaraTersi Oct 17, 2024
d7135ff
fix: better formatting for error message :bug:
ClaraTersi Oct 17, 2024
6153896
feat: adds UUID handler for routes with path parameters :sparkles:
ClaraTersi Oct 17, 2024
e2d2848
fix: uses parsed uuid while retrieving organization :bug:
ClaraTersi Oct 17, 2024
866170a
fix: uses parsed uuid while deleting organization :bug:
ClaraTersi Oct 17, 2024
ad1bcae
fix: uses parsed uuid while getting and updating a ledger :bug:
ClaraTersi Oct 17, 2024
2260a33
fix: uses parsed uuid while getting all organization ledgers :bug:
ClaraTersi Oct 17, 2024
8dc3a97
fix: uses parsed uuid while deleting ledger by id :bug:
ClaraTersi Oct 17, 2024
333bf49
fix: uses parsed uuid while creating asset :bug:
ClaraTersi Oct 17, 2024
9c8b3a2
fix: uses parsed uuid while retrieving and updating asset :bug:
ClaraTersi Oct 17, 2024
aadf885
fix: uses parsed uuid while retrieving all assets from a ledger :bug:
ClaraTersi Oct 17, 2024
4dfe76c
fix: Invalid code format validation :bug:
andrerussowsky Oct 18, 2024
e8383ca
fix: Invalid code format validation :bug:
andrerussowsky Oct 18, 2024
926ca9b
fix: remove unique constraint on database in code and reference on ac…
MartinezAvellan Oct 18, 2024
3a71282
fix: add log; :bug:
MartinezAvellan Oct 18, 2024
9b71d2e
fix: add parentheses on find name or asset query; :bug:
MartinezAvellan Oct 18, 2024
d2481eb
fix: add required in asset_code; :bug:
MartinezAvellan Oct 18, 2024
2375963
fix: create validation on code to certify that asset_code exist on as…
MartinezAvellan Oct 18, 2024
5c5ca6a
fix (asset): uses parsed uuid while deleting :bug:
ClaraTersi Oct 18, 2024
583890a
fix: adjust to validate if exists code on assets; :bug:
MartinezAvellan Oct 18, 2024
398a529
fix (portfolio): uses parsed uuid for retrieving and updating :bug:
ClaraTersi Oct 18, 2024
944b07d
Merge pull request #112 from LerianStudio/feature/MZ-545
MartinezAvellan Oct 18, 2024
a181709
fix: remove copyloopvar and perfsprint; :bug:
MartinezAvellan Oct 18, 2024
6aeaa66
Merge branch 'develop' into fix/MZ-555
MartinezAvellan Oct 18, 2024
8a50b63
chore(release): 1.19.0-beta.3
lerian-studio Oct 18, 2024
d4eab0c
fix (portfolio): uses parsed uuid for retrieving all :bug:
ClaraTersi Oct 18, 2024
a1983d3
fix (portfolio): uses parsed uuid for deleting :bug:
ClaraTersi Oct 18, 2024
2a11025
fix (product): uses parsed uuid on create :bug:
ClaraTersi Oct 18, 2024
707be65
fix: remove goconst :bug:
MartinezAvellan Oct 18, 2024
c97ce38
fix (product): uses parsed uuid on get and update :bug:
ClaraTersi Oct 18, 2024
041b528
fix (product): uses parsed uuid for getting all :bug:
ClaraTersi Oct 18, 2024
35f7ed4
fix (product): uses parsed uuid on delete :bug:
ClaraTersi Oct 18, 2024
2a00555
fix (account): uses parsed uuid on creation :bug:
ClaraTersi Oct 18, 2024
991e9df
fix (account): uses parsed uuid on update :bug:
ClaraTersi Oct 18, 2024
b3b40f6
fix (account): uses parsed uuid for retrieving all :bug:
ClaraTersi Oct 18, 2024
4d22c8c
fix: go sec and lint; :bug:
MartinezAvellan Oct 18, 2024
aea4d46
fix (account): uses parsed uuid for retrieving by id :bug:
ClaraTersi Oct 18, 2024
d84ac61
fix (account): uses parsed uuid on delete :bug:
ClaraTersi Oct 18, 2024
8a9729a
Merge branch 'develop' into fix/MZ-555
MartinezAvellan Oct 18, 2024
c4ed7e3
refactor: update postman :hammer:
MartinezAvellan Oct 18, 2024
b6cef81
fix (organization): uuid logging format :bug:
ClaraTersi Oct 18, 2024
40d1bbd
feat: require code :sparkles:
andrerussowsky Oct 18, 2024
d7e89c4
Merge pull request #113 from LerianStudio/fix/MZ-555
MartinezAvellan Oct 18, 2024
de899e1
fix (ledger): uuid logging format :bug:
ClaraTersi Oct 18, 2024
c866eaf
fix (asset): uuid logging format :bug:
ClaraTersi Oct 18, 2024
c9d3947
chore(release): 1.19.0-beta.4
lerian-studio Oct 18, 2024
3fce388
Merge branch 'develop' into feature/MZ-546
MartinezAvellan Oct 18, 2024
2936f9d
test: implements testing for UUID parser handler :rotating_light:
ClaraTersi Oct 18, 2024
d1015a5
Merge branch 'develop' into fix/MZ-540
ClaraTersi Oct 18, 2024
d78a64f
Merge pull request #114 from LerianStudio/feature/MZ-546
MartinezAvellan Oct 18, 2024
ae17b2c
chore(release): 1.19.0-beta.5
lerian-studio Oct 18, 2024
da0a22a
fix: asset validate create before to ledger_id :bug:
MartinezAvellan Oct 18, 2024
495c9c3
Merge pull request #115 from LerianStudio/fix/MZ-567
MartinezAvellan Oct 18, 2024
40084c6
chore(release): 1.19.0-beta.6
lerian-studio Oct 18, 2024
ef1de2f
Merge branch 'develop' into fix/MZ-540
ClaraTersi Oct 18, 2024
381ba21
fix: uses UUID to find asset :bug:
ClaraTersi Oct 18, 2024
05b89c5
fix: remove asset_code validation on account :bug:
ClaraTersi Oct 18, 2024
42cd47b
Merge pull request #116 from LerianStudio/fix/MZ-540
MartinezAvellan Oct 18, 2024
d947df0
chore(release): 1.19.0-beta.7
lerian-studio Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,19 @@ linters:
enable:
- bodyclose
- gocognit
- goconst
- depguard
- dogsled
- dupword # Detects duplicate words.
- durationcheck
- errchkjson
- exportloopref # Detects pointers to enclosing loop variables.
- gocritic # Metalinter; detects bugs, performance, and styling issues.
- gocyclo
- gofumpt # Detects whether code was gofumpt-ed.
- goimports
- gosec # Detects security problems.
- gosimple
- loggercheck
- govet
# - golint
- ineffassign
- megacheck
- wsl
- misspell # Detects commonly misspelled English words in comments.
- nakedret
- nilerr # Detects code that returns nil even if it checks that the error is not nil.
- nolintlint # Detects ill-formed or insufficient nolint directives.
- perfsprint # Detects fmt.Sprintf uses that can be replaced with a faster alternative.
- prealloc # Detects slice declarations that could potentially be pre-allocated.
- predeclared # Detects code that shadows one of Go's predeclared identifiers
- reassign
Expand All @@ -34,12 +23,10 @@ linters:
- tenv # Detects using os.Setenv instead of t.Setenv.
- thelper # Detects test helpers without t.Helper().
- tparallel # Detects inappropriate usage of t.Parallel().
- typecheck
- unconvert # Detects unnecessary type conversions.
- unparam
- unused
- usestdlibvars
- vet
- wastedassign
- errcheck

Expand Down
76 changes: 76 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
## [1.19.0-beta.7](https://github.com/LerianStudio/midaz/compare/v1.19.0-beta.6...v1.19.0-beta.7) (2024-10-18)


### Features

* adds UUID handler for routes with path parameters :sparkles: ([6153896](https://github.com/LerianStudio/midaz/commit/6153896bc83e0d3048a7223f89eafe6b6f2deae3))
* adds validation error for invalid path parameters :sparkles: ([270ecfd](https://github.com/LerianStudio/midaz/commit/270ecfdc7aa14040aefa29ab09710aa6274acce9))
* implements handler for parsing UUID path parameters :sparkles: ([6baa571](https://github.com/LerianStudio/midaz/commit/6baa571275c876ab48760f882e48a400bd892196))


### Bug Fixes

* better formatting for error message :bug: ([d7135ff](https://github.com/LerianStudio/midaz/commit/d7135ff90f50f154a95928829142a37226be7629))
* remove asset_code validation on account :bug: ([05b89c5](https://github.com/LerianStudio/midaz/commit/05b89c52266d1e067ffc429d29405d49f50762dc))
* uses parsed uuid while creating asset :bug: ([333bf49](https://github.com/LerianStudio/midaz/commit/333bf4921d3f2fd48156ead07ac8b1b29d88d5fa))
* uses parsed uuid while deleting ledger by id :bug: ([8dc3a97](https://github.com/LerianStudio/midaz/commit/8dc3a97f8c859a6948cad099cd61888c8c016bee))
* uses parsed uuid while deleting organization :bug: ([866170a](https://github.com/LerianStudio/midaz/commit/866170a1d2bb849fc1ed002a9aed99d7ee43eecb))
* uses parsed uuid while getting all organization ledgers :bug: ([2260a33](https://github.com/LerianStudio/midaz/commit/2260a331e381d452bcab942f9f06864c60444f52))
* uses parsed uuid while getting and updating a ledger :bug: ([ad1bcae](https://github.com/LerianStudio/midaz/commit/ad1bcae482d2939c8e828b169b566d3a13be95cd))
* uses parsed uuid while retrieving all assets from a ledger :bug: ([aadf885](https://github.com/LerianStudio/midaz/commit/aadf8852154726bd4aef2e3295221b5472236ed9))
* uses parsed uuid while retrieving and updating asset :bug: ([9c8b3a2](https://github.com/LerianStudio/midaz/commit/9c8b3a2f9747117e5149f3a515c8a5b582db4942))
* uses parsed uuid while retrieving organization :bug: ([e2d2848](https://github.com/LerianStudio/midaz/commit/e2d284808c9c1d95d3d1192be2e4ba3e613318dc))
* uses UUID to find asset :bug: ([381ba21](https://github.com/LerianStudio/midaz/commit/381ba2178633863f17cffb327a7ab2276926ce0d))

## [1.19.0-beta.6](https://github.com/LerianStudio/midaz/compare/v1.19.0-beta.5...v1.19.0-beta.6) (2024-10-18)


### Bug Fixes

* asset validate create before to ledger_id :bug: ([da0a22a](https://github.com/LerianStudio/midaz/commit/da0a22a38f57c6d8217e8511abb07592523c822f))

## [1.19.0-beta.5](https://github.com/LerianStudio/midaz/compare/v1.19.0-beta.4...v1.19.0-beta.5) (2024-10-18)


### Features

* require code :sparkles: ([40d1bbd](https://github.com/LerianStudio/midaz/commit/40d1bbd7f54c85aaab279e36754274df93d12a34))

## [1.19.0-beta.4](https://github.com/LerianStudio/midaz/compare/v1.19.0-beta.3...v1.19.0-beta.4) (2024-10-18)


### Bug Fixes

* add log; :bug: ([3a71282](https://github.com/LerianStudio/midaz/commit/3a712820a16ede4cd50cdc1729c5abf0507950b0))
* add parentheses on find name or asset query; :bug: ([9b71d2e](https://github.com/LerianStudio/midaz/commit/9b71d2ee9bafba37b0eb9e1a0f328b5d10036d1e))
* add required in asset_code; :bug: ([d2481eb](https://github.com/LerianStudio/midaz/commit/d2481ebf4d3007df5337394c151360aca28ee69a))
* adjust to validate if exists code on assets; :bug: ([583890a](https://github.com/LerianStudio/midaz/commit/583890a6c1d178b95b41666a91600a60d3053123))
* create validation on code to certify that asset_code exist on assets before insert in accounts; :bug: ([2375963](https://github.com/LerianStudio/midaz/commit/2375963e26657972f22ac714c905775bdf0ed5d5))
* go sec and lint; :bug: ([4d22c8c](https://github.com/LerianStudio/midaz/commit/4d22c8c5be0f6498c5305ed01e1121efbe4e8987))
* remove copyloopvar and perfsprint; :bug: ([a181709](https://github.com/LerianStudio/midaz/commit/a1817091640de24bad22e43eaddccd86b21dcf82))
* remove goconst :bug: ([707be65](https://github.com/LerianStudio/midaz/commit/707be656984aaea2c839be70f6c7c17e84375866))
* remove unique constraint on database in code and reference on accounts; :bug: ([926ca9b](https://github.com/LerianStudio/midaz/commit/926ca9b758d7e69611afa903c035fa01218b108f))

## [1.19.0-beta.3](https://github.com/LerianStudio/midaz/compare/v1.19.0-beta.2...v1.19.0-beta.3) (2024-10-18)


### Bug Fixes

* Invalid code format validation :bug: ([e8383ca](https://github.com/LerianStudio/midaz/commit/e8383cac7957d1f0d63ce20f71534052ab1e8703))
* Invalid code format validation :bug: ([4dfe76c](https://github.com/LerianStudio/midaz/commit/4dfe76c1092412a129a60b09d408f71d8a59dca0))

## [1.19.0-beta.2](https://github.com/LerianStudio/midaz/compare/v1.19.0-beta.1...v1.19.0-beta.2) (2024-10-17)

## [1.19.0-beta.1](https://github.com/LerianStudio/midaz/compare/v1.18.0...v1.19.0-beta.1) (2024-10-17)


### Features

* implement get operation by portfolio :sparkles: ([1e9322f](https://github.com/LerianStudio/midaz/commit/1e9322f8257672d95d850739609af87c673d7b56))
* initialize CLI with root and version commands :sparkles: ([6ebff8a](https://github.com/LerianStudio/midaz/commit/6ebff8a40ba097b0eaa4feb1106ebc29a5ba84dc))


### Bug Fixes

* resolve conflicts :bug: ([bc4b697](https://github.com/LerianStudio/midaz/commit/bc4b697c2e50cd1ec3cd41e0f96cb933a17b6a79))

## [1.18.0](https://github.com/LerianStudio/midaz/compare/v1.17.0...v1.18.0) (2024-10-16)


Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ transaction:
all-services:
$(MAKE) -C $(AUTH_DIR) $(COMMAND) && \
$(MAKE) -C $(LEDGER_DIR) $(COMMAND) && \
$(MAKE) -C $(TRANSACTION_DIR) $(COMMAND)
$(MAKE) -C $(TRANSACTION_DIR) $(COMMAND)
1 change: 1 addition & 0 deletions common/constant/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ var (
ErrNoAccountIDsProvided = errors.New("0062")
ErrFailedToRetrieveAccountsByAliases = errors.New("0063")
ErrNoAccountsFound = errors.New("0064")
ErrInvalidPathParameter = errors.New("0065")
)
6 changes: 6 additions & 0 deletions common/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,12 @@ func ValidateBusinessError(err error, entityType string, args ...any) error {
Title: "No Accounts Found",
Message: "No accounts were found in the search. Please review the search criteria and try again.",
},
cn.ErrInvalidPathParameter: ValidationError{
EntityType: entityType,
Code: cn.ErrInvalidPathParameter.Error(),
Title: "Invalid Path Parameter",
Message: fmt.Sprintf("The provided path parameter(s) %s is/are not in the expected format. Please ensure the parameter adheres to the required format and try again.", args),
},
}

if mappedError, found := errorMap[err]; found {
Expand Down
27 changes: 27 additions & 0 deletions common/net/http/withBody.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"reflect"
"strings"

cn "github.com/LerianStudio/midaz/common/constant"
"github.com/google/uuid"

"github.com/LerianStudio/midaz/common"

"github.com/gofiber/fiber/v2"
Expand Down Expand Up @@ -152,6 +155,30 @@ func ValidateStruct(s any) error {
return nil
}

// ParseUUIDPathParameters globally, considering all path parameters are UUIDs
func ParseUUIDPathParameters(c *fiber.Ctx) error {
params := c.AllParams()

var invalidUUIDs []string

for param, value := range params {
parsedUUID, err := uuid.Parse(value)
if err != nil {
invalidUUIDs = append(invalidUUIDs, param)
continue
}

c.Locals(param, parsedUUID)
}

if len(invalidUUIDs) > 0 {
err := common.ValidateBusinessError(cn.ErrInvalidPathParameter, "", strings.Join(invalidUUIDs, ", "))
return WithError(c, err)
}

return c.Next()
}

//nolint:ireturn
func newValidator() (*validator.Validate, ut.Translator) {
locale := en.New()
Expand Down
65 changes: 65 additions & 0 deletions common/net/http/withBody_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package http
import (
"encoding/json"
"github.com/LerianStudio/midaz/common"
"github.com/gofiber/fiber/v2"
"github.com/stretchr/testify/require"
"net/http/httptest"
"reflect"
"testing"
)
Expand Down Expand Up @@ -76,3 +79,65 @@ func TestFilterRequiredFieldWithNoFields(t *testing.T) {
t.Errorf("Want %v, got %v", expected, result)
}
}

func TestParseUUIDPathParameters_ValidUUID(t *testing.T) {
app := fiber.New()

app.Get("/v1/organizations/:id", ParseUUIDPathParameters, func(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusOK) // Se o middleware passar, responde com 200
})

req := httptest.NewRequest("GET", "/v1/organizations/123e4567-e89b-12d3-a456-426614174000", nil)
resp, err := app.Test(req, -1)
require.NoError(t, err)

require.Equal(t, fiber.StatusOK, resp.StatusCode)
}

func TestParseUUIDPathParameters_MultipleValidUUID(t *testing.T) {
app := fiber.New()

app.Get("/v1/organizations/:organization_id/ledgers/:id", ParseUUIDPathParameters, func(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusOK)
})

req := httptest.NewRequest(
"GET",
"/v1/organizations/123e4567-e89b-12d3-a456-426614174000/ledgers/c71ab589-cf46-4f2d-b6ef-b395c9a475da",
nil)
resp, err := app.Test(req, -1)
require.NoError(t, err)

require.Equal(t, fiber.StatusOK, resp.StatusCode)
}

func TestParseUUIDPathParameters_InvalidUUID(t *testing.T) {
app := fiber.New()

app.Get("/v1/organizations/:id", ParseUUIDPathParameters, func(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusOK)
})

req := httptest.NewRequest("GET", "/v1/organizations/invalid-uuid", nil)
resp, err := app.Test(req, -1)
require.NoError(t, err)

require.Equal(t, fiber.StatusBadRequest, resp.StatusCode)
}

func TestParseUUIDPathParameters_ValidAndInvalidUUID(t *testing.T) {
app := fiber.New()

app.Get("/v1/organizations/:organization_id/ledgers/:id", ParseUUIDPathParameters, func(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusOK)
})

req := httptest.NewRequest(
"GET",
"/v1/organizations/123e4567-e89b-12d3-a456-426614174000/ledgers/invalid-uuid",
nil)
resp, err := app.Test(req, -1)
require.NoError(t, err)

require.Equal(t, fiber.StatusBadRequest, resp.StatusCode)
}
4 changes: 3 additions & 1 deletion common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ func ValidateCurrency(code string) error {
}

for _, r := range code {
if unicode.IsLetter(r) && !unicode.IsUpper(r) {
if !unicode.IsLetter(r) {
return cn.ErrInvalidCodeFormat
} else if !unicode.IsUpper(r) {
return cn.ErrCodeUppercaseRequirement
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (r *AssetPostgreSQLRepository) FindByNameOrCode(ctx context.Context, organi
return false, err
}

rows, err := db.QueryContext(ctx, "SELECT * FROM asset WHERE organization_id = $1 AND ledger_id = $2 AND name LIKE $3 OR code = $4 AND deleted_at IS NULL ORDER BY created_at DESC",
rows, err := db.QueryContext(ctx, "SELECT * FROM asset WHERE organization_id = $1 AND ledger_id = $2 AND (name LIKE $3 OR code = $4) AND deleted_at IS NULL ORDER BY created_at DESC",
organizationID, ledgerID, name, code)
if err != nil {
return false, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (r *OrganizationPostgreSQLRepository) Find(ctx context.Context, id uuid.UUI

var address string

row := db.QueryRowContext(ctx, `SELECT * FROM organization WHERE id = $1 AND deleted_at IS NULL`, id)
row := db.QueryRowContext(ctx, `SELECT * FROM organization WHERE id = $1`, id)
if err := row.Scan(&organization.ID, &organization.ParentOrganizationID, &organization.LegalName,
&organization.DoingBusinessAs, &organization.LegalDocument, &address, &organization.Status, &organization.StatusDescription,
&organization.CreatedAt, &organization.UpdatedAt, &organization.DeletedAt); err != nil {
Expand Down
23 changes: 12 additions & 11 deletions components/ledger/internal/app/command/create-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@ import (
)

// CreateAccount creates a new account persists data in the repository.
func (uc *UseCase) CreateAccount(ctx context.Context, organizationID, ledgerID, portfolioID string, cai *a.CreateAccountInput) (*a.Account, error) {
func (uc *UseCase) CreateAccount(ctx context.Context, organizationID, ledgerID, portfolioID uuid.UUID, cai *a.CreateAccountInput) (*a.Account, error) {
logger := mlog.NewLoggerFromContext(ctx)
logger.Infof("Trying to create account: %v", cai)

if common.IsNilOrEmpty(&cai.Name) {
cai.Name = cai.AssetCode + " " + cai.Type + " account"
}

if common.IsNilOrEmpty(cai.Alias) {
cai.Alias = nil
}

var status a.Status
if cai.Status.IsEmpty() {
status = a.Status{
Expand All @@ -46,8 +42,13 @@ func (uc *UseCase) CreateAccount(ctx context.Context, organizationID, ledgerID,
Scale: &balanceValue,
}

isAsset, _ := uc.AssetRepo.FindByNameOrCode(ctx, organizationID, ledgerID, "", cai.AssetCode)
if !isAsset {
return nil, common.ValidateBusinessError(cn.ErrAssetCodeNotFound, reflect.TypeOf(a.Account{}).Name())
}

if cai.EntityID == nil {
portfolio, err := uc.PortfolioRepo.Find(ctx, uuid.MustParse(organizationID), uuid.MustParse(ledgerID), uuid.MustParse(portfolioID))
portfolio, err := uc.PortfolioRepo.Find(ctx, organizationID, ledgerID, portfolioID)
if err != nil {
logger.Errorf("Error find portfolio to get Entity ID: %v", err)
return nil, err
Expand All @@ -57,7 +58,7 @@ func (uc *UseCase) CreateAccount(ctx context.Context, organizationID, ledgerID,
}

if !common.IsNilOrEmpty(cai.ParentAccountID) {
acc, err := uc.AccountRepo.Find(ctx, uuid.MustParse(organizationID), uuid.MustParse(ledgerID), uuid.MustParse(portfolioID), uuid.MustParse(*cai.ParentAccountID))
acc, err := uc.AccountRepo.Find(ctx, organizationID, ledgerID, portfolioID, uuid.MustParse(*cai.ParentAccountID))
if err != nil {
return nil, err
}
Expand All @@ -68,7 +69,7 @@ func (uc *UseCase) CreateAccount(ctx context.Context, organizationID, ledgerID,
}

if !common.IsNilOrEmpty(cai.Alias) {
_, err := uc.AccountRepo.FindByAlias(ctx, uuid.MustParse(organizationID), uuid.MustParse(ledgerID), uuid.MustParse(portfolioID), *cai.Alias)
_, err := uc.AccountRepo.FindByAlias(ctx, organizationID, ledgerID, portfolioID, *cai.Alias)
if err != nil {
return nil, err
}
Expand All @@ -82,9 +83,9 @@ func (uc *UseCase) CreateAccount(ctx context.Context, organizationID, ledgerID,
Type: cai.Type,
ParentAccountID: cai.ParentAccountID,
ProductID: cai.ProductID,
OrganizationID: organizationID,
PortfolioID: portfolioID,
LedgerID: ledgerID,
OrganizationID: organizationID.String(),
PortfolioID: portfolioID.String(),
LedgerID: ledgerID.String(),
EntityID: *cai.EntityID,
Balance: balance,
Status: status,
Expand Down
8 changes: 4 additions & 4 deletions components/ledger/internal/app/command/create-product.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// CreateProduct creates a new product persists data in the repository.
func (uc *UseCase) CreateProduct(ctx context.Context, organizationID, ledgerID string, cpi *r.CreateProductInput) (*r.Product, error) {
func (uc *UseCase) CreateProduct(ctx context.Context, organizationID, ledgerID uuid.UUID, cpi *r.CreateProductInput) (*r.Product, error) {
logger := mlog.NewLoggerFromContext(ctx)
logger.Infof("Trying to create product: %v", cpi)

Expand All @@ -28,15 +28,15 @@ func (uc *UseCase) CreateProduct(ctx context.Context, organizationID, ledgerID s

product := &r.Product{
ID: uuid.New().String(),
LedgerID: ledgerID,
OrganizationID: organizationID,
LedgerID: ledgerID.String(),
OrganizationID: organizationID.String(),
Name: cpi.Name,
Status: status,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}

_, err := uc.ProductRepo.FindByName(ctx, uuid.MustParse(organizationID), uuid.MustParse(ledgerID), cpi.Name)
_, err := uc.ProductRepo.FindByName(ctx, organizationID, ledgerID, cpi.Name)
if err != nil {
return nil, err
}
Expand Down
Loading
Loading