Skip to content

Commit

Permalink
Merge branch 'develop' into fix/interactive_input
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwelbm authored Oct 21, 2024
2 parents e762158 + 44335ec commit dda0291
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 380 deletions.
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
## [1.22.0-beta.6](https://github.com/LerianStudio/midaz/compare/v1.22.0-beta.5...v1.22.0-beta.6) (2024-10-21)


### Features

* implements method to check if a ledger exists by name in an organization :sparkles: ([9737579](https://github.com/LerianStudio/midaz/commit/973757967817027815cc1a5497247af3e26ea587))


### Bug Fixes

* uses parsed UUID for organizationID on create ledger :bug: ([b506dc3](https://github.com/LerianStudio/midaz/commit/b506dc3dfe1e1ea8abdf251ca040ab3a6db163ef))
* validates if a ledger with the same name already exists for the same organization :bug: ([08df20b](https://github.com/LerianStudio/midaz/commit/08df20bf4cdd99fc33ce3d273162addb0023afc6))

## [1.22.0-beta.5](https://github.com/LerianStudio/midaz/compare/v1.22.0-beta.4...v1.22.0-beta.5) (2024-10-21)


### Bug Fixes

* rename to put on pattern :bug: ([ec8141a](https://github.com/LerianStudio/midaz/commit/ec8141ae8195d6e6f864ee766bca94bf6e90de03))
* update some ports on .env :bug: ([b7c58ea](https://github.com/LerianStudio/midaz/commit/b7c58ea75e5c82b8728a785a4b233fa5351c478c))

## [1.22.0-beta.4](https://github.com/LerianStudio/midaz/compare/v1.22.0-beta.3...v1.22.0-beta.4) (2024-10-21)


### Bug Fixes

* patch account doesnt return the right data :bug: ([a9c97c2](https://github.com/LerianStudio/midaz/commit/a9c97c2b48b16ae237195777fa8c77d23370e184))

## [1.22.0-beta.3](https://github.com/LerianStudio/midaz/compare/v1.22.0-beta.2...v1.22.0-beta.3) (2024-10-21)


### Bug Fixes

* sets type as a required field for creating accounts :bug: ([a35044f](https://github.com/LerianStudio/midaz/commit/a35044f7d79b4eb3ecd1476d9ac5527e36617fb1))

## [1.22.0-beta.2](https://github.com/LerianStudio/midaz/compare/v1.22.0-beta.1...v1.22.0-beta.2) (2024-10-21)

## [1.22.0-beta.1](https://github.com/LerianStudio/midaz/compare/v1.21.0...v1.22.0-beta.1) (2024-10-21)


### Bug Fixes

* sets name as a required field for creating ledgers :bug: ([534cda5](https://github.com/LerianStudio/midaz/commit/534cda5d9203a6c478baf8980dea2e3fc2170eaf))

## [1.21.0](https://github.com/LerianStudio/midaz/compare/v1.20.0...v1.21.0) (2024-10-18)


Expand Down
17 changes: 6 additions & 11 deletions components/auth/.env.example
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
# AUTH
#Env
ENV_NAME=production

#APP - Auth
APP_CONTEXT=/auth/v1
SERVER_PORT=3004
SERVER_ADDRESS=:${SERVER_PORT}

# Casdoor
CASDOOR_PORT=8000
# CASDOOR
CASDOOR_PORT=8080
RUNNING_IN_DOCKER=true

# Casdoor DB
# CADOOR DB
DB_HOST=casdoor-db
CASDOOR_DB_USER=midaz
CASDOOR_DB_NAME=casdoor
CASDOOR_DB_PASSWORD=leriand
CASDOOR_DB_PORT=5436
USER_EXECUTE_COMMAND=postgres

# LOG
LOG_LEVEL=debug

# Casdoor Config
# CASDOOR CONFIG
appname=casdoor
httpport=${CASDOOR_PORT}
runmode=dev
Expand Down
27 changes: 23 additions & 4 deletions components/ledger/.env.example
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
#ENV_NAME=production #default local
VERSION=1.8.0
# DEFAULT local
# ENV_NAME=production

# APP VERSION
VERSION=1.21.0

# APP
SERVER_PORT=3000
SERVER_ADDRESS=:${SERVER_PORT}

# PROTOBUF
PROTO_URL=localhost
PROTO_PORT=50051
PROTO_PORT=3001
PROTO_ADDRESS=:${PROTO_PORT}

# MONGO DB
MONGO_HOST=mongodb
MONGO_NAME=ledger
MONGO_USER=midaz
MONGO_PASSWORD=leriand
MONGO_PORT=27017

# REDIS
REDIS_PORT=6379

# DB POSTGRESQL PRIMARY AND REPLICA
DB_HOST=primary-ledger
DB_USER=midaz
DB_NAME=ledger
DB_PASSWORD=leriand
DB_PORT=5432

DB_REPLICA_HOST=replica-ledger
DB_REPLICA_USER=midaz
DB_REPLICA_NAME=ledger
DB_REPLICA_PASSWORD=leriand
DB_REPLICA_PORT=5433

REPLICATION_USER=replicator
REPLICATION_PASSWORD=replicator_password
USER_EXECUTE_COMMAND=postgres

# LOG LEVEL
LOG_LEVEL=debug
CASDOOR_PORT=8000

# CASDOOR
CASDOOR_PORT=8080
CASDOOR_ADDRESS=http://casdoor:${CASDOOR_PORT}
CASDOOR_CLIENT_ID=9670e0ca55a29a466d31
CASDOOR_CLIENT_SECRET=dd03f916cacf4a98c6a413d9c38ba102dce436a9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,29 @@ func (r *LedgerPostgreSQLRepository) FindAll(ctx context.Context, organizationID
return ledgers, nil
}

// FindByName returns error and a boolean indicating if Ledger entities exists by name
func (r *LedgerPostgreSQLRepository) FindByName(ctx context.Context, organizationID uuid.UUID, name string) (bool, error) {
db, err := r.connection.GetDB()
if err != nil {
return false, err
}

rows, err := db.QueryContext(ctx,
"SELECT * FROM ledger WHERE organization_id = $1 AND LOWER(name) LIKE LOWER($2) AND deleted_at IS NULL",
organizationID,
name)
if err != nil {
return false, err
}
defer rows.Close()

if rows.Next() {
return true, common.ValidateBusinessError(cn.ErrLedgerNameConflict, reflect.TypeOf(l.Ledger{}).Name(), name)
}

return false, nil
}

// ListByIDs retrieves Ledgers entities from the database using the provided IDs.
func (r *LedgerPostgreSQLRepository) ListByIDs(ctx context.Context, organizationID uuid.UUID, ids []uuid.UUID) ([]*l.Ledger, error) {
db, err := r.connection.GetDB()
Expand Down
11 changes: 9 additions & 2 deletions components/ledger/internal/app/command/create-ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package command

import (
"context"
"github.com/google/uuid"
"reflect"
"time"

Expand All @@ -12,7 +13,7 @@ import (
)

// CreateLedger creates a new ledger persists data in the repository.
func (uc *UseCase) CreateLedger(ctx context.Context, organizationID string, cli *l.CreateLedgerInput) (*l.Ledger, error) {
func (uc *UseCase) CreateLedger(ctx context.Context, organizationID uuid.UUID, cli *l.CreateLedgerInput) (*l.Ledger, error) {
logger := mlog.NewLoggerFromContext(ctx)
logger.Infof("Trying to create ledger: %v", cli)

Expand All @@ -25,8 +26,14 @@ func (uc *UseCase) CreateLedger(ctx context.Context, organizationID string, cli
status = cli.Status
}

_, err := uc.LedgerRepo.FindByName(ctx, organizationID, cli.Name)
if err != nil {
logger.Errorf("Error creating ledger: %v", err)
return nil, err
}

ledger := &l.Ledger{
OrganizationID: organizationID,
OrganizationID: organizationID.String(),
Name: cli.Name,
Status: status,
CreatedAt: time.Now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type LedgerPostgreSQLModel struct {

// CreateLedgerInput is a struct design to encapsulate request create payload data.
type CreateLedgerInput struct {
Name string `json:"name"`
Name string `json:"name" validate:"required"`
Status Status `json:"status"`
Metadata map[string]any `json:"metadata"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Repository interface {
Create(ctx context.Context, ledger *Ledger) (*Ledger, error)
Find(ctx context.Context, organizationID, id uuid.UUID) (*Ledger, error)
FindAll(ctx context.Context, organizationID uuid.UUID, limit, page int) ([]*Ledger, error)
FindByName(ctx context.Context, organizationID uuid.UUID, name string) (bool, error)
ListByIDs(ctx context.Context, organizationID uuid.UUID, ids []uuid.UUID) ([]*Ledger, error)
Update(ctx context.Context, organizationID, id uuid.UUID, ledger *Ledger) (*Ledger, error)
Delete(ctx context.Context, organizationID, id uuid.UUID) error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type CreateAccountInput struct {
AssetCode string `json:"assetCode" validate:"required"`
Name string `json:"name"`
Alias *string `json:"alias"`
Type string `json:"type"`
Type string `json:"type" validate:"required"`
ParentAccountID *string `json:"parentAccountId" validate:"omitempty,uuid"`
ProductID *string `json:"productId" validate:"omitempty,uuid"`
EntityID *string `json:"entityId"`
Expand Down
15 changes: 15 additions & 0 deletions components/ledger/internal/gen/mock/ledger/ledger_mock.go

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

8 changes: 7 additions & 1 deletion components/ledger/internal/ports/http/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,18 @@ func (handler *AccountHandler) UpdateAccount(i any, c *fiber.Ctx) error {
payload := i.(*a.UpdateAccountInput)
logger.Infof("Request to update an Account with details: %#v", payload)

account, err := handler.Command.UpdateAccount(ctx, organizationID, ledgerID, portfolioID, id, payload)
_, err := handler.Command.UpdateAccount(ctx, organizationID, ledgerID, portfolioID, id, payload)
if err != nil {
logger.Errorf("Failed to update Account with ID: %s, Error: %s", id.String(), err.Error())
return commonHTTP.WithError(c, err)
}

account, err := handler.Query.GetAccountByID(c.Context(), organizationID, ledgerID, portfolioID, id)
if err != nil {
logger.Errorf("Failed to retrieve Account with ID: %s, Error: %s", id, err.Error())
return commonHTTP.WithError(c, err)
}

logger.Infof("Successfully updated Account with Portfolio ID: %s and Account ID: %s", portfolioID.String(), id.String())

return commonHTTP.OK(c, account)
Expand Down
2 changes: 1 addition & 1 deletion components/ledger/internal/ports/http/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (handler *LedgerHandler) CreateLedger(i any, c *fiber.Ctx) error {

logger := mlog.NewLoggerFromContext(ctx)

organizationID := c.Params("organization_id")
organizationID := c.Locals("organization_id").(uuid.UUID)

payload := i.(*l.CreateLedgerInput)
logger.Infof("Request to create an ledger with details: %#v", payload)
Expand Down
2 changes: 1 addition & 1 deletion components/mdz/example.env → components/mdz/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CLIENT_ID=9670e0ca55a29a466d31
CLIENT_SECRET=dd03f916cacf4a98c6a413d9c38ba102dce436a9
URL_API_AUTH=http://127.0.0.1:8000
URL_API_AUTH=http://127.0.0.1:8080
35 changes: 12 additions & 23 deletions components/transaction/.env.example
Original file line number Diff line number Diff line change
@@ -1,55 +1,44 @@
#Env
ENV_NAME=production
# DEFAULT local
# ENV_NAME=production

#APP - Transaction
# APP
APP_CONTEXT=/transaction/v1
SERVER_PORT=3003
SERVER_PORT=3002
SERVER_ADDRESS=:${SERVER_PORT}

#Mongo DB - Transaction
# MONGO DB
MONGO_HOST=mongodb
MONGO_NAME=transaction
MONGO_USER=midaz
MONGO_PASSWORD=leriand
MONGO_PORT=27018

# DB POSTGRESQL PRIMARY AND REPLICA
DB_HOST=primary-transaction
DB_USER=midaz
DB_NAME=transaction
DB_PASSWORD=leriand
DB_PORT=5434

DB_REPLICA_HOST=replica-transaction
DB_REPLICA_USER=midaz
DB_REPLICA_NAME=transaction
DB_REPLICA_PASSWORD=leriand
DB_REPLICA_PORT=5435

REPLICATION_USER=replicator
REPLICATION_PASSWORD=replicator_password
USER_EXECUTE_COMMAND=postgres
LOG_LEVEL=debug

## TRILLIAN
# MARIADB
DATABASE=transaction
ROOT_PASSWORD=midaz
TRILLIAN_PASSWORD=midaz
TRILLIAN_USER=transaction
MARIA_PORT=3306

# ADMINER
ADMINER_PORT=8080

# TRILLIAN LOG SERVER AND SIGNER
RPC_PORT=8090
HTTP_PORT=8091
SIGNER_PORT=8092
# LOG LEVEL
LOG_LEVEL=debug

# LEDGER gRPC
LEDGER_GRPC_ADDR=midaz-ledger
LEDGER_GRPC_PORT=50051
LEDGER_GRPC_PORT=3001

# CASSDOOR
CASDOOR_PORT=8000
CASDOOR_PORT=8080
CASDOOR_ADDRESS=http://casdoor:${CASDOOR_PORT}
CASDOOR_CLIENT_ID=9670e0ca55a29a466d31
CASDOOR_CLIENT_SECRET=dd03f916cacf4a98c6a413d9c38ba102dce436a9
Expand Down
Loading

0 comments on commit dda0291

Please sign in to comment.