Skip to content

Commit

Permalink
Merge pull request #19 from LerianStudio/feature/MZ-477
Browse files Browse the repository at this point in the history
Feature/MZ-477
  • Loading branch information
MartinezAvellan authored Jun 3, 2024
2 parents bd09874 + 0c5e531 commit 765e91b
Show file tree
Hide file tree
Showing 24 changed files with 225 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package domain
package mpostgres

// Pagination is a struct designed to encapsulate pagination response payload data.
type Pagination struct {
Expand Down
4 changes: 2 additions & 2 deletions components/ledger/internal/ports/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package ports
import (
"github.com/LerianStudio/midaz/common"
"github.com/LerianStudio/midaz/common/mlog"
"github.com/LerianStudio/midaz/common/mpostgres"
commonHTTP "github.com/LerianStudio/midaz/common/net/http"
"github.com/LerianStudio/midaz/components/ledger/internal/app/command"
"github.com/LerianStudio/midaz/components/ledger/internal/app/query"
"github.com/LerianStudio/midaz/components/ledger/internal/domain"
a "github.com/LerianStudio/midaz/components/ledger/internal/domain/portfolio/account"
"github.com/gofiber/fiber/v2"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -55,7 +55,7 @@ func (handler *AccountHandler) GetAllAccounts(c *fiber.Ctx) error {

headerParams := common.ValidateParameters(c.Queries())

pagination := domain.Pagination{
pagination := mpostgres.Pagination{
Limit: headerParams.Limit,
Page: headerParams.Page,
}
Expand Down
4 changes: 2 additions & 2 deletions components/ledger/internal/ports/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package ports
import (
"github.com/LerianStudio/midaz/common"
"github.com/LerianStudio/midaz/common/mlog"
"github.com/LerianStudio/midaz/common/mpostgres"
commonHTTP "github.com/LerianStudio/midaz/common/net/http"
"github.com/LerianStudio/midaz/components/ledger/internal/app/command"
"github.com/LerianStudio/midaz/components/ledger/internal/app/query"
"github.com/LerianStudio/midaz/components/ledger/internal/domain"
i "github.com/LerianStudio/midaz/components/ledger/internal/domain/portfolio/instrument"
"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
Expand Down Expand Up @@ -57,7 +57,7 @@ func (handler *InstrumentHandler) GetAllInstruments(c *fiber.Ctx) error {

headerParams := common.ValidateParameters(c.Queries())

pagination := domain.Pagination{
pagination := mpostgres.Pagination{
Limit: headerParams.Limit,
Page: headerParams.Page,
}
Expand Down
7 changes: 3 additions & 4 deletions components/ledger/internal/ports/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import (
"os"

"github.com/LerianStudio/midaz/common"
"github.com/LerianStudio/midaz/components/ledger/internal/domain"
"go.mongodb.org/mongo-driver/bson"

"github.com/LerianStudio/midaz/common/mlog"
"github.com/LerianStudio/midaz/common/mpostgres"
commonHTTP "github.com/LerianStudio/midaz/common/net/http"
"github.com/LerianStudio/midaz/components/ledger/internal/app/command"
"github.com/LerianStudio/midaz/components/ledger/internal/app/query"
l "github.com/LerianStudio/midaz/components/ledger/internal/domain/onboarding/ledger"
"github.com/gofiber/fiber/v2"
"go.mongodb.org/mongo-driver/bson"
)

// LedgerHandler struct contains a ledger use case for managing ledger related operations.
Expand Down Expand Up @@ -73,7 +72,7 @@ func (handler *LedgerHandler) GetAllLedgers(c *fiber.Ctx) error {

headerParams := common.ValidateParameters(c.Queries())

pagination := domain.Pagination{
pagination := mpostgres.Pagination{
Limit: headerParams.Limit,
Page: headerParams.Page,
}
Expand Down
7 changes: 3 additions & 4 deletions components/ledger/internal/ports/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package ports
import (
"os"

"github.com/LerianStudio/midaz/components/ledger/internal/domain"
"go.mongodb.org/mongo-driver/bson"

"github.com/LerianStudio/midaz/common"
"github.com/LerianStudio/midaz/common/mlog"
"github.com/LerianStudio/midaz/common/mpostgres"
commonHTTP "github.com/LerianStudio/midaz/common/net/http"
"github.com/LerianStudio/midaz/components/ledger/internal/app/command"
"github.com/LerianStudio/midaz/components/ledger/internal/app/query"
o "github.com/LerianStudio/midaz/components/ledger/internal/domain/onboarding/organization"
"github.com/gofiber/fiber/v2"
"go.mongodb.org/mongo-driver/bson"
)

// OrganizationHandler struct contains an organization use case for managing organization related operations.
Expand Down Expand Up @@ -96,7 +95,7 @@ func (handler *OrganizationHandler) GetAllOrganizations(c *fiber.Ctx) error {

headerParams := common.ValidateParameters(c.Queries())

pagination := domain.Pagination{
pagination := mpostgres.Pagination{
Limit: headerParams.Limit,
Page: headerParams.Page,
}
Expand Down
4 changes: 2 additions & 2 deletions components/ledger/internal/ports/portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package ports
import (
"github.com/LerianStudio/midaz/common"
"github.com/LerianStudio/midaz/common/mlog"
"github.com/LerianStudio/midaz/common/mpostgres"
commonHTTP "github.com/LerianStudio/midaz/common/net/http"
"github.com/LerianStudio/midaz/components/ledger/internal/app/command"
"github.com/LerianStudio/midaz/components/ledger/internal/app/query"
"github.com/LerianStudio/midaz/components/ledger/internal/domain"
p "github.com/LerianStudio/midaz/components/ledger/internal/domain/portfolio/portfolio"
"github.com/gofiber/fiber/v2"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -54,7 +54,7 @@ func (handler *PortfolioHandler) GetAllPortfolios(c *fiber.Ctx) error {

headerParams := common.ValidateParameters(c.Queries())

pagination := domain.Pagination{
pagination := mpostgres.Pagination{
Limit: headerParams.Limit,
Page: headerParams.Page,
}
Expand Down
4 changes: 2 additions & 2 deletions components/ledger/internal/ports/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package ports
import (
"github.com/LerianStudio/midaz/common"
"github.com/LerianStudio/midaz/common/mlog"
"github.com/LerianStudio/midaz/common/mpostgres"
commonHTTP "github.com/LerianStudio/midaz/common/net/http"
"github.com/LerianStudio/midaz/components/ledger/internal/app/command"
"github.com/LerianStudio/midaz/components/ledger/internal/app/query"
"github.com/LerianStudio/midaz/components/ledger/internal/domain"
r "github.com/LerianStudio/midaz/components/ledger/internal/domain/portfolio/product"
"github.com/gofiber/fiber/v2"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -52,7 +52,7 @@ func (handler *ProductHandler) GetAllProducts(c *fiber.Ctx) error {

headerParams := common.ValidateParameters(c.Queries())

pagination := domain.Pagination{
pagination := mpostgres.Pagination{
Limit: headerParams.Limit,
Page: headerParams.Page,
}
Expand Down
Empty file.
19 changes: 19 additions & 0 deletions components/transaction/examples/error.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(transaction
(chart-of-accounts-group-name PAG_CONTAS_CODE_123182371973821973981)
(metadata
(m 1)
(Cpf 43049498x)
)
(from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :amount BRL 2|4)
(description "description for the transaction not for the operation")
(send BRL 30|4 :from
(sources
(from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :remaining)
)
)
(distribute
(to @McGeegor :share 50 :of 25 :desc whatever)
(to @jeff :amount BRL 2|4)
(to @cl3v_ :remaining)
)
)
38 changes: 38 additions & 0 deletions components/transaction/examples/transaction-template.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(transaction V1
(chart-of-accounts-group-name p2p_transfer_group)
(description "P2P sent")
(code P2P_TRANSFER)
(pending false)
(metadata
(anyKey anyValue)
(anotherKey anotherValue)
)
(send BRL $amount|$scale
(source
(from $sourceAccount :amount BRL $amount|2
(description "P2P sent to $destination")
(chart-of-accounts p2p_debit_source_8123891)
(metadata
(anyKey anyValue)
(anotherKey anotherValue)
)
)
)
)
(distribute
(to $destination :amount BRL $amount|$scale
(description "P2P sent $destination")
(chart-of-accounts p2p_credit_destination_1231412)
)
(distribute :remaining
(to $destination :remaining
(description "P2P sent $destination")
(chart-of-accounts p2p_credit_destination_1231412)
(metadata
(anyKey anyValue)
(anotherKey anotherValue)
)
)
)
)
)
85 changes: 85 additions & 0 deletions components/transaction/examples/transaction.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
(transaction V1
(chart-of-accounts-group-name PAG_CONTAS_CODE_123182371973821973981)
(description "mcgregor for the transaction not for the operation")
(metadata
(m 1)
(Cpf 43049498x)
)
(send BRL 30|4
(source
(from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :amount BRL 2|4)
(from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :share 100 :of 25 :desc whatever)
(from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :remaining)
(from 3172933b-50d2-4b17-96aa-9b378d6a6eac :amount BRL 2|4
(description "description for the transaction not for the operation")
)
(from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :share 50 :of 100 :desc whatever
(description "description for the transaction not for the operation")
)
(from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :remaining
(description "description for the transaction not for the operation")
)
(from 3172933b-50d2-4b17-96aa-9b378d6a6eac :amount BRL 2|4
(metadata
(Cpf 43049498x)
(1 m)
)
)
(from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :share 100 :of 25 :desc whatever
(metadata
(Cpf 43049498x)
(1 m)
)
)
(from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :remaining
(metadata
(Cpf 43049498x)
(1 m)
)
)
(source :remaining
(from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :amount BRL 2|4)
)
)
)
(distribute
(to @McGeegor :share 50 :of 25 :desc whatever)
(to @jeff :amount BRL 2|4)
(to @cl3v_ :remaining)
(to 1a9ba2dd-d778-415f-a61a-387d64994eeb :share 50 :of 100 :desc whatever
(description "description for the transaction not for the operation")
)
(to 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :amount BRL 2|4
(description "description for the transaction not for the operation")
)
(to 9fe618ed-cec1-4a5b-90d8-2f5819a8c3dd :remaining
(description "description for the transaction not for the operation")
)
(to 540b504c-8f9d-480f-9354-3728cf7025ef :share 50 :of 25 :desc whatever
(description "description for the transaction not for the operation")
(metadata
(m m)
(Cpf 43049498x)
)
)
(to 540b504c-8f9d-480f-9354-3728cf7025ef :amount BRL 2|4
(description "description for the transaction not for the operation")
(metadata
(m m)
(Cpf 43049498x)
)
)
(to 540b504c-8f9d-480f-9354-3728cf7025ef :remaining
(description "description for the transaction not for the operation")
(metadata
(m m)
(Cpf 43049498x)
)
)
(distribute :remaining
(to 540b504c-8f9d-480f-9354-3728cf7025ef :share 38)
(to @McGregor :share 50 :of 25 :desc whatever)
(to 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :amount BRL 2|4)
)
)
)
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ import (
"github.com/LerianStudio/midaz/common"
"github.com/LerianStudio/midaz/common/mpostgres"
t "github.com/LerianStudio/midaz/components/transaction/internal/domain/transaction"
sqrl "github.com/Masterminds/squirrel"
"github.com/google/uuid"
"github.com/lib/pq"
)

// TransactionPostgreSQLRepository is a Postgresql-specific implementation of the TransactionRepository.
type TransactionPostgreSQLRepository struct {
connection *mpostgres.PostgresConnection
tableName string
}

// NewTransactionPostgreSQLRepository returns a new instance of TransactionPostgreSQLRepository using the given Postgres connection.
func NewTransactionPostgreSQLRepository(pc *mpostgres.PostgresConnection) *TransactionPostgreSQLRepository {
c := &TransactionPostgreSQLRepository{
connection: pc,
tableName: "transaction",
}

_, err := c.connection.GetDB()
Expand Down Expand Up @@ -83,16 +86,30 @@ func (r *TransactionPostgreSQLRepository) Create(ctx context.Context, transactio
}

// FindAll retrieves Transactions entities from the database.
func (r *TransactionPostgreSQLRepository) FindAll(ctx context.Context, organizationID, ledgerID uuid.UUID) ([]*t.Transaction, error) {
func (r *TransactionPostgreSQLRepository) FindAll(ctx context.Context, organizationID, ledgerID uuid.UUID, limit, page int) ([]*t.Transaction, error) {
db, err := r.connection.GetDB()
if err != nil {
return nil, err
}

var transactions []*t.Transaction

rows, err := db.QueryContext(ctx, "SELECT * FROM transaction WHERE organization_id = $1 AND ledger_id = $2 AND deleted_at IS NULL ORDER BY created_at DESC",
organizationID, ledgerID)
findAll := sqrl.Select("*").
From(r.tableName).
Where(sqrl.Expr("organization_id = ?", organizationID)).
Where(sqrl.Expr("ledger_id = ?", ledgerID)).
Where(sqrl.Eq{"deleted_at": nil}).
OrderBy("created_at DESC").
Limit(uint64(limit)).
Offset(uint64((page - 1) * limit)).
PlaceholderFormat(sqrl.Dollar)

query, args, err := findAll.ToSql()
if err != nil {
return nil, err
}

rows, err := db.QueryContext(ctx, query, args...)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 765e91b

Please sign in to comment.