Skip to content

Commit

Permalink
Merge pull request #362 from LerianStudio/refactor/MIDAZ-353
Browse files Browse the repository at this point in the history
Refactor/MIDAZ-353
  • Loading branch information
MartinezAvellan authored Dec 6, 2024
2 parents 264cf21 + da49821 commit 65c02aa
Show file tree
Hide file tree
Showing 23 changed files with 1,561 additions and 283 deletions.
11 changes: 9 additions & 2 deletions components/auth/setup/00_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,37 @@ INSERT INTO "casbin_lerian_enforcer_rule" ("ptype", "v0", "v1", "v2", "v3", "v4"
('p', 'developer_role', 'organization', 'post', '', '', ''),
('p', 'developer_role', 'organization', 'get', '', '', ''),
('p', 'developer_role', 'organization', 'patch', '', '', ''),
('p', 'developer_role', 'organization', 'put', '', '', ''),
('p', 'developer_role', 'ledger', 'post', '', '', ''),
('p', 'developer_role', 'ledger', 'get', '', '', ''),
('p', 'developer_role', 'ledger', 'patch', '', '', ''),
('p', 'developer_role', 'ledger', 'put', '', '', ''),
('p', 'developer_role', 'asset', 'post', '', '', ''),
('p', 'developer_role', 'asset', 'get', '', '', ''),
('p', 'developer_role', 'asset', 'patch', '', '', ''),
('p', 'developer_role', 'asset', 'put', '', '', ''),
('p', 'developer_role', 'portfolio', 'post', '', '', ''),
('p', 'developer_role', 'portfolio', 'get', '', '', ''),
('p', 'developer_role', 'portfolio', 'patch', '', '', ''),
('p', 'developer_role', 'portfolio', 'put', '', '', ''),
('p', 'developer_role', 'product', 'post', '', '', ''),
('p', 'developer_role', 'product', 'get', '', '', ''),
('p', 'developer_role', 'product', 'patch', '', '', ''),
('p', 'developer_role', 'product', 'put', '', '', ''),
('p', 'developer_role', 'account', 'post', '', '', ''),
('p', 'developer_role', 'account', 'get', '', '', ''),
('p', 'developer_role', 'account', 'patch', '', '', ''),
('p', 'developer_role', 'account', 'put', '', '', ''),
('p', 'developer_role', 'transaction', 'post', '', '', ''),
('p', 'developer_role', 'transaction', 'get', '', '', ''),
('p', 'developer_role', 'transaction', 'patch', '', '', ''),
('p', 'developer_role', 'transaction', 'put', '', '', ''),
('p', 'developer_role', 'operation', 'post', '', '', ''),
('p', 'developer_role', 'operation', 'get', '', '', ''),
('p', 'developer_role', 'operation', 'patch', '', '', ''),
('p', 'developer_role', 'asset-rate', 'post', '', '', ''),
('p', 'developer_role', 'operation', 'put', '', '', ''),
('p', 'developer_role', 'asset-rate', 'put', '', '', ''),
('p', 'developer_role', 'asset-rate', 'get', '', '', ''),
('p', 'developer_role', 'asset-rate', 'patch', '', '', ''),
('p', 'user_role', 'organization', 'get', '', '', ''),
('p', 'user_role', 'ledger', 'get', '', '', ''),
('p', 'user_role', 'asset', 'get', '', '', ''),
Expand Down
3 changes: 2 additions & 1 deletion components/auth/setup/init_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,8 @@
"actions": [
"get",
"post",
"patch"
"patch",
"put"
],
"domains": [],
"effect": "Allow",
Expand Down
10 changes: 10 additions & 0 deletions components/ledger/internal/services/query/get-all-organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package query
import (
"context"
"errors"
"github.com/LerianStudio/midaz/pkg/mopentelemetry"
"reflect"

"github.com/LerianStudio/midaz/components/ledger/internal/services"
Expand All @@ -15,10 +16,17 @@ import (
// GetAllOrganizations fetch all Organizations from the repository
func (uc *UseCase) GetAllOrganizations(ctx context.Context, filter http.QueryHeader) ([]*mmodel.Organization, error) {
logger := pkg.NewLoggerFromContext(ctx)
tracer := pkg.NewTracerFromContext(ctx)

ctx, span := tracer.Start(ctx, "query.get_all_organizations")
defer span.End()

logger.Infof("Retrieving organizations")

organizations, err := uc.OrganizationRepo.FindAll(ctx, filter.Limit, filter.Page)
if err != nil {
mopentelemetry.HandleSpanError(&span, "Failed to get organizations on repo", err)

logger.Errorf("Error getting organizations on repo: %v", err)

if errors.Is(err, services.ErrDatabaseItemNotFound) {
Expand All @@ -31,6 +39,8 @@ func (uc *UseCase) GetAllOrganizations(ctx context.Context, filter http.QueryHea
if organizations != nil {
metadata, err := uc.MetadataRepo.FindList(ctx, reflect.TypeOf(mmodel.Organization{}).Name(), filter)
if err != nil {
mopentelemetry.HandleSpanError(&span, "Failed to get metadata on repo", err)

return nil, pkg.ValidateBusinessError(constant.ErrNoOrganizationsFound, reflect.TypeOf(mmodel.Organization{}).Name())
}

Expand Down
182 changes: 145 additions & 37 deletions components/transaction/api/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const docTemplate = `{
},
"/v1/organizations/{organization_id}/ledgers/{ledger_id}/asset-rates": {
"post": {
"description": "Create an AssetRate with the input payload",
"description": "Create or Update an AssetRate with the input details",
"consumes": [
"application/json"
],
Expand All @@ -169,7 +169,7 @@ const docTemplate = `{
"tags": [
"Asset Rates"
],
"summary": "Create an AssetRate",
"summary": "Create or Update an AssetRate",
"parameters": [
{
"type": "string",
Expand Down Expand Up @@ -218,16 +218,16 @@ const docTemplate = `{
}
}
},
"/v1/organizations/{organization_id}/ledgers/{ledger_id}/asset-rates/{asset_rate_id}": {
"/v1/organizations/{organization_id}/ledgers/{ledger_id}/asset-rates/from/{asset_code}": {
"get": {
"description": "Get an AssetRate with the input ID",
"description": "Get an AssetRate by the Asset Code with the input details",
"produces": [
"application/json"
],
"tags": [
"Asset Rates"
],
"summary": "Get an AssetRate by ID",
"summary": "Get an AssetRate by the Asset Code",
"parameters": [
{
"type": "string",
Expand Down Expand Up @@ -258,20 +258,93 @@ const docTemplate = `{
},
{
"type": "string",
"description": "AssetRate ID",
"name": "asset_rate_id",
"description": "From Asset Code",
"name": "asset_code",
"in": "path",
"required": true
},
{
"description": "AssetRate Input",
"name": "asset-rate",
"in": "body",
"required": true,
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "csv",
"example": "\"BRL,USD,SGD\"",
"description": "To Asset Codes",
"name": "to",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/CreateAssetRateInput"
"allOf": [
{
"$ref": "#/definitions/Pagination"
},
{
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/AssetRate"
}
}
}
}
]
}
}
}
}
},
"/v1/organizations/{organization_id}/ledgers/{ledger_id}/asset-rates/{external_id}": {
"get": {
"description": "Get an AssetRate by External ID with the input details",
"produces": [
"application/json"
],
"tags": [
"Asset Rates"
],
"summary": "Get an AssetRate by External ID",
"parameters": [
{
"type": "string",
"description": "Authorization Bearer Token",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "string",
"description": "Request ID",
"name": "Midaz-Id",
"in": "header"
},
{
"type": "string",
"description": "Organization ID",
"name": "organization_id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Ledger ID",
"name": "ledger_id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "External ID",
"name": "external_id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
Expand Down Expand Up @@ -803,36 +876,41 @@ const docTemplate = `{
"Amount": {
"description": "Amount is the struct designed to represent the amount of an operation.",
"type": "object",
"required": [
"asset",
"value"
],
"properties": {
"amount": {
"type": "number",
"example": 1500
"asset": {
"type": "string",
"example": "BRL"
},
"scale": {
"type": "number",
"type": "integer",
"minimum": 0,
"example": 2
},
"value": {
"type": "integer",
"example": 1000
}
}
},
"AssetRate": {
"description": "AssetRate is a struct designed to store asset rate data.",
"type": "object",
"properties": {
"amount": {
"type": "number",
"example": 5000
},
"baseAssetCode": {
"createdAt": {
"type": "string",
"example": "BRL"
"example": "2021-01-01T00:00:00Z"
},
"counterAssetCode": {
"externalId": {
"type": "string",
"example": "USD"
"example": "00000000-0000-0000-0000-000000000000"
},
"createdAt": {
"from": {
"type": "string",
"example": "2021-01-01T00:00:00Z"
"example": "USD"
},
"id": {
"type": "string",
Expand All @@ -850,13 +928,29 @@ const docTemplate = `{
"type": "string",
"example": "00000000-0000-0000-0000-000000000000"
},
"rate": {
"type": "number",
"example": 100
},
"scale": {
"type": "number",
"example": 2
},
"source": {
"type": "string",
"example": "@person1"
"example": "External System"
},
"to": {
"type": "string",
"example": "BRL"
},
"ttl": {
"type": "integer",
"example": 3600
},
"updatedAt": {
"type": "string",
"example": "2021-01-01T00:00:00Z"
}
}
},
Expand All @@ -881,30 +975,44 @@ const docTemplate = `{
"CreateAssetRateInput": {
"description": "CreateAssetRateInput is the input payload to create an asset rate.",
"type": "object",
"required": [
"from",
"rate",
"to"
],
"properties": {
"amount": {
"type": "number",
"example": 5000
},
"baseAssetCode": {
"externalId": {
"type": "string",
"example": "BRL"
"example": "00000000-0000-0000-0000-000000000000"
},
"counterAssetCode": {
"from": {
"type": "string",
"example": "USD"
},
"metadata": {
"type": "object",
"additionalProperties": {}
},
"rate": {
"type": "integer",
"example": 100
},
"scale": {
"type": "number",
"type": "integer",
"minimum": 0,
"example": 2
},
"source": {
"type": "string",
"example": "@person1"
"example": "External System"
},
"to": {
"type": "string",
"example": "BRL"
},
"ttl": {
"type": "integer",
"example": 3600
}
}
},
Expand Down Expand Up @@ -1155,7 +1263,7 @@ const docTemplate = `{
}
},
"Status": {
"description": "Status is the struct designed to represent the status of an operation.",
"description": "Status is the struct designed to represent the status of a transaction.",
"type": "object",
"properties": {
"code": {
Expand Down
Loading

0 comments on commit 65c02aa

Please sign in to comment.