diff --git a/components/audit/api/docs.go b/components/audit/api/docs.go index cbb94055..0491181e 100644 --- a/components/audit/api/docs.go +++ b/components/audit/api/docs.go @@ -44,7 +44,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -100,7 +100,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { diff --git a/components/audit/api/openapi.yaml b/components/audit/api/openapi.yaml index 0b31fa2c..a6b74d6f 100644 --- a/components/audit/api/openapi.yaml +++ b/components/audit/api/openapi.yaml @@ -25,7 +25,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -68,7 +68,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID diff --git a/components/audit/api/swagger.json b/components/audit/api/swagger.json index 1290be1a..a0cbcfcb 100644 --- a/components/audit/api/swagger.json +++ b/components/audit/api/swagger.json @@ -38,7 +38,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -94,7 +94,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { diff --git a/components/audit/api/swagger.yaml b/components/audit/api/swagger.yaml index eb14d5a9..6bbf5139 100644 --- a/components/audit/api/swagger.yaml +++ b/components/audit/api/swagger.yaml @@ -56,7 +56,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -94,7 +94,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path diff --git a/components/audit/internal/adapters/http/in/trillian.go b/components/audit/internal/adapters/http/in/trillian.go index 599fce1d..43ad1b42 100644 --- a/components/audit/internal/adapters/http/in/trillian.go +++ b/components/audit/internal/adapters/http/in/trillian.go @@ -20,7 +20,7 @@ type TrillianHandler struct { // @Tags Audit // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param audit_id path string true "Audit ID" @@ -84,7 +84,7 @@ func (th *TrillianHandler) AuditLogs(c *fiber.Ctx) error { // @Tags Audit // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param audit_id path string true "Audit ID" diff --git a/components/auth/setup/00_init.sql b/components/auth/setup/00_init.sql index 4bcb6175..260582a5 100644 --- a/components/auth/setup/00_init.sql +++ b/components/auth/setup/00_init.sql @@ -64,6 +64,10 @@ INSERT INTO "casbin_lerian_enforcer_rule" ("ptype", "v0", "v1", "v2", "v3", "v4" ('p', 'developer_role', 'operation', 'get', '', '', ''), ('p', 'developer_role', 'operation', 'patch', '', '', ''), ('p', 'developer_role', 'operation', 'put', '', '', ''), +('p', 'developer_role', 'balance', 'post', '', '', ''), +('p', 'developer_role', 'balance', 'get', '', '', ''), +('p', 'developer_role', 'balance', 'patch', '', '', ''), +('p', 'developer_role', 'balance', 'put', '', '', ''), ('p', 'developer_role', 'asset-rate', 'put', '', '', ''), ('p', 'developer_role', 'asset-rate', 'get', '', '', ''), ('p', 'user_role', 'organization', 'get', '', '', ''), @@ -74,6 +78,7 @@ INSERT INTO "casbin_lerian_enforcer_rule" ("ptype", "v0", "v1", "v2", "v3", "v4" ('p', 'user_role', 'account', 'get', '', '', ''), ('p', 'user_role', 'transaction', 'get', '', '', ''), ('p', 'user_role', 'operation', 'get', '', '', ''), +('p', 'user_role', 'balance', 'get', '', '', ''), ('p', 'user_role', 'asset-rate', 'get', '', '', ''), ('p', 'grpc_role', 'account.AccountProto', '*', '', '', ''), ('p', 'auditor_role', 'audit', 'get', '', '', ''); diff --git a/components/auth/setup/init_data.json b/components/auth/setup/init_data.json index ee0ad8ff..ce20e9fc 100644 --- a/components/auth/setup/init_data.json +++ b/components/auth/setup/init_data.json @@ -817,6 +817,7 @@ "segment", "transaction", "operation", + "balance", "asset-rate" ], "actions": [ @@ -882,6 +883,7 @@ "segment", "transaction", "operation", + "balance", "asset-rate" ], "actions": [ diff --git a/components/mdz/internal/rest/organization_test.go b/components/mdz/internal/rest/organization_test.go index 64fc0a2b..c9950743 100644 --- a/components/mdz/internal/rest/organization_test.go +++ b/components/mdz/internal/rest/organization_test.go @@ -147,7 +147,7 @@ func TestOrganizationGetByID(t *testing.T) { func TestOrganizationUpdate(t *testing.T) { inp := mmodel.UpdateOrganizationInput{ LegalName: "Corwin LLC", - DoingBusinessAs: ptr.StringPtr("The ledger.io"), + DoingBusinessAs: "The ledger.io", Status: mmodel.Status{ Code: "ACTIVE", Description: ptr.StringPtr("Teste Ledger"), diff --git a/components/mdz/pkg/cmd/organization/update.go b/components/mdz/pkg/cmd/organization/update.go index a72a2db6..22162af4 100644 --- a/components/mdz/pkg/cmd/organization/update.go +++ b/components/mdz/pkg/cmd/organization/update.go @@ -95,7 +95,7 @@ func (f *factoryOrganizationUpdate) UpdateRequestFromFlags(org *mmodel.UpdateOrg return err } - org.DoingBusinessAs = &doingBusinessAsPtr + org.DoingBusinessAs = doingBusinessAsPtr org.Status.Code = f.Code org.Status.Description = utils.AssignOptionalStringPtr(f.Description) diff --git a/components/onboarding/api/docs.go b/components/onboarding/api/docs.go index 4f6c0b65..1b047844 100644 --- a/components/onboarding/api/docs.go +++ b/components/onboarding/api/docs.go @@ -44,7 +44,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -143,7 +143,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -187,7 +187,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -224,7 +224,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -264,7 +264,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -315,7 +315,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -422,7 +422,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -473,7 +473,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -517,7 +517,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -564,7 +564,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -622,7 +622,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -735,7 +735,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -793,7 +793,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -849,7 +849,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -900,7 +900,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -954,7 +954,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1019,7 +1019,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1132,7 +1132,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1190,7 +1190,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1241,7 +1241,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1295,7 +1295,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1360,7 +1360,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1473,7 +1473,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1531,7 +1531,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1582,7 +1582,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1636,7 +1636,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1701,7 +1701,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1814,7 +1814,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1872,7 +1872,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1923,7 +1923,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1977,7 +1977,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -2230,7 +2230,8 @@ const docTemplate = `{ "description": "CreateAssetInput is the input payload to create an asset.", "type": "object", "required": [ - "code" + "code", + "name" ], "properties": { "code": { diff --git a/components/onboarding/api/openapi.yaml b/components/onboarding/api/openapi.yaml index f0b43b41..642a8b2e 100644 --- a/components/onboarding/api/openapi.yaml +++ b/components/onboarding/api/openapi.yaml @@ -25,7 +25,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Metadata @@ -84,7 +84,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string requestBody: @@ -117,7 +117,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -144,7 +144,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -174,7 +174,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -213,7 +213,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -279,7 +279,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -318,7 +318,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -351,7 +351,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -387,7 +387,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -432,7 +432,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -503,7 +503,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -548,7 +548,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -591,7 +591,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -630,7 +630,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -672,7 +672,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -723,7 +723,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -794,7 +794,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -839,7 +839,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -878,7 +878,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -920,7 +920,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -971,7 +971,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -1042,7 +1042,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -1087,7 +1087,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -1126,7 +1126,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -1168,7 +1168,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -1219,7 +1219,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -1290,7 +1290,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -1335,7 +1335,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -1374,7 +1374,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -1416,7 +1416,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -1698,6 +1698,7 @@ components: type: string required: - code + - name type: object CreateLedgerInput: description: CreateLedgerInput is the input payload to create a ledger. diff --git a/components/onboarding/api/swagger.json b/components/onboarding/api/swagger.json index bbc68230..c5b7bf73 100644 --- a/components/onboarding/api/swagger.json +++ b/components/onboarding/api/swagger.json @@ -38,7 +38,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -137,7 +137,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -181,7 +181,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -218,7 +218,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -258,7 +258,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -309,7 +309,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -416,7 +416,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -467,7 +467,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -511,7 +511,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -558,7 +558,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -616,7 +616,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -729,7 +729,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -787,7 +787,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -843,7 +843,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -894,7 +894,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -948,7 +948,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1013,7 +1013,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1126,7 +1126,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1184,7 +1184,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1235,7 +1235,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1289,7 +1289,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1354,7 +1354,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1467,7 +1467,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1525,7 +1525,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1576,7 +1576,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1630,7 +1630,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1695,7 +1695,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1808,7 +1808,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1866,7 +1866,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1917,7 +1917,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1971,7 +1971,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -2224,7 +2224,8 @@ "description": "CreateAssetInput is the input payload to create an asset.", "type": "object", "required": [ - "code" + "code", + "name" ], "properties": { "code": { diff --git a/components/onboarding/api/swagger.yaml b/components/onboarding/api/swagger.yaml index 78fb1f69..3e0a82a1 100644 --- a/components/onboarding/api/swagger.yaml +++ b/components/onboarding/api/swagger.yaml @@ -172,6 +172,7 @@ definitions: type: string required: - code + - name type: object CreateLedgerInput: description: CreateLedgerInput is the input payload to create a ledger. @@ -528,7 +529,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Metadata in: query @@ -592,7 +593,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization Input in: body @@ -621,7 +622,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -644,7 +645,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -673,7 +674,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -707,7 +708,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -777,7 +778,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -811,7 +812,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -839,7 +840,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -873,7 +874,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -912,7 +913,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -986,7 +987,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1025,7 +1026,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1063,7 +1064,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1096,7 +1097,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1135,7 +1136,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1179,7 +1180,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1253,7 +1254,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1292,7 +1293,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1325,7 +1326,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1364,7 +1365,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1408,7 +1409,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1482,7 +1483,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1521,7 +1522,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1554,7 +1555,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1593,7 +1594,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1637,7 +1638,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1711,7 +1712,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1750,7 +1751,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1783,7 +1784,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1822,7 +1823,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path diff --git a/components/onboarding/internal/adapters/http/in/account.go b/components/onboarding/internal/adapters/http/in/account.go index 7f20e1ca..b3e23dc9 100644 --- a/components/onboarding/internal/adapters/http/in/account.go +++ b/components/onboarding/internal/adapters/http/in/account.go @@ -29,7 +29,7 @@ type AccountHandler struct { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param account body mmodel.CreateAccountInput true "Account" @@ -80,7 +80,7 @@ func (handler *AccountHandler) CreateAccount(i any, c *fiber.Ctx) error { // @Tags Accounts // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param metadata query string false "Metadata" @@ -174,7 +174,7 @@ func (handler *AccountHandler) GetAllAccounts(c *fiber.Ctx) error { // @Tags Accounts // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param id path string true "Account ID" @@ -216,7 +216,7 @@ func (handler *AccountHandler) GetAccountByID(c *fiber.Ctx) error { // @Tags Accounts // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param alias path string true "Alias" @@ -259,7 +259,7 @@ func (handler *AccountHandler) GetAccountByAlias(c *fiber.Ctx) error { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param id path string true "Account ID" @@ -320,7 +320,7 @@ func (handler *AccountHandler) UpdateAccount(i any, c *fiber.Ctx) error { // @Description Delete an Account with the input ID // @Tags Accounts // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param id path string true "Account ID" diff --git a/components/onboarding/internal/adapters/http/in/asset.go b/components/onboarding/internal/adapters/http/in/asset.go index 078f163d..db2f6706 100644 --- a/components/onboarding/internal/adapters/http/in/asset.go +++ b/components/onboarding/internal/adapters/http/in/asset.go @@ -29,7 +29,7 @@ type AssetHandler struct { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param asset body mmodel.CreateAssetInput true "Asset Input" @@ -81,7 +81,7 @@ func (handler *AssetHandler) CreateAsset(a any, c *fiber.Ctx) error { // @Tags Assets // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param metadata query string false "Metadata" @@ -170,7 +170,7 @@ func (handler *AssetHandler) GetAllAssets(c *fiber.Ctx) error { // @Tags Assets // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param id path string true "Asset ID" @@ -213,7 +213,7 @@ func (handler *AssetHandler) GetAssetByID(c *fiber.Ctx) error { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param id path string true "Asset ID" @@ -274,7 +274,7 @@ func (handler *AssetHandler) UpdateAsset(a any, c *fiber.Ctx) error { // @Description Delete an Asset with the input ID // @Tags Assets // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param id path string true "Asset ID" diff --git a/components/onboarding/internal/adapters/http/in/ledger.go b/components/onboarding/internal/adapters/http/in/ledger.go index 44b0a088..e10c7b82 100644 --- a/components/onboarding/internal/adapters/http/in/ledger.go +++ b/components/onboarding/internal/adapters/http/in/ledger.go @@ -33,7 +33,7 @@ type LedgerHandler struct { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger body mmodel.CreateLedgerInput true "Ledger Input" // @Success 200 {object} mmodel.Ledger @@ -79,7 +79,7 @@ func (handler *LedgerHandler) CreateLedger(i any, c *fiber.Ctx) error { // @Tags Ledgers // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param id path string true "Ledger ID" // @Success 200 {object} mmodel.Ledger @@ -119,7 +119,7 @@ func (handler *LedgerHandler) GetLedgerByID(c *fiber.Ctx) error { // @Tags Ledgers // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param id path string true "Ledger ID" // @Param limit query int false "Limit" default(10) @@ -204,7 +204,7 @@ func (handler *LedgerHandler) GetAllLedgers(c *fiber.Ctx) error { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param id path string true "Ledger ID" // @Param ledger body mmodel.UpdateLedgerInput true "Ledger Input" @@ -263,7 +263,7 @@ func (handler *LedgerHandler) UpdateLedger(p any, c *fiber.Ctx) error { // @Description Delete a Ledger with the input ID // @Tags Ledgers // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param id path string true "Ledger ID" // @Success 204 diff --git a/components/onboarding/internal/adapters/http/in/organization.go b/components/onboarding/internal/adapters/http/in/organization.go index 722287c1..d11f580d 100644 --- a/components/onboarding/internal/adapters/http/in/organization.go +++ b/components/onboarding/internal/adapters/http/in/organization.go @@ -32,7 +32,7 @@ type OrganizationHandler struct { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization body mmodel.CreateOrganizationInput true "Organization Input" // @Success 200 {object} mmodel.Organization // @Router /v1/organizations [post] @@ -75,7 +75,7 @@ func (handler *OrganizationHandler) CreateOrganization(p any, c *fiber.Ctx) erro // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param id path string true "Organization ID" // @Param organization body mmodel.UpdateOrganizationInput true "Organization Input" // @Success 200 {object} mmodel.Organization @@ -132,7 +132,7 @@ func (handler *OrganizationHandler) UpdateOrganization(p any, c *fiber.Ctx) erro // @Tags Organizations // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param id path string true "Organization ID" // @Success 200 {object} mmodel.Organization // @Router /v1/organizations/{id} [get] @@ -169,7 +169,7 @@ func (handler *OrganizationHandler) GetOrganizationByID(c *fiber.Ctx) error { // @Tags Organizations // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param metadata query string false "Metadata" // @Param limit query int false "Limit" default(10) // @Param page query int false "Page" default(1) @@ -248,7 +248,7 @@ func (handler *OrganizationHandler) GetAllOrganizations(c *fiber.Ctx) error { // @Description Delete an Organization with the input ID // @Tags Organizations // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param id path string true "Organization ID" // @Success 204 // @Router /v1/organizations/{id} [delete] diff --git a/components/onboarding/internal/adapters/http/in/portfolio.go b/components/onboarding/internal/adapters/http/in/portfolio.go index 68e052bf..07fc9971 100644 --- a/components/onboarding/internal/adapters/http/in/portfolio.go +++ b/components/onboarding/internal/adapters/http/in/portfolio.go @@ -29,7 +29,7 @@ type PortfolioHandler struct { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param portfolio body mmodel.CreatePortfolioInput true "Portfolio Payload" @@ -79,7 +79,7 @@ func (handler *PortfolioHandler) CreatePortfolio(i any, c *fiber.Ctx) error { // @Tags Portfolios // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param metadata query string false "Metadata query" @@ -166,7 +166,7 @@ func (handler *PortfolioHandler) GetAllPortfolios(c *fiber.Ctx) error { // @Tags Portfolios // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param id path string true "Portfolio ID" @@ -209,7 +209,7 @@ func (handler *PortfolioHandler) GetPortfolioByID(c *fiber.Ctx) error { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param id path string true "Portfolio ID" @@ -270,7 +270,7 @@ func (handler *PortfolioHandler) UpdatePortfolio(i any, c *fiber.Ctx) error { // @Description Delete a Portfolio with the input ID // @Tags Portfolios // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param id path string true "Portfolio ID" diff --git a/components/onboarding/internal/adapters/http/in/segment.go b/components/onboarding/internal/adapters/http/in/segment.go index c7eacf3c..724daa33 100644 --- a/components/onboarding/internal/adapters/http/in/segment.go +++ b/components/onboarding/internal/adapters/http/in/segment.go @@ -29,7 +29,7 @@ type SegmentHandler struct { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param segment body mmodel.CreateSegmentInput true "Segment" @@ -77,7 +77,7 @@ func (handler *SegmentHandler) CreateSegment(i any, c *fiber.Ctx) error { // @Tags Segments // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param metadata query string false "Metadata" @@ -164,7 +164,7 @@ func (handler *SegmentHandler) GetAllSegments(c *fiber.Ctx) error { // @Tags Segments // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param id path string true "Segment ID" @@ -206,7 +206,7 @@ func (handler *SegmentHandler) GetSegmentByID(c *fiber.Ctx) error { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param id path string true "Segment ID" @@ -266,7 +266,7 @@ func (handler *SegmentHandler) UpdateSegment(i any, c *fiber.Ctx) error { // @Description Delete a Segment with the input ID // @Tags Segments // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param id path string true "Segment ID" diff --git a/components/onboarding/internal/services/command/update-organization.go b/components/onboarding/internal/services/command/update-organization.go index 7257b79e..ff716fc2 100644 --- a/components/onboarding/internal/services/command/update-organization.go +++ b/components/onboarding/internal/services/command/update-organization.go @@ -39,7 +39,7 @@ func (uc *UseCase) UpdateOrganizationByID(ctx context.Context, id uuid.UUID, uoi organization := &mmodel.Organization{ ParentOrganizationID: uoi.ParentOrganizationID, LegalName: uoi.LegalName, - DoingBusinessAs: uoi.DoingBusinessAs, + DoingBusinessAs: &uoi.DoingBusinessAs, Address: uoi.Address, Status: uoi.Status, } diff --git a/components/onboarding/internal/services/command/update-organization_test.go b/components/onboarding/internal/services/command/update-organization_test.go index cba009ad..51cc3112 100644 --- a/components/onboarding/internal/services/command/update-organization_test.go +++ b/components/onboarding/internal/services/command/update-organization_test.go @@ -42,7 +42,7 @@ func TestUpdateOrganizationByID(t *testing.T) { input: &mmodel.UpdateOrganizationInput{ ParentOrganizationID: nil, LegalName: "Updated Organization", - DoingBusinessAs: ptr.StringPtr("Updated DBA"), + DoingBusinessAs: "Updated DBA", Address: mmodel.Address{Country: "US"}, Status: mmodel.Status{Code: "active"}, Metadata: map[string]any{"key": "value"}, diff --git a/components/transaction/api/docs.go b/components/transaction/api/docs.go index effc8854..93800534 100644 --- a/components/transaction/api/docs.go +++ b/components/transaction/api/docs.go @@ -23,6 +23,397 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { + "/v1/organizations/:organization_id/ledgers/:ledger_id/accounts/:account_id/balances": { + "get": { + "description": "Get all balances by account id", + "produces": [ + "application/json" + ], + "tags": [ + "Balances" + ], + "summary": "Get all balances by account id", + "parameters": [ + { + "type": "string", + "description": "Authorization Bearer Token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "Request ID", + "name": "X-Request-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": "Account ID", + "name": "account_id", + "in": "path", + "required": true + }, + { + "type": "integer", + "default": 10, + "description": "Limit", + "name": "limit", + "in": "query" + }, + { + "type": "string", + "description": "Start Date", + "name": "start_date", + "in": "query" + }, + { + "type": "string", + "description": "End Date", + "name": "end_date", + "in": "query" + }, + { + "type": "string", + "description": "Sort Order", + "name": "sort_order", + "in": "query" + }, + { + "type": "string", + "description": "Cursor", + "name": "cursor", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/Pagination" + }, + { + "type": "object", + "properties": { + " next_cursor": { + "type": "string" + }, + " prev_cursor": { + "type": "string" + }, + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/mmodel.Balance" + } + }, + "limit": { + "type": "integer" + } + } + } + ] + } + } + } + } + }, + "/v1/organizations/:organization_id/ledgers/:ledger_id/balances": { + "get": { + "description": "Get all balances", + "produces": [ + "application/json" + ], + "tags": [ + "Balances" + ], + "summary": "Get all balances", + "parameters": [ + { + "type": "string", + "description": "Authorization Bearer Token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "Request ID", + "name": "X-Request-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": "integer", + "default": 10, + "description": "Limit", + "name": "limit", + "in": "query" + }, + { + "type": "string", + "description": "Start Date", + "name": "start_date", + "in": "query" + }, + { + "type": "string", + "description": "End Date", + "name": "end_date", + "in": "query" + }, + { + "type": "string", + "description": "Sort Order", + "name": "sort_order", + "in": "query" + }, + { + "type": "string", + "description": "Cursor", + "name": "cursor", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/Pagination" + }, + { + "type": "object", + "properties": { + " next_cursor": { + "type": "string" + }, + " prev_cursor": { + "type": "string" + }, + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/mmodel.Balance" + } + }, + "limit": { + "type": "integer" + } + } + } + ] + } + } + } + } + }, + "/v1/organizations/:organization_id/ledgers/:ledger_id/balances/:balance_id": { + "get": { + "description": "Get a Balance with the input ID", + "produces": [ + "application/json" + ], + "tags": [ + "Balances" + ], + "summary": "Get Balance by id", + "parameters": [ + { + "type": "string", + "description": "Authorization Bearer Token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "Request ID", + "name": "X-Request-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": "Balance ID", + "name": "balance_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mmodel.Balance" + } + } + } + }, + "delete": { + "description": "Delete a Balance with the input ID", + "produces": [ + "application/json" + ], + "tags": [ + "Balances" + ], + "summary": "Delete Balance by account", + "parameters": [ + { + "type": "string", + "description": "Authorization Bearer Token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "Request ID", + "name": "X-Request-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": "Balance ID", + "name": "balance_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mmodel.Balance" + } + } + } + }, + "patch": { + "description": "Update a Balance with the input payload", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Balances" + ], + "summary": "Update Balance", + "parameters": [ + { + "type": "string", + "description": "Authorization Bearer Token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "Request ID", + "name": "X-Request-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": "Balance ID", + "name": "balance_id", + "in": "path", + "required": true + }, + { + "description": "Balance Input", + "name": "balance", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/mmodel.UpdateBalance" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mmodel.Balance" + } + } + } + } + }, "/v1/organizations/{organization_id}/ledgers/{ledger_id}/accounts/{account_id}/operations": { "get": { "description": "Get all Operations with the input ID", @@ -44,7 +435,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -89,7 +480,7 @@ const docTemplate = `{ }, { "type": "string", - "description": "Ledger ID", + "description": "Sort Order", "name": "sort_order", "in": "query" }, @@ -155,7 +546,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -221,7 +612,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -279,7 +670,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -404,7 +795,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -460,7 +851,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -574,7 +965,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -633,7 +1024,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -691,7 +1082,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -748,7 +1139,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -816,7 +1207,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -891,7 +1282,7 @@ const docTemplate = `{ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1494,6 +1885,89 @@ const docTemplate = `{ "additionalProperties": {} } } + }, + "mmodel.Balance": { + "description": "Balance is a struct designed to store balance data.", + "type": "object", + "properties": { + "accountId": { + "type": "string", + "example": "00000000-0000-0000-0000-000000000000" + }, + "accountType": { + "type": "string", + "example": "creditCard" + }, + "alias": { + "type": "string", + "example": "@person1" + }, + "allowReceiving": { + "type": "boolean", + "example": true + }, + "allowSending": { + "type": "boolean", + "example": true + }, + "assetCode": { + "type": "string", + "example": "BRL" + }, + "available": { + "type": "integer", + "example": 1500 + }, + "createdAt": { + "type": "string", + "example": "2021-01-01T00:00:00Z" + }, + "deletedAt": { + "type": "string", + "example": "2021-01-01T00:00:00Z" + }, + "id": { + "type": "string", + "example": "00000000-0000-0000-0000-000000000000" + }, + "ledgerId": { + "type": "string", + "example": "00000000-0000-0000-0000-000000000000" + }, + "metadata": { + "type": "object", + "additionalProperties": {} + }, + "onHold": { + "type": "integer", + "example": 500 + }, + "organizationId": { + "type": "string", + "example": "00000000-0000-0000-0000-000000000000" + }, + "scale": { + "type": "integer", + "example": 2 + }, + "updatedAt": { + "type": "string", + "example": "2021-01-01T00:00:00Z" + } + } + }, + "mmodel.UpdateBalance": { + "type": "object", + "properties": { + "allowReceiving": { + "type": "boolean", + "example": true + }, + "allowSending": { + "type": "boolean", + "example": true + } + } } } }` diff --git a/components/transaction/api/openapi.yaml b/components/transaction/api/openapi.yaml index b3047ccd..aca9bcfb 100644 --- a/components/transaction/api/openapi.yaml +++ b/components/transaction/api/openapi.yaml @@ -13,9 +13,9 @@ info: servers: - url: //localhost:3001/ paths: - /v1/organizations/{organization_id}/ledgers/{ledger_id}/accounts/{account_id}/operations: + /v1/organizations/:organization_id/ledgers/:ledger_id/accounts/:account_id/balances: get: - description: Get all Operations with the input ID + description: Get all balances by account id parameters: - description: Authorization Bearer Token in: header @@ -25,7 +25,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -62,7 +62,70 @@ paths: name: end_date schema: type: string + - description: Sort Order + in: query + name: sort_order + schema: + type: string + - description: Cursor + in: query + name: cursor + schema: + type: string + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/inline_response_200' + description: OK + summary: Get all balances by account id + tags: + - Balances + /v1/organizations/:organization_id/ledgers/:ledger_id/balances: + get: + description: Get all balances + parameters: + - description: Authorization Bearer Token + in: header + name: Authorization + required: true + schema: + type: string + - description: Request ID + in: header + name: X-Request-Id + schema: + type: string + - description: Organization ID + in: path + name: organization_id + required: true + schema: + type: string - description: Ledger ID + in: path + name: ledger_id + required: true + schema: + type: string + - description: Limit + in: query + name: limit + schema: + default: 10 + type: integer + - description: Start Date + in: query + name: start_date + schema: + type: string + - description: End Date + in: query + name: end_date + schema: + type: string + - description: Sort Order in: query name: sort_order schema: @@ -79,6 +142,210 @@ paths: schema: $ref: '#/components/schemas/inline_response_200' description: OK + summary: Get all balances + tags: + - Balances + /v1/organizations/:organization_id/ledgers/:ledger_id/balances/:balance_id: + delete: + description: Delete a Balance with the input ID + parameters: + - description: Authorization Bearer Token + in: header + name: Authorization + required: true + schema: + type: string + - description: Request ID + in: header + name: X-Request-Id + schema: + type: string + - description: Organization ID + in: path + name: organization_id + required: true + schema: + type: string + - description: Ledger ID + in: path + name: ledger_id + required: true + schema: + type: string + - description: Balance ID + in: path + name: balance_id + required: true + schema: + type: string + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/mmodel.Balance' + description: OK + summary: Delete Balance by account + tags: + - Balances + get: + description: Get a Balance with the input ID + parameters: + - description: Authorization Bearer Token + in: header + name: Authorization + required: true + schema: + type: string + - description: Request ID + in: header + name: X-Request-Id + schema: + type: string + - description: Organization ID + in: path + name: organization_id + required: true + schema: + type: string + - description: Ledger ID + in: path + name: ledger_id + required: true + schema: + type: string + - description: Balance ID + in: path + name: balance_id + required: true + schema: + type: string + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/mmodel.Balance' + description: OK + summary: Get Balance by id + tags: + - Balances + patch: + description: Update a Balance with the input payload + parameters: + - description: Authorization Bearer Token + in: header + name: Authorization + required: true + schema: + type: string + - description: Request ID + in: header + name: X-Request-Id + schema: + type: string + - description: Organization ID + in: path + name: organization_id + required: true + schema: + type: string + - description: Ledger ID + in: path + name: ledger_id + required: true + schema: + type: string + - description: Balance ID + in: path + name: balance_id + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/mmodel.UpdateBalance' + description: Balance Input + required: true + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/mmodel.Balance' + description: OK + summary: Update Balance + tags: + - Balances + x-codegen-request-body-name: balance + /v1/organizations/{organization_id}/ledgers/{ledger_id}/accounts/{account_id}/operations: + get: + description: Get all Operations with the input ID + parameters: + - description: Authorization Bearer Token + in: header + name: Authorization + required: true + schema: + type: string + - description: Request ID + in: header + name: X-Request-Id + schema: + type: string + - description: Organization ID + in: path + name: organization_id + required: true + schema: + type: string + - description: Ledger ID + in: path + name: ledger_id + required: true + schema: + type: string + - description: Account ID + in: path + name: account_id + required: true + schema: + type: string + - description: Limit + in: query + name: limit + schema: + default: 10 + type: integer + - description: Start Date + in: query + name: start_date + schema: + type: string + - description: End Date + in: query + name: end_date + schema: + type: string + - description: Sort Order + in: query + name: sort_order + schema: + type: string + - description: Cursor + in: query + name: cursor + schema: + type: string + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/inline_response_200_1' + description: OK summary: Get all Operations by account tags: - Operations @@ -94,7 +361,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -143,7 +410,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -188,7 +455,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -252,7 +519,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/inline_response_200_1' + $ref: '#/components/schemas/inline_response_200_2' description: OK summary: Get an AssetRate by the Asset Code tags: @@ -269,7 +536,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -312,7 +579,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -361,7 +628,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/inline_response_200_2' + $ref: '#/components/schemas/inline_response_200_3' description: OK summary: Get all Transactions tags: @@ -378,7 +645,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -427,7 +694,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -472,7 +739,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -514,7 +781,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -565,7 +832,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -622,7 +889,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id schema: type: string - description: Organization ID @@ -1555,7 +1822,147 @@ components: type: object type: object type: object + mmodel.Balance: + description: Balance is a struct designed to store balance data. + example: + metadata: + key: '{}' + assetCode: BRL + onHold: 500 + allowReceiving: true + accountType: creditCard + available: 1500 + scale: 2 + allowSending: true + ledgerId: 00000000-0000-0000-0000-000000000000 + organizationId: 00000000-0000-0000-0000-000000000000 + accountId: 00000000-0000-0000-0000-000000000000 + createdAt: 2021-01-01T00:00:00Z + deletedAt: 2021-01-01T00:00:00Z + alias: '@person1' + id: 00000000-0000-0000-0000-000000000000 + updatedAt: 2021-01-01T00:00:00Z + properties: + accountId: + example: 00000000-0000-0000-0000-000000000000 + type: string + accountType: + example: creditCard + type: string + alias: + example: '@person1' + type: string + allowReceiving: + example: true + type: boolean + allowSending: + example: true + type: boolean + assetCode: + example: BRL + type: string + available: + example: 1500 + type: integer + createdAt: + example: 2021-01-01T00:00:00Z + type: string + deletedAt: + example: 2021-01-01T00:00:00Z + type: string + id: + example: 00000000-0000-0000-0000-000000000000 + type: string + ledgerId: + example: 00000000-0000-0000-0000-000000000000 + type: string + metadata: + additionalProperties: + type: object + type: object + onHold: + example: 500 + type: integer + organizationId: + example: 00000000-0000-0000-0000-000000000000 + type: string + scale: + example: 2 + type: integer + updatedAt: + example: 2021-01-01T00:00:00Z + type: string + type: object + mmodel.UpdateBalance: + properties: + allowReceiving: + example: true + type: boolean + allowSending: + example: true + type: boolean + type: object inline_response_200: + example: + Pagination: + prev_cursor: MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAwMA== + next_cursor: MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAwMA== + limit: 10 + page: 1 + items: '{}' + ' prev_cursor': ' prev_cursor' + ' next_cursor': ' next_cursor' + limit: 0 + items: + - metadata: + key: '{}' + assetCode: BRL + onHold: 500 + allowReceiving: true + accountType: creditCard + available: 1500 + scale: 2 + allowSending: true + ledgerId: 00000000-0000-0000-0000-000000000000 + organizationId: 00000000-0000-0000-0000-000000000000 + accountId: 00000000-0000-0000-0000-000000000000 + createdAt: 2021-01-01T00:00:00Z + deletedAt: 2021-01-01T00:00:00Z + alias: '@person1' + id: 00000000-0000-0000-0000-000000000000 + updatedAt: 2021-01-01T00:00:00Z + - metadata: + key: '{}' + assetCode: BRL + onHold: 500 + allowReceiving: true + accountType: creditCard + available: 1500 + scale: 2 + allowSending: true + ledgerId: 00000000-0000-0000-0000-000000000000 + organizationId: 00000000-0000-0000-0000-000000000000 + accountId: 00000000-0000-0000-0000-000000000000 + createdAt: 2021-01-01T00:00:00Z + deletedAt: 2021-01-01T00:00:00Z + alias: '@person1' + id: 00000000-0000-0000-0000-000000000000 + updatedAt: 2021-01-01T00:00:00Z + properties: + ' next_cursor': + type: string + ' prev_cursor': + type: string + Pagination: + $ref: '#/components/schemas/Pagination' + items: + items: + $ref: '#/components/schemas/mmodel.Balance' + type: array + limit: + type: integer + type: object + inline_response_200_1: example: Pagination: prev_cursor: MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAwMA== @@ -1643,7 +2050,7 @@ components: limit: type: integer type: object - inline_response_200_1: + inline_response_200_2: example: Pagination: prev_cursor: MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAwMA== @@ -1697,7 +2104,7 @@ components: prev_cursor: type: string type: object - inline_response_200_2: + inline_response_200_3: example: Pagination: prev_cursor: MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAwMA== diff --git a/components/transaction/api/swagger.json b/components/transaction/api/swagger.json index cea9610a..281f9875 100644 --- a/components/transaction/api/swagger.json +++ b/components/transaction/api/swagger.json @@ -17,6 +17,397 @@ "host": "localhost:3001", "basePath": "/", "paths": { + "/v1/organizations/:organization_id/ledgers/:ledger_id/accounts/:account_id/balances": { + "get": { + "description": "Get all balances by account id", + "produces": [ + "application/json" + ], + "tags": [ + "Balances" + ], + "summary": "Get all balances by account id", + "parameters": [ + { + "type": "string", + "description": "Authorization Bearer Token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "Request ID", + "name": "X-Request-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": "Account ID", + "name": "account_id", + "in": "path", + "required": true + }, + { + "type": "integer", + "default": 10, + "description": "Limit", + "name": "limit", + "in": "query" + }, + { + "type": "string", + "description": "Start Date", + "name": "start_date", + "in": "query" + }, + { + "type": "string", + "description": "End Date", + "name": "end_date", + "in": "query" + }, + { + "type": "string", + "description": "Sort Order", + "name": "sort_order", + "in": "query" + }, + { + "type": "string", + "description": "Cursor", + "name": "cursor", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/Pagination" + }, + { + "type": "object", + "properties": { + " next_cursor": { + "type": "string" + }, + " prev_cursor": { + "type": "string" + }, + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/mmodel.Balance" + } + }, + "limit": { + "type": "integer" + } + } + } + ] + } + } + } + } + }, + "/v1/organizations/:organization_id/ledgers/:ledger_id/balances": { + "get": { + "description": "Get all balances", + "produces": [ + "application/json" + ], + "tags": [ + "Balances" + ], + "summary": "Get all balances", + "parameters": [ + { + "type": "string", + "description": "Authorization Bearer Token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "Request ID", + "name": "X-Request-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": "integer", + "default": 10, + "description": "Limit", + "name": "limit", + "in": "query" + }, + { + "type": "string", + "description": "Start Date", + "name": "start_date", + "in": "query" + }, + { + "type": "string", + "description": "End Date", + "name": "end_date", + "in": "query" + }, + { + "type": "string", + "description": "Sort Order", + "name": "sort_order", + "in": "query" + }, + { + "type": "string", + "description": "Cursor", + "name": "cursor", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/Pagination" + }, + { + "type": "object", + "properties": { + " next_cursor": { + "type": "string" + }, + " prev_cursor": { + "type": "string" + }, + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/mmodel.Balance" + } + }, + "limit": { + "type": "integer" + } + } + } + ] + } + } + } + } + }, + "/v1/organizations/:organization_id/ledgers/:ledger_id/balances/:balance_id": { + "get": { + "description": "Get a Balance with the input ID", + "produces": [ + "application/json" + ], + "tags": [ + "Balances" + ], + "summary": "Get Balance by id", + "parameters": [ + { + "type": "string", + "description": "Authorization Bearer Token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "Request ID", + "name": "X-Request-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": "Balance ID", + "name": "balance_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mmodel.Balance" + } + } + } + }, + "delete": { + "description": "Delete a Balance with the input ID", + "produces": [ + "application/json" + ], + "tags": [ + "Balances" + ], + "summary": "Delete Balance by account", + "parameters": [ + { + "type": "string", + "description": "Authorization Bearer Token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "Request ID", + "name": "X-Request-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": "Balance ID", + "name": "balance_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mmodel.Balance" + } + } + } + }, + "patch": { + "description": "Update a Balance with the input payload", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Balances" + ], + "summary": "Update Balance", + "parameters": [ + { + "type": "string", + "description": "Authorization Bearer Token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "Request ID", + "name": "X-Request-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": "Balance ID", + "name": "balance_id", + "in": "path", + "required": true + }, + { + "description": "Balance Input", + "name": "balance", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/mmodel.UpdateBalance" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mmodel.Balance" + } + } + } + } + }, "/v1/organizations/{organization_id}/ledgers/{ledger_id}/accounts/{account_id}/operations": { "get": { "description": "Get all Operations with the input ID", @@ -38,7 +429,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -83,7 +474,7 @@ }, { "type": "string", - "description": "Ledger ID", + "description": "Sort Order", "name": "sort_order", "in": "query" }, @@ -149,7 +540,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -215,7 +606,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -273,7 +664,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -398,7 +789,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -454,7 +845,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -568,7 +959,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -627,7 +1018,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -685,7 +1076,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -742,7 +1133,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -810,7 +1201,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -885,7 +1276,7 @@ { "type": "string", "description": "Request ID", - "name": "Midaz-Id", + "name": "X-Request-Id", "in": "header" }, { @@ -1488,6 +1879,89 @@ "additionalProperties": {} } } + }, + "mmodel.Balance": { + "description": "Balance is a struct designed to store balance data.", + "type": "object", + "properties": { + "accountId": { + "type": "string", + "example": "00000000-0000-0000-0000-000000000000" + }, + "accountType": { + "type": "string", + "example": "creditCard" + }, + "alias": { + "type": "string", + "example": "@person1" + }, + "allowReceiving": { + "type": "boolean", + "example": true + }, + "allowSending": { + "type": "boolean", + "example": true + }, + "assetCode": { + "type": "string", + "example": "BRL" + }, + "available": { + "type": "integer", + "example": 1500 + }, + "createdAt": { + "type": "string", + "example": "2021-01-01T00:00:00Z" + }, + "deletedAt": { + "type": "string", + "example": "2021-01-01T00:00:00Z" + }, + "id": { + "type": "string", + "example": "00000000-0000-0000-0000-000000000000" + }, + "ledgerId": { + "type": "string", + "example": "00000000-0000-0000-0000-000000000000" + }, + "metadata": { + "type": "object", + "additionalProperties": {} + }, + "onHold": { + "type": "integer", + "example": 500 + }, + "organizationId": { + "type": "string", + "example": "00000000-0000-0000-0000-000000000000" + }, + "scale": { + "type": "integer", + "example": 2 + }, + "updatedAt": { + "type": "string", + "example": "2021-01-01T00:00:00Z" + } + } + }, + "mmodel.UpdateBalance": { + "type": "object", + "properties": { + "allowReceiving": { + "type": "boolean", + "example": true + }, + "allowSending": { + "type": "boolean", + "example": true + } + } } } } \ No newline at end of file diff --git a/components/transaction/api/swagger.yaml b/components/transaction/api/swagger.yaml index 12ea5929..30d4d812 100644 --- a/components/transaction/api/swagger.yaml +++ b/components/transaction/api/swagger.yaml @@ -419,6 +419,67 @@ definitions: additionalProperties: {} type: object type: object + mmodel.Balance: + description: Balance is a struct designed to store balance data. + properties: + accountId: + example: 00000000-0000-0000-0000-000000000000 + type: string + accountType: + example: creditCard + type: string + alias: + example: '@person1' + type: string + allowReceiving: + example: true + type: boolean + allowSending: + example: true + type: boolean + assetCode: + example: BRL + type: string + available: + example: 1500 + type: integer + createdAt: + example: "2021-01-01T00:00:00Z" + type: string + deletedAt: + example: "2021-01-01T00:00:00Z" + type: string + id: + example: 00000000-0000-0000-0000-000000000000 + type: string + ledgerId: + example: 00000000-0000-0000-0000-000000000000 + type: string + metadata: + additionalProperties: {} + type: object + onHold: + example: 500 + type: integer + organizationId: + example: 00000000-0000-0000-0000-000000000000 + type: string + scale: + example: 2 + type: integer + updatedAt: + example: "2021-01-01T00:00:00Z" + type: string + type: object + mmodel.UpdateBalance: + properties: + allowReceiving: + example: true + type: boolean + allowSending: + example: true + type: boolean + type: object host: localhost:3001 info: contact: @@ -432,6 +493,265 @@ info: title: Midaz Transaction API version: v1.48.0 paths: + /v1/organizations/:organization_id/ledgers/:ledger_id/accounts/:account_id/balances: + get: + description: Get all balances by account id + parameters: + - description: Authorization Bearer Token + in: header + name: Authorization + required: true + type: string + - description: Request ID + in: header + name: X-Request-Id + type: string + - description: Organization ID + in: path + name: organization_id + required: true + type: string + - description: Ledger ID + in: path + name: ledger_id + required: true + type: string + - description: Account ID + in: path + name: account_id + required: true + type: string + - default: 10 + description: Limit + in: query + name: limit + type: integer + - description: Start Date + in: query + name: start_date + type: string + - description: End Date + in: query + name: end_date + type: string + - description: Sort Order + in: query + name: sort_order + type: string + - description: Cursor + in: query + name: cursor + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/Pagination' + - properties: + ' next_cursor': + type: string + ' prev_cursor': + type: string + items: + items: + $ref: '#/definitions/mmodel.Balance' + type: array + limit: + type: integer + type: object + summary: Get all balances by account id + tags: + - Balances + /v1/organizations/:organization_id/ledgers/:ledger_id/balances: + get: + description: Get all balances + parameters: + - description: Authorization Bearer Token + in: header + name: Authorization + required: true + type: string + - description: Request ID + in: header + name: X-Request-Id + type: string + - description: Organization ID + in: path + name: organization_id + required: true + type: string + - description: Ledger ID + in: path + name: ledger_id + required: true + type: string + - default: 10 + description: Limit + in: query + name: limit + type: integer + - description: Start Date + in: query + name: start_date + type: string + - description: End Date + in: query + name: end_date + type: string + - description: Sort Order + in: query + name: sort_order + type: string + - description: Cursor + in: query + name: cursor + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/Pagination' + - properties: + ' next_cursor': + type: string + ' prev_cursor': + type: string + items: + items: + $ref: '#/definitions/mmodel.Balance' + type: array + limit: + type: integer + type: object + summary: Get all balances + tags: + - Balances + /v1/organizations/:organization_id/ledgers/:ledger_id/balances/:balance_id: + delete: + description: Delete a Balance with the input ID + parameters: + - description: Authorization Bearer Token + in: header + name: Authorization + required: true + type: string + - description: Request ID + in: header + name: X-Request-Id + type: string + - description: Organization ID + in: path + name: organization_id + required: true + type: string + - description: Ledger ID + in: path + name: ledger_id + required: true + type: string + - description: Balance ID + in: path + name: balance_id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/mmodel.Balance' + summary: Delete Balance by account + tags: + - Balances + get: + description: Get a Balance with the input ID + parameters: + - description: Authorization Bearer Token + in: header + name: Authorization + required: true + type: string + - description: Request ID + in: header + name: X-Request-Id + type: string + - description: Organization ID + in: path + name: organization_id + required: true + type: string + - description: Ledger ID + in: path + name: ledger_id + required: true + type: string + - description: Balance ID + in: path + name: balance_id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/mmodel.Balance' + summary: Get Balance by id + tags: + - Balances + patch: + consumes: + - application/json + description: Update a Balance with the input payload + parameters: + - description: Authorization Bearer Token + in: header + name: Authorization + required: true + type: string + - description: Request ID + in: header + name: X-Request-Id + type: string + - description: Organization ID + in: path + name: organization_id + required: true + type: string + - description: Ledger ID + in: path + name: ledger_id + required: true + type: string + - description: Balance ID + in: path + name: balance_id + required: true + type: string + - description: Balance Input + in: body + name: balance + required: true + schema: + $ref: '#/definitions/mmodel.UpdateBalance' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/mmodel.Balance' + summary: Update Balance + tags: + - Balances /v1/organizations/{organization_id}/ledgers/{ledger_id}/accounts/{account_id}/operations: get: description: Get all Operations with the input ID @@ -443,7 +763,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -473,7 +793,7 @@ paths: in: query name: end_date type: string - - description: Ledger ID + - description: Sort Order in: query name: sort_order type: string @@ -515,7 +835,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -560,7 +880,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -599,7 +919,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -637,7 +957,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -719,7 +1039,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -791,7 +1111,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -830,7 +1150,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -876,7 +1196,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -927,7 +1247,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -967,7 +1287,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path @@ -1007,7 +1327,7 @@ paths: type: string - description: Request ID in: header - name: Midaz-Id + name: X-Request-Id type: string - description: Organization ID in: path diff --git a/components/transaction/internal/adapters/http/in/assetrate.go b/components/transaction/internal/adapters/http/in/assetrate.go index 0f0f2bfa..5897ebd5 100644 --- a/components/transaction/internal/adapters/http/in/assetrate.go +++ b/components/transaction/internal/adapters/http/in/assetrate.go @@ -28,7 +28,7 @@ type AssetRateHandler struct { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param asset-rate body assetrate.CreateAssetRateInput true "AssetRate Input" @@ -80,7 +80,7 @@ func (handler *AssetRateHandler) CreateOrUpdateAssetRate(p any, c *fiber.Ctx) er // @Tags Asset Rates // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param external_id path string true "External ID" @@ -123,7 +123,7 @@ func (handler *AssetRateHandler) GetAssetRateByExternalID(c *fiber.Ctx) error { // @Tags Asset Rates // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param asset_code path string true "From Asset Code" diff --git a/components/transaction/internal/adapters/http/in/balance.go b/components/transaction/internal/adapters/http/in/balance.go new file mode 100644 index 00000000..1ea24ad5 --- /dev/null +++ b/components/transaction/internal/adapters/http/in/balance.go @@ -0,0 +1,319 @@ +package in + +import ( + "github.com/LerianStudio/midaz/pkg/mmodel" + "go.mongodb.org/mongo-driver/bson" + + "github.com/LerianStudio/midaz/components/transaction/internal/services/command" + "github.com/LerianStudio/midaz/components/transaction/internal/services/query" + "github.com/LerianStudio/midaz/pkg" + "github.com/LerianStudio/midaz/pkg/mopentelemetry" + "github.com/LerianStudio/midaz/pkg/mpostgres" + "github.com/LerianStudio/midaz/pkg/net/http" + + "github.com/gofiber/fiber/v2" + "github.com/google/uuid" +) + +// BalanceHandler struct contains a cqrs use case for managing balances. +type BalanceHandler struct { + Command *command.UseCase + Query *query.UseCase +} + +// GetAllBalances retrieves all balances. +// +// @Summary Get all balances +// @Description Get all balances +// @Tags Balances +// @Produce json +// @Param Authorization header string true "Authorization Bearer Token" +// @Param X-Request-Id header string false "Request ID" +// @Param organization_id path string true "Organization ID" +// @Param ledger_id path string true "Ledger ID" +// @Param limit query int false "Limit" default(10) +// @Param start_date query string false "Start Date" example "2021-01-01" +// @Param end_date query string false "End Date" example "2021-01-01" +// @Param sort_order query string false "Sort Order" enum(asc,desc) +// @Param cursor query string false "Cursor" +// @Success 200 {object} mpostgres.Pagination{items=[]mmodel.Balance, next_cursor=string, prev_cursor=string,limit=int} +// @Router /v1/organizations/:organization_id/ledgers/:ledger_id/balances [get] +func (handler *BalanceHandler) GetAllBalances(c *fiber.Ctx) error { + ctx := c.UserContext() + + logger := pkg.NewLoggerFromContext(ctx) + tracer := pkg.NewTracerFromContext(ctx) + + ctx, span := tracer.Start(ctx, "handler.get_all_balances") + defer span.End() + + organizationID := c.Locals("organization_id").(uuid.UUID) + ledgerID := c.Locals("ledger_id").(uuid.UUID) + + headerParams, err := http.ValidateParameters(c.Queries()) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to validate query parameters", err) + + logger.Errorf("Failed to validate query parameters, Error: %s", err.Error()) + + return http.WithError(c, err) + } + + pagination := mpostgres.Pagination{ + Limit: headerParams.Limit, + NextCursor: headerParams.Cursor, + SortOrder: headerParams.SortOrder, + StartDate: headerParams.StartDate, + EndDate: headerParams.EndDate, + } + + logger.Infof("Initiating retrieval of all Balances") + + headerParams.Metadata = &bson.M{} + + err = mopentelemetry.SetSpanAttributesFromStruct(&span, "headerParams", headerParams) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to convert headerParams to JSON string", err) + + return http.WithError(c, err) + } + + balances, cur, err := handler.Query.GetAllBalances(ctx, organizationID, ledgerID, *headerParams) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to retrieve all Balances", err) + + logger.Errorf("Failed to retrieve all Balances, Error: %s", err.Error()) + + return http.WithError(c, err) + } + + logger.Infof("Successfully retrieved all Balances") + + pagination.SetItems(balances) + pagination.SetCursor(cur.Next, cur.Prev) + + return http.OK(c, pagination) +} + +// GetAllBalancesByAccountID retrieves all balances. +// +// @Summary Get all balances by account id +// @Description Get all balances by account id +// @Tags Balances +// @Produce json +// @Param Authorization header string true "Authorization Bearer Token" +// @Param X-Request-Id header string false "Request ID" +// @Param organization_id path string true "Organization ID" +// @Param ledger_id path string true "Ledger ID" +// @Param account_id path string true "Account ID" +// @Param limit query int false "Limit" default(10) +// @Param start_date query string false "Start Date" example "2021-01-01" +// @Param end_date query string false "End Date" example "2021-01-01" +// @Param sort_order query string false "Sort Order" enum(asc,desc) +// @Param cursor query string false "Cursor" +// @Success 200 {object} mpostgres.Pagination{items=[]mmodel.Balance, next_cursor=string, prev_cursor=string,limit=int} +// @Router /v1/organizations/:organization_id/ledgers/:ledger_id/accounts/:account_id/balances [get] +func (handler *BalanceHandler) GetAllBalancesByAccountID(c *fiber.Ctx) error { + ctx := c.UserContext() + + logger := pkg.NewLoggerFromContext(ctx) + tracer := pkg.NewTracerFromContext(ctx) + + ctx, span := tracer.Start(ctx, "handler.get_all_balances_by_account_id") + defer span.End() + + organizationID := c.Locals("organization_id").(uuid.UUID) + ledgerID := c.Locals("ledger_id").(uuid.UUID) + accountID := c.Locals("account_id").(uuid.UUID) + + headerParams, err := http.ValidateParameters(c.Queries()) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to validate query parameters", err) + + logger.Errorf("Failed to validate query parameters, Error: %s", err.Error()) + + return http.WithError(c, err) + } + + pagination := mpostgres.Pagination{ + Limit: headerParams.Limit, + NextCursor: headerParams.Cursor, + SortOrder: headerParams.SortOrder, + StartDate: headerParams.StartDate, + EndDate: headerParams.EndDate, + } + + logger.Infof("Initiating retrieval of all Balances by account id") + + headerParams.Metadata = &bson.M{} + + err = mopentelemetry.SetSpanAttributesFromStruct(&span, "headerParams", headerParams) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to convert headerParams to JSON string", err) + + return http.WithError(c, err) + } + + balances, cur, err := handler.Query.GetAllBalancesByAccountID(ctx, organizationID, ledgerID, accountID, *headerParams) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to retrieve all Balances by account id", err) + + logger.Errorf("Failed to retrieve all Balances by account id, Error: %s", err.Error()) + + return http.WithError(c, err) + } + + logger.Infof("Successfully retrieved all Balances by account id") + + pagination.SetItems(balances) + pagination.SetCursor(cur.Next, cur.Prev) + + return http.OK(c, pagination) +} + +// GetBalanceByID retrieves a balance by ID. +// +// @Summary Get Balance by id +// @Description Get a Balance with the input ID +// @Tags Balances +// @Produce json +// @Param Authorization header string true "Authorization Bearer Token" +// @Param X-Request-Id header string false "Request ID" +// @Param organization_id path string true "Organization ID" +// @Param ledger_id path string true "Ledger ID" +// @Param balance_id path string true "Balance ID" +// @Success 200 {object} mmodel.Balance +// @Router /v1/organizations/:organization_id/ledgers/:ledger_id/balances/:balance_id [get] +func (handler *BalanceHandler) GetBalanceByID(c *fiber.Ctx) error { + ctx := c.UserContext() + + logger := pkg.NewLoggerFromContext(ctx) + tracer := pkg.NewTracerFromContext(ctx) + + ctx, span := tracer.Start(ctx, "handler.get_balance_by_id") + defer span.End() + + organizationID := c.Locals("organization_id").(uuid.UUID) + ledgerID := c.Locals("ledger_id").(uuid.UUID) + balanceID := c.Locals("balance_id").(uuid.UUID) + + logger.Infof("Initiating retrieval of balance by id") + + op, err := handler.Query.GetBalanceByID(ctx, organizationID, ledgerID, balanceID) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to retrieve balance by id", err) + + logger.Errorf("Failed to retrieve balance by id, Error: %s", err.Error()) + + return http.WithError(c, err) + } + + logger.Infof("Successfully retrieved balance by id") + + return http.OK(c, op) +} + +// DeleteBalanceByID delete a balance by ID. +// +// @Summary Delete Balance by account +// @Description Delete a Balance with the input ID +// @Tags Balances +// @Produce json +// @Param Authorization header string true "Authorization Bearer Token" +// @Param X-Request-Id header string false "Request ID" +// @Param organization_id path string true "Organization ID" +// @Param ledger_id path string true "Ledger ID" +// @Param balance_id path string true "Balance ID" +// @Success 200 {object} mmodel.Balance +// @Router /v1/organizations/:organization_id/ledgers/:ledger_id/balances/:balance_id [delete] +func (handler *BalanceHandler) DeleteBalanceByID(c *fiber.Ctx) error { + ctx := c.UserContext() + + logger := pkg.NewLoggerFromContext(ctx) + tracer := pkg.NewTracerFromContext(ctx) + + ctx, span := tracer.Start(ctx, "handler.delete_balance_by_id") + defer span.End() + + organizationID := c.Locals("organization_id").(uuid.UUID) + ledgerID := c.Locals("ledger_id").(uuid.UUID) + balanceID := c.Locals("balance_id").(uuid.UUID) + + logger.Infof("Initiating delete balance by id") + + err := handler.Command.DeleteBalance(ctx, organizationID, ledgerID, balanceID) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to delete balance by id", err) + + logger.Errorf("Failed to delete balance by id, Error: %s", err.Error()) + + return http.WithError(c, err) + } + + logger.Infof("Successfully delete balance by id") + + return http.NoContent(c) +} + +// UpdateBalance method that patch balance created before +// +// @Summary Update Balance +// @Description Update a Balance with the input payload +// @Tags Balances +// @Accept json +// @Produce json +// @Param Authorization header string true "Authorization Bearer Token" +// @Param X-Request-Id header string false "Request ID" +// @Param organization_id path string true "Organization ID" +// @Param ledger_id path string true "Ledger ID" +// @Param balance_id path string true "Balance ID" +// @Param balance body mmodel.UpdateBalance true "Balance Input" +// @Success 200 {object} mmodel.Balance +// @Router /v1/organizations/:organization_id/ledgers/:ledger_id/balances/:balance_id [patch] +func (handler *BalanceHandler) UpdateBalance(p any, c *fiber.Ctx) error { + ctx := c.UserContext() + + logger := pkg.NewLoggerFromContext(ctx) + tracer := pkg.NewTracerFromContext(ctx) + + ctx, span := tracer.Start(ctx, "handler.update_balance") + defer span.End() + + organizationID := c.Locals("organization_id").(uuid.UUID) + ledgerID := c.Locals("ledger_id").(uuid.UUID) + balanceID := c.Locals("balance_id").(uuid.UUID) + + logger.Infof("Initiating update of Balance with Organization ID: %s, Ledger ID: %s, and ID: %s", organizationID.String(), ledgerID.String(), balanceID.String()) + + payload := p.(*mmodel.UpdateBalance) + logger.Infof("Request to update a Balance with details: %#v", payload) + + err := mopentelemetry.SetSpanAttributesFromStruct(&span, "payload", payload) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to convert payload to JSON string", err) + + return http.WithError(c, err) + } + + err = handler.Command.Update(ctx, organizationID, ledgerID, balanceID, *payload) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to update Balance on command", err) + + logger.Errorf("Failed to update Balance with ID: %s, Error: %s", balanceID, err.Error()) + + return http.WithError(c, err) + } + + op, err := handler.Query.GetBalanceByID(ctx, organizationID, ledgerID, balanceID) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to retrieve Balance on query", err) + + logger.Errorf("Failed to retrieve Balance with ID: %s, Error: %s", balanceID, err.Error()) + + return http.WithError(c, err) + } + + logger.Infof("Successfully updated Balance with Organization ID: %s, Ledger ID: %s, and ID: %s", organizationID, ledgerID, balanceID) + + return http.OK(c, op) +} diff --git a/components/transaction/internal/adapters/http/in/operation.go b/components/transaction/internal/adapters/http/in/operation.go index d7b25c5c..dd725fa2 100644 --- a/components/transaction/internal/adapters/http/in/operation.go +++ b/components/transaction/internal/adapters/http/in/operation.go @@ -28,14 +28,14 @@ type OperationHandler struct { // @Tags Operations // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param account_id path string true "Account ID" // @Param limit query int false "Limit" default(10) // @Param start_date query string false "Start Date" example "2021-01-01" // @Param end_date query string false "End Date" example "2021-01-01" -// @Param sort_order query string false "Ledger ID" enum(asc,desc) +// @Param sort_order query string false "Sort Order" enum(asc,desc) // @Param cursor query string false "Cursor" // @Success 200 {object} mpostgres.Pagination{items=[]operation.Operation, next_cursor=string, prev_cursor=string,limit=int} // @Router /v1/organizations/{organization_id}/ledgers/{ledger_id}/accounts/{account_id}/operations [get] @@ -104,7 +104,7 @@ func (handler *OperationHandler) GetAllOperationsByAccount(c *fiber.Ctx) error { // @Tags Operations // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param account_id path string true "Account ID" @@ -149,7 +149,7 @@ func (handler *OperationHandler) GetOperationByAccount(c *fiber.Ctx) error { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param transaction_id path string true "Transaction ID" diff --git a/components/transaction/internal/adapters/http/in/routes.go b/components/transaction/internal/adapters/http/in/routes.go index eea03560..df585093 100644 --- a/components/transaction/internal/adapters/http/in/routes.go +++ b/components/transaction/internal/adapters/http/in/routes.go @@ -6,6 +6,7 @@ import ( "github.com/LerianStudio/midaz/components/transaction/internal/adapters/postgres/transaction" "github.com/LerianStudio/midaz/pkg/mcasdoor" "github.com/LerianStudio/midaz/pkg/mlog" + "github.com/LerianStudio/midaz/pkg/mmodel" "github.com/LerianStudio/midaz/pkg/mopentelemetry" "github.com/LerianStudio/midaz/pkg/net/http" @@ -14,7 +15,7 @@ import ( fiberSwagger "github.com/swaggo/fiber-swagger" ) -func NewRouter(lg mlog.Logger, tl *mopentelemetry.Telemetry, cc *mcasdoor.CasdoorConnection, th *TransactionHandler, oh *OperationHandler, ah *AssetRateHandler) *fiber.App { +func NewRouter(lg mlog.Logger, tl *mopentelemetry.Telemetry, cc *mcasdoor.CasdoorConnection, th *TransactionHandler, oh *OperationHandler, ah *AssetRateHandler, bh *BalanceHandler) *fiber.App { f := fiber.New(fiber.Config{ DisableStartupMessage: true, }) @@ -51,6 +52,13 @@ func NewRouter(lg mlog.Logger, tl *mopentelemetry.Telemetry, cc *mcasdoor.Casdoo f.Get("/v1/organizations/:organization_id/ledgers/:ledger_id/asset-rates/:external_id", jwt.ProtectHTTP(), jwt.WithPermissionHTTP("asset-rate"), http.ParseUUIDPathParameters, ah.GetAssetRateByExternalID) f.Get("/v1/organizations/:organization_id/ledgers/:ledger_id/asset-rates/from/:asset_code", jwt.ProtectHTTP(), jwt.WithPermissionHTTP("asset-rate"), http.ParseUUIDPathParameters, ah.GetAllAssetRatesByAssetCode) + //Balance + f.Get("/v1/organizations/:organization_id/ledgers/:ledger_id/balances", jwt.ProtectHTTP(), jwt.WithPermissionHTTP("balance"), http.ParseUUIDPathParameters, bh.GetAllBalances) + f.Get("/v1/organizations/:organization_id/ledgers/:ledger_id/balances/:balance_id", jwt.ProtectHTTP(), jwt.WithPermissionHTTP("balance"), http.ParseUUIDPathParameters, bh.GetBalanceByID) + f.Get("/v1/organizations/:organization_id/ledgers/:ledger_id/accounts/:account_id/balances", jwt.ProtectHTTP(), jwt.WithPermissionHTTP("balance"), http.ParseUUIDPathParameters, bh.GetAllBalancesByAccountID) + f.Delete("/v1/organizations/:organization_id/ledgers/:ledger_id/balances/:balance_id", jwt.ProtectHTTP(), jwt.WithPermissionHTTP("balance"), http.ParseUUIDPathParameters, bh.DeleteBalanceByID) + f.Patch("/v1/organizations/:organization_id/ledgers/:ledger_id/balances/:balance_id", jwt.ProtectHTTP(), jwt.WithPermissionHTTP("balance"), http.ParseUUIDPathParameters, http.WithBody(new(mmodel.UpdateBalance), bh.UpdateBalance)) + // Health f.Get("/health", http.Ping) diff --git a/components/transaction/internal/adapters/http/in/transaction.go b/components/transaction/internal/adapters/http/in/transaction.go index e3d1a973..d6ac2d89 100644 --- a/components/transaction/internal/adapters/http/in/transaction.go +++ b/components/transaction/internal/adapters/http/in/transaction.go @@ -35,7 +35,7 @@ type TransactionHandler struct { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param transaction body transaction.CreateTransactionInput true "Transaction Input" @@ -69,7 +69,7 @@ func (handler *TransactionHandler) CreateTransactionJSON(p any, c *fiber.Ctx) er // @Accept mpfd // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param transaction formData file true "Transaction DSL file" @@ -169,7 +169,7 @@ func (handler *TransactionHandler) CommitTransaction(c *fiber.Ctx) error { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param transaction_id path string true "Transaction ID" @@ -250,7 +250,7 @@ func (handler *TransactionHandler) RevertTransaction(c *fiber.Ctx) error { // @Accept json // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param transaction_id path string true "Transaction ID" @@ -305,7 +305,7 @@ func (handler *TransactionHandler) UpdateTransaction(p any, c *fiber.Ctx) error // @Tags Transactions // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param transaction_id path string true "Transaction ID" @@ -369,7 +369,7 @@ func (handler *TransactionHandler) GetTransaction(c *fiber.Ctx) error { // @Tags Transactions // @Produce json // @Param Authorization header string true "Authorization Bearer Token" -// @Param Midaz-Id header string false "Request ID" +// @Param X-Request-Id header string false "Request ID" // @Param organization_id path string true "Organization ID" // @Param ledger_id path string true "Ledger ID" // @Param limit query int false "Limit" default(10) diff --git a/components/transaction/internal/adapters/postgres/balance/balance.mock.go b/components/transaction/internal/adapters/postgres/balance/balance.mock.go index fec6b81d..75650f12 100644 --- a/components/transaction/internal/adapters/postgres/balance/balance.mock.go +++ b/components/transaction/internal/adapters/postgres/balance/balance.mock.go @@ -14,6 +14,7 @@ import ( reflect "reflect" mmodel "github.com/LerianStudio/midaz/pkg/mmodel" + http "github.com/LerianStudio/midaz/pkg/net/http" uuid "github.com/google/uuid" gomock "go.uber.org/mock/gomock" ) @@ -22,6 +23,7 @@ import ( type MockRepository struct { ctrl *gomock.Controller recorder *MockRepositoryMockRecorder + isgomock struct{} } // MockRepositoryMockRecorder is the mock recorder for MockRepository. @@ -42,59 +44,134 @@ func (m *MockRepository) EXPECT() *MockRepositoryMockRecorder { } // Create mocks base method. -func (m *MockRepository) Create(arg0 context.Context, arg1 *mmodel.Balance) error { +func (m *MockRepository) Create(ctx context.Context, balance *mmodel.Balance) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Create", arg0, arg1) + ret := m.ctrl.Call(m, "Create", ctx, balance) ret0, _ := ret[0].(error) return ret0 } // Create indicates an expected call of Create. -func (mr *MockRepositoryMockRecorder) Create(arg0, arg1 any) *gomock.Call { +func (mr *MockRepositoryMockRecorder) Create(ctx, balance any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockRepository)(nil).Create), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockRepository)(nil).Create), ctx, balance) +} + +// Delete mocks base method. +func (m *MockRepository) Delete(ctx context.Context, organizationID, ledgerID, id uuid.UUID) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", ctx, organizationID, ledgerID, id) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete. +func (mr *MockRepositoryMockRecorder) Delete(ctx, organizationID, ledgerID, id any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockRepository)(nil).Delete), ctx, organizationID, ledgerID, id) +} + +// Find mocks base method. +func (m *MockRepository) Find(ctx context.Context, organizationID, ledgerID, id uuid.UUID) (*mmodel.Balance, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Find", ctx, organizationID, ledgerID, id) + ret0, _ := ret[0].(*mmodel.Balance) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Find indicates an expected call of Find. +func (mr *MockRepositoryMockRecorder) Find(ctx, organizationID, ledgerID, id any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Find", reflect.TypeOf((*MockRepository)(nil).Find), ctx, organizationID, ledgerID, id) +} + +// ListAll mocks base method. +func (m *MockRepository) ListAll(ctx context.Context, organizationID, ledgerID uuid.UUID, filter http.Pagination) ([]*mmodel.Balance, http.CursorPagination, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListAll", ctx, organizationID, ledgerID, filter) + ret0, _ := ret[0].([]*mmodel.Balance) + ret1, _ := ret[1].(http.CursorPagination) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// ListAll indicates an expected call of ListAll. +func (mr *MockRepositoryMockRecorder) ListAll(ctx, organizationID, ledgerID, filter any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListAll", reflect.TypeOf((*MockRepository)(nil).ListAll), ctx, organizationID, ledgerID, filter) +} + +// ListAllByAccountID mocks base method. +func (m *MockRepository) ListAllByAccountID(ctx context.Context, organizationID, ledgerID, accountID uuid.UUID, filter http.Pagination) ([]*mmodel.Balance, http.CursorPagination, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListAllByAccountID", ctx, organizationID, ledgerID, accountID, filter) + ret0, _ := ret[0].([]*mmodel.Balance) + ret1, _ := ret[1].(http.CursorPagination) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// ListAllByAccountID indicates an expected call of ListAllByAccountID. +func (mr *MockRepositoryMockRecorder) ListAllByAccountID(ctx, organizationID, ledgerID, accountID, filter any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListAllByAccountID", reflect.TypeOf((*MockRepository)(nil).ListAllByAccountID), ctx, organizationID, ledgerID, accountID, filter) } // ListByAccountIDs mocks base method. -func (m *MockRepository) ListByAccountIDs(arg0 context.Context, arg1, arg2 uuid.UUID, arg3 []uuid.UUID) ([]*mmodel.Balance, error) { +func (m *MockRepository) ListByAccountIDs(ctx context.Context, organizationID, ledgerID uuid.UUID, ids []uuid.UUID) ([]*mmodel.Balance, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListByAccountIDs", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "ListByAccountIDs", ctx, organizationID, ledgerID, ids) ret0, _ := ret[0].([]*mmodel.Balance) ret1, _ := ret[1].(error) return ret0, ret1 } // ListByAccountIDs indicates an expected call of ListByAccountIDs. -func (mr *MockRepositoryMockRecorder) ListByAccountIDs(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockRepositoryMockRecorder) ListByAccountIDs(ctx, organizationID, ledgerID, ids any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListByAccountIDs", reflect.TypeOf((*MockRepository)(nil).ListByAccountIDs), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListByAccountIDs", reflect.TypeOf((*MockRepository)(nil).ListByAccountIDs), ctx, organizationID, ledgerID, ids) } // ListByAliases mocks base method. -func (m *MockRepository) ListByAliases(arg0 context.Context, arg1, arg2 uuid.UUID, arg3 []string) ([]*mmodel.Balance, error) { +func (m *MockRepository) ListByAliases(ctx context.Context, organizationID, ledgerID uuid.UUID, aliases []string) ([]*mmodel.Balance, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListByAliases", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "ListByAliases", ctx, organizationID, ledgerID, aliases) ret0, _ := ret[0].([]*mmodel.Balance) ret1, _ := ret[1].(error) return ret0, ret1 } // ListByAliases indicates an expected call of ListByAliases. -func (mr *MockRepositoryMockRecorder) ListByAliases(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockRepositoryMockRecorder) ListByAliases(ctx, organizationID, ledgerID, aliases any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListByAliases", reflect.TypeOf((*MockRepository)(nil).ListByAliases), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListByAliases", reflect.TypeOf((*MockRepository)(nil).ListByAliases), ctx, organizationID, ledgerID, aliases) } // SelectForUpdate mocks base method. -func (m *MockRepository) SelectForUpdate(arg0 context.Context, arg1, arg2 uuid.UUID, arg3 []*mmodel.Balance) error { +func (m *MockRepository) SelectForUpdate(ctx context.Context, organizationID, ledgerID uuid.UUID, balances []*mmodel.Balance) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SelectForUpdate", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "SelectForUpdate", ctx, organizationID, ledgerID, balances) ret0, _ := ret[0].(error) return ret0 } // SelectForUpdate indicates an expected call of SelectForUpdate. -func (mr *MockRepositoryMockRecorder) SelectForUpdate(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockRepositoryMockRecorder) SelectForUpdate(ctx, organizationID, ledgerID, balances any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectForUpdate", reflect.TypeOf((*MockRepository)(nil).SelectForUpdate), ctx, organizationID, ledgerID, balances) +} + +// Update mocks base method. +func (m *MockRepository) Update(ctx context.Context, organizationID, ledgerID, id uuid.UUID, balance mmodel.UpdateBalance) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", ctx, organizationID, ledgerID, id, balance) + ret0, _ := ret[0].(error) + return ret0 +} + +// Update indicates an expected call of Update. +func (mr *MockRepositoryMockRecorder) Update(ctx, organizationID, ledgerID, id, balance any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectForUpdate", reflect.TypeOf((*MockRepository)(nil).SelectForUpdate), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockRepository)(nil).Update), ctx, organizationID, ledgerID, id, balance) } diff --git a/components/transaction/internal/adapters/postgres/balance/balance.postgresql.go b/components/transaction/internal/adapters/postgres/balance/balance.postgresql.go index df1741f9..9d1c62ef 100644 --- a/components/transaction/internal/adapters/postgres/balance/balance.postgresql.go +++ b/components/transaction/internal/adapters/postgres/balance/balance.postgresql.go @@ -8,7 +8,10 @@ import ( "github.com/LerianStudio/midaz/pkg/constant" "github.com/LerianStudio/midaz/pkg/mmodel" "github.com/LerianStudio/midaz/pkg/mopentelemetry" + "github.com/LerianStudio/midaz/pkg/mpointers" "github.com/LerianStudio/midaz/pkg/mpostgres" + "github.com/LerianStudio/midaz/pkg/net/http" + "github.com/Masterminds/squirrel" "github.com/google/uuid" "github.com/lib/pq" "reflect" @@ -22,9 +25,14 @@ import ( //go:generate mockgen --destination=balance.mock.go --package=balance . Repository type Repository interface { Create(ctx context.Context, balance *mmodel.Balance) error + Find(ctx context.Context, organizationID, ledgerID, id uuid.UUID) (*mmodel.Balance, error) + ListAll(ctx context.Context, organizationID, ledgerID uuid.UUID, filter http.Pagination) ([]*mmodel.Balance, http.CursorPagination, error) + ListAllByAccountID(ctx context.Context, organizationID, ledgerID, accountID uuid.UUID, filter http.Pagination) ([]*mmodel.Balance, http.CursorPagination, error) ListByAccountIDs(ctx context.Context, organizationID, ledgerID uuid.UUID, ids []uuid.UUID) ([]*mmodel.Balance, error) ListByAliases(ctx context.Context, organizationID, ledgerID uuid.UUID, aliases []string) ([]*mmodel.Balance, error) SelectForUpdate(ctx context.Context, organizationID, ledgerID uuid.UUID, balances []*mmodel.Balance) error + Update(ctx context.Context, organizationID, ledgerID, id uuid.UUID, balance mmodel.UpdateBalance) error + Delete(ctx context.Context, organizationID, ledgerID, id uuid.UUID) error } // BalancePostgreSQLRepository is a Postgresql-specific implementation of the BalanceRepository. @@ -186,6 +194,227 @@ func (r *BalancePostgreSQLRepository) ListByAccountIDs(ctx context.Context, orga return balances, nil } +// ListAll list Balances entity from the database. +func (r *BalancePostgreSQLRepository) ListAll(ctx context.Context, organizationID, ledgerID uuid.UUID, filter http.Pagination) ([]*mmodel.Balance, http.CursorPagination, error) { + tracer := pkg.NewTracerFromContext(ctx) + + ctx, span := tracer.Start(ctx, "postgres.list_all_balances") + defer span.End() + + db, err := r.connection.GetDB() + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to get database connection", err) + + return nil, http.CursorPagination{}, err + } + + balances := make([]*mmodel.Balance, 0) + + decodedCursor := http.Cursor{} + isFirstPage := pkg.IsNilOrEmpty(&filter.Cursor) + orderDirection := strings.ToUpper(filter.SortOrder) + + if !isFirstPage { + decodedCursor, err = http.DecodeCursor(filter.Cursor) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to decode cursor", err) + + return nil, http.CursorPagination{}, err + } + } + + findAll := squirrel.Select("*"). + From(r.tableName). + Where(squirrel.Expr("organization_id = ?", organizationID)). + Where(squirrel.Expr("ledger_id = ?", ledgerID)). + Where(squirrel.Eq{"deleted_at": nil}). + Where(squirrel.GtOrEq{"created_at": pkg.NormalizeDate(filter.StartDate, mpointers.Int(-1))}). + Where(squirrel.LtOrEq{"created_at": pkg.NormalizeDate(filter.EndDate, mpointers.Int(1))}). + PlaceholderFormat(squirrel.Dollar) + + findAll, orderDirection = http.ApplyCursorPagination(findAll, decodedCursor, orderDirection, filter.Limit) + + query, args, err := findAll.ToSql() + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to build query", err) + + return nil, http.CursorPagination{}, err + } + + ctx, spanQuery := tracer.Start(ctx, "postgres.list_all.query") + + rows, err := db.QueryContext(ctx, query, args...) + if err != nil { + mopentelemetry.HandleSpanError(&spanQuery, "Failed to get operations on repo", err) + + return nil, http.CursorPagination{}, err + } + defer rows.Close() + + spanQuery.End() + + for rows.Next() { + var balance BalancePostgreSQLModel + if err = rows.Scan( + &balance.ID, + &balance.OrganizationID, + &balance.LedgerID, + &balance.AccountID, + &balance.Alias, + &balance.AssetCode, + &balance.Available, + &balance.OnHold, + &balance.Scale, + &balance.Version, + &balance.AccountType, + &balance.AllowSending, + &balance.AllowReceiving, + &balance.CreatedAt, + &balance.UpdatedAt, + &balance.DeletedAt, + ); err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to scan row", err) + + return nil, http.CursorPagination{}, err + } + + balances = append(balances, balance.ToEntity()) + } + + if err = rows.Err(); err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to iterate rows", err) + + return nil, http.CursorPagination{}, err + } + + hasPagination := len(balances) > filter.Limit + + balances = http.PaginateRecords(isFirstPage, hasPagination, decodedCursor.PointsNext, balances, filter.Limit, orderDirection) + + cur := http.CursorPagination{} + if len(balances) > 0 { + cur, err = http.CalculateCursor(isFirstPage, hasPagination, decodedCursor.PointsNext, balances[0].ID, balances[len(balances)-1].ID) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to calculate cursor", err) + + return nil, http.CursorPagination{}, err + } + } + + return balances, cur, nil +} + +// ListAllByAccountID list Balances entity from the database using the provided accountID. +func (r *BalancePostgreSQLRepository) ListAllByAccountID(ctx context.Context, organizationID, ledgerID, accountID uuid.UUID, filter http.Pagination) ([]*mmodel.Balance, http.CursorPagination, error) { + tracer := pkg.NewTracerFromContext(ctx) + + ctx, span := tracer.Start(ctx, "postgres.list_all_balances_by_account_id") + defer span.End() + + db, err := r.connection.GetDB() + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to get database connection", err) + + return nil, http.CursorPagination{}, err + } + + balances := make([]*mmodel.Balance, 0) + + decodedCursor := http.Cursor{} + isFirstPage := pkg.IsNilOrEmpty(&filter.Cursor) + orderDirection := strings.ToUpper(filter.SortOrder) + + if !isFirstPage { + decodedCursor, err = http.DecodeCursor(filter.Cursor) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to decode cursor", err) + + return nil, http.CursorPagination{}, err + } + } + + findAll := squirrel.Select("*"). + From(r.tableName). + Where(squirrel.Expr("organization_id = ?", organizationID)). + Where(squirrel.Expr("ledger_id = ?", ledgerID)). + Where(squirrel.Expr("account_id = ?", accountID)). + Where(squirrel.Eq{"deleted_at": nil}). + Where(squirrel.GtOrEq{"created_at": pkg.NormalizeDate(filter.StartDate, mpointers.Int(-1))}). + Where(squirrel.LtOrEq{"created_at": pkg.NormalizeDate(filter.EndDate, mpointers.Int(1))}). + PlaceholderFormat(squirrel.Dollar) + + findAll, orderDirection = http.ApplyCursorPagination(findAll, decodedCursor, orderDirection, filter.Limit) + + query, args, err := findAll.ToSql() + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to build query", err) + + return nil, http.CursorPagination{}, err + } + + ctx, spanQuery := tracer.Start(ctx, "postgres.list_all_by_account_id.query") + + rows, err := db.QueryContext(ctx, query, args...) + if err != nil { + mopentelemetry.HandleSpanError(&spanQuery, "Failed to get operations on repo", err) + + return nil, http.CursorPagination{}, err + } + defer rows.Close() + + spanQuery.End() + + for rows.Next() { + var balance BalancePostgreSQLModel + if err = rows.Scan( + &balance.ID, + &balance.OrganizationID, + &balance.LedgerID, + &balance.AccountID, + &balance.Alias, + &balance.AssetCode, + &balance.Available, + &balance.OnHold, + &balance.Scale, + &balance.Version, + &balance.AccountType, + &balance.AllowSending, + &balance.AllowReceiving, + &balance.CreatedAt, + &balance.UpdatedAt, + &balance.DeletedAt, + ); err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to scan row", err) + + return nil, http.CursorPagination{}, err + } + + balances = append(balances, balance.ToEntity()) + } + + if err = rows.Err(); err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to iterate rows", err) + + return nil, http.CursorPagination{}, err + } + + hasPagination := len(balances) > filter.Limit + + balances = http.PaginateRecords(isFirstPage, hasPagination, decodedCursor.PointsNext, balances, filter.Limit, orderDirection) + + cur := http.CursorPagination{} + if len(balances) > 0 { + cur, err = http.CalculateCursor(isFirstPage, hasPagination, decodedCursor.PointsNext, balances[0].ID, balances[len(balances)-1].ID) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to calculate cursor", err) + + return nil, http.CursorPagination{}, err + } + } + + return balances, cur, nil +} + // ListByAliases list Balances entity from the database using the provided aliases. func (r *BalancePostgreSQLRepository) ListByAliases(ctx context.Context, organizationID, ledgerID uuid.UUID, aliases []string) ([]*mmodel.Balance, error) { tracer := pkg.NewTracerFromContext(ctx) @@ -371,3 +600,169 @@ func (r *BalancePostgreSQLRepository) SelectForUpdate(ctx context.Context, organ return nil } + +// Find retrieves a balance entity from the database using the provided ID. +func (r *BalancePostgreSQLRepository) Find(ctx context.Context, organizationID, ledgerID, id uuid.UUID) (*mmodel.Balance, error) { + tracer := pkg.NewTracerFromContext(ctx) + + ctx, span := tracer.Start(ctx, "postgres.find_balance") + defer span.End() + + db, err := r.connection.GetDB() + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to get database connection", err) + + return nil, err + } + + balance := &BalancePostgreSQLModel{} + + ctx, spanQuery := tracer.Start(ctx, "postgres.find.query") + + row := db.QueryRowContext(ctx, "SELECT * FROM balance WHERE organization_id = $1 AND ledger_id = $2 AND id = $3 AND deleted_at IS NULL", + organizationID, ledgerID, id) + + spanQuery.End() + + if err = row.Scan( + &balance.ID, + &balance.OrganizationID, + &balance.LedgerID, + &balance.AccountID, + &balance.Alias, + &balance.AssetCode, + &balance.Available, + &balance.OnHold, + &balance.Scale, + &balance.Version, + &balance.AccountType, + &balance.AllowSending, + &balance.AllowReceiving, + &balance.CreatedAt, + &balance.UpdatedAt, + &balance.DeletedAt, + ); err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to scan row", err) + + if errors.Is(err, sql.ErrNoRows) { + return nil, pkg.ValidateBusinessError(constant.ErrEntityNotFound, reflect.TypeOf(mmodel.Balance{}).Name()) + } + + return nil, err + } + + return balance.ToEntity(), nil +} + +// Delete marks a balance as deleted in the database using the ID provided +func (r *BalancePostgreSQLRepository) Delete(ctx context.Context, organizationID, ledgerID, id uuid.UUID) error { + tracer := pkg.NewTracerFromContext(ctx) + + ctx, span := tracer.Start(ctx, "postgres.delete_balance") + defer span.End() + + db, err := r.connection.GetDB() + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to get database connection", err) + + return err + } + + ctx, spanQuery := tracer.Start(ctx, "postgres.delete.exec") + + result, err := db.ExecContext(ctx, ` + UPDATE balance + SET deleted_at = NOW() + WHERE organization_id = $1 AND ledger_id = $2 AND id = $3 AND deleted_at IS NULL`, + organizationID, ledgerID, id, + ) + if err != nil { + mopentelemetry.HandleSpanError(&span, "failed to execute delete query", err) + return err + } + + spanQuery.End() + + rowsAffected, err := result.RowsAffected() + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to get rows affected", err) + + return err + } + + if rowsAffected == 0 { + err = pkg.ValidateBusinessError(constant.ErrEntityNotFound, reflect.TypeOf(mmodel.Balance{}).Name()) + + mopentelemetry.HandleSpanError(&span, "Failed to delete balance. Rows affected is 0", err) + + return err + } + + return nil +} + +// Update updates the allow_sending and allow_receiving fields of a Balance in the database. +func (r *BalancePostgreSQLRepository) Update(ctx context.Context, organizationID, ledgerID, id uuid.UUID, balance mmodel.UpdateBalance) error { + tracer := pkg.NewTracerFromContext(ctx) + logger := pkg.NewLoggerFromContext(ctx) + + ctx, span := tracer.Start(ctx, "postgres.update_balance") + defer span.End() + + db, err := r.connection.GetDB() + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to get database connection", err) + + return err + } + + ctx, spanQuery := tracer.Start(ctx, "postgres.update.exec") + defer spanQuery.End() + + var updates []string + + var args []any + + if balance.AllowSending != nil { + updates = append(updates, "allow_sending = $"+strconv.Itoa(len(args)+1)) + args = append(args, balance.AllowSending) + } + + if balance.AllowReceiving != nil { + updates = append(updates, "allow_receiving = $"+strconv.Itoa(len(args)+1)) + args = append(args, balance.AllowReceiving) + } + + updates = append(updates, "updated_at = $"+strconv.Itoa(len(args)+1)) + args = append(args, time.Now(), organizationID, ledgerID, id) + + queryUpdate := `UPDATE balance SET ` + strings.Join(updates, ", ") + + ` WHERE organization_id = $` + strconv.Itoa(len(args)-2) + + ` AND ledger_id = $` + strconv.Itoa(len(args)-1) + + ` AND id = $` + strconv.Itoa(len(args)) + + ` AND deleted_at IS NULL` + + result, err := db.ExecContext(ctx, queryUpdate, args...) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Err on result exec content", err) + + logger.Errorf("Err on result exec content: %v", err) + + return err + } + + rowsAffected, err := result.RowsAffected() + if err != nil || rowsAffected == 0 { + if err == nil { + err = sql.ErrNoRows + } + + mopentelemetry.HandleSpanError(&span, "Err on rows affected", err) + + logger.Errorf("Err on rows affected: %v", err) + + return err + } + + return nil +} diff --git a/components/transaction/internal/bootstrap/config.go b/components/transaction/internal/bootstrap/config.go index 909e8068..93299be3 100644 --- a/components/transaction/internal/bootstrap/config.go +++ b/components/transaction/internal/bootstrap/config.go @@ -193,9 +193,14 @@ func InitServers() *Service { Query: queryUseCase, } + balanceHandler := &in.BalanceHandler{ + Command: useCase, + Query: queryUseCase, + } + multiQueueConsumer := NewMultiQueueConsumer(routes, useCase) - app := in.NewRouter(logger, telemetry, casDoorConnection, transactionHandler, operationHandler, assetRateHandler) + app := in.NewRouter(logger, telemetry, casDoorConnection, transactionHandler, operationHandler, assetRateHandler, balanceHandler) server := NewServer(cfg, app, logger, telemetry) @@ -204,4 +209,4 @@ func InitServers() *Service { MultiQueueConsumer: multiQueueConsumer, Logger: logger, } -} +} \ No newline at end of file diff --git a/components/transaction/internal/services/command/delete_balance.go b/components/transaction/internal/services/command/delete_balance.go new file mode 100644 index 00000000..b988d04f --- /dev/null +++ b/components/transaction/internal/services/command/delete_balance.go @@ -0,0 +1,30 @@ +package command + +import ( + "context" + "github.com/LerianStudio/midaz/pkg" + "github.com/LerianStudio/midaz/pkg/mopentelemetry" + "github.com/google/uuid" +) + +// DeleteBalance delete balance in the repository. +func (uc *UseCase) DeleteBalance(ctx context.Context, organizationID, ledgerID, balanceID uuid.UUID) error { + logger := pkg.NewLoggerFromContext(ctx) + tracer := pkg.NewTracerFromContext(ctx) + + ctx, span := tracer.Start(ctx, "exec.delete_balance") + defer span.End() + + logger.Infof("Trying to delete balance") + + err := uc.BalanceRepo.Delete(ctx, organizationID, ledgerID, balanceID) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to delete balance on repo", err) + + logger.Errorf("Error delete balance: %v", err) + + return err + } + + return nil +} diff --git a/components/transaction/internal/services/command/delete_balance_test.go b/components/transaction/internal/services/command/delete_balance_test.go new file mode 100644 index 00000000..487dc7ec --- /dev/null +++ b/components/transaction/internal/services/command/delete_balance_test.go @@ -0,0 +1,52 @@ +package command + +import ( + "context" + "errors" + "github.com/LerianStudio/midaz/components/transaction/internal/adapters/postgres/balance" + "github.com/LerianStudio/midaz/pkg" + "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" + "testing" +) + +// TestDeleteBalanceSuccess is responsible to test DeleteBalanceSuccess with success +func TestDeleteBalanceSuccess(t *testing.T) { + organizationID := pkg.GenerateUUIDv7() + ledgerID := pkg.GenerateUUIDv7() + balanceID := pkg.GenerateUUIDv7() + + uc := UseCase{ + BalanceRepo: balance.NewMockRepository(gomock.NewController(t)), + } + + uc.BalanceRepo.(*balance.MockRepository). + EXPECT(). + Delete(gomock.Any(), organizationID, ledgerID, balanceID). + Return(nil). + Times(1) + err := uc.BalanceRepo.Delete(context.TODO(), organizationID, ledgerID, balanceID) + + assert.Nil(t, err) +} + +// TestDeleteBalanceError is responsible to test DeleteBalanceError with error +func TestDeleteBalanceError(t *testing.T) { + errMSG := "errDatabaseItemNotFound" + organizationID := pkg.GenerateUUIDv7() + ledgerID := pkg.GenerateUUIDv7() + balanceID := pkg.GenerateUUIDv7() + + uc := UseCase{ + BalanceRepo: balance.NewMockRepository(gomock.NewController(t)), + } + + uc.BalanceRepo.(*balance.MockRepository). + EXPECT(). + Delete(gomock.Any(), organizationID, ledgerID, balanceID). + Return(errors.New(errMSG)) + err := uc.BalanceRepo.Delete(context.TODO(), organizationID, ledgerID, balanceID) + + assert.NotEmpty(t, err) + assert.Equal(t, err.Error(), errMSG) +} diff --git a/components/transaction/internal/services/command/update-balance.go b/components/transaction/internal/services/command/update-balance.go index 61cbf5a1..dac0e714 100644 --- a/components/transaction/internal/services/command/update-balance.go +++ b/components/transaction/internal/services/command/update-balance.go @@ -2,6 +2,7 @@ package command import ( "context" + "github.com/LerianStudio/midaz/pkg" "github.com/LerianStudio/midaz/pkg/constant" goldModel "github.com/LerianStudio/midaz/pkg/gold/transaction/model" "github.com/LerianStudio/midaz/pkg/mlog" @@ -44,3 +45,25 @@ func (uc *UseCase) UpdateBalances(ctx context.Context, logger mlog.Logger, organ return nil } + +// Update balance in the repository. +func (uc *UseCase) Update(ctx context.Context, organizationID, ledgerID, balanceID uuid.UUID, update mmodel.UpdateBalance) error { + logger := pkg.NewLoggerFromContext(ctx) + tracer := pkg.NewTracerFromContext(ctx) + + ctx, span := tracer.Start(ctx, "exec.update_balance") + defer span.End() + + logger.Infof("Trying to update balance") + + err := uc.BalanceRepo.Update(ctx, organizationID, ledgerID, balanceID, update) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to update balance on repo", err) + + logger.Errorf("Error update balance: %v", err) + + return err + } + + return nil +} diff --git a/components/transaction/internal/services/command/update-balance_test.go b/components/transaction/internal/services/command/update-balance_test.go new file mode 100644 index 00000000..86727ac6 --- /dev/null +++ b/components/transaction/internal/services/command/update-balance_test.go @@ -0,0 +1,69 @@ +package command + +import ( + "context" + "errors" + "github.com/LerianStudio/midaz/components/transaction/internal/adapters/postgres/balance" + "github.com/LerianStudio/midaz/pkg" + "github.com/LerianStudio/midaz/pkg/mmodel" + "go.uber.org/mock/gomock" + "testing" + + "github.com/stretchr/testify/assert" +) + +// TestUpdateBalanceSuccess is responsible to test UpdateBalanceSuccess with success +func TestUpdateBalanceSuccess(t *testing.T) { + organizationID := pkg.GenerateUUIDv7() + ledgerID := pkg.GenerateUUIDv7() + balanceID := pkg.GenerateUUIDv7() + + allowSending := false + + balanceUpdate := mmodel.UpdateBalance{ + AllowSending: &allowSending, + AllowReceiving: nil, + } + + uc := UseCase{ + BalanceRepo: balance.NewMockRepository(gomock.NewController(t)), + } + + uc.BalanceRepo.(*balance.MockRepository). + EXPECT(). + Update(gomock.Any(), organizationID, ledgerID, balanceID, balanceUpdate). + Return(nil). + Times(1) + err := uc.BalanceRepo.Update(context.TODO(), organizationID, ledgerID, balanceID, balanceUpdate) + + assert.Nil(t, err) +} + +// TestUpdateBalanceError is responsible to test UpdateBalanceError with error +func TestUpdateBalanceError(t *testing.T) { + errMSG := "errDatabaseItemNotFound" + organizationID := pkg.GenerateUUIDv7() + ledgerID := pkg.GenerateUUIDv7() + balanceID := pkg.GenerateUUIDv7() + + allowSending := true + allowReceiving := false + + balanceUpdate := mmodel.UpdateBalance{ + AllowSending: &allowSending, + AllowReceiving: &allowReceiving, + } + + uc := UseCase{ + BalanceRepo: balance.NewMockRepository(gomock.NewController(t)), + } + + uc.BalanceRepo.(*balance.MockRepository). + EXPECT(). + Update(gomock.Any(), organizationID, ledgerID, balanceID, balanceUpdate). + Return(errors.New(errMSG)) + err := uc.BalanceRepo.Update(context.TODO(), organizationID, ledgerID, balanceID, balanceUpdate) + + assert.NotEmpty(t, err) + assert.Equal(t, err.Error(), errMSG) +} diff --git a/components/transaction/internal/services/query/get-all-balances-account.go b/components/transaction/internal/services/query/get-all-balances-account.go new file mode 100644 index 00000000..dfaf0920 --- /dev/null +++ b/components/transaction/internal/services/query/get-all-balances-account.go @@ -0,0 +1,63 @@ +package query + +import ( + "context" + "errors" + "github.com/LerianStudio/midaz/pkg/mmodel" + "reflect" + + "github.com/LerianStudio/midaz/components/transaction/internal/adapters/postgres/operation" + "github.com/LerianStudio/midaz/components/transaction/internal/services" + "github.com/LerianStudio/midaz/pkg" + "github.com/LerianStudio/midaz/pkg/constant" + "github.com/LerianStudio/midaz/pkg/mopentelemetry" + "github.com/LerianStudio/midaz/pkg/net/http" + + "github.com/google/uuid" +) + +func (uc *UseCase) GetAllBalancesByAccountID(ctx context.Context, organizationID, ledgerID, accountID uuid.UUID, filter http.QueryHeader) ([]*mmodel.Balance, http.CursorPagination, error) { + logger := pkg.NewLoggerFromContext(ctx) + tracer := pkg.NewTracerFromContext(ctx) + + ctx, span := tracer.Start(ctx, "query.get_all_balances_by_account_id") + defer span.End() + + logger.Infof("Retrieving all balances by account") + + balance, cur, err := uc.BalanceRepo.ListAllByAccountID(ctx, organizationID, ledgerID, accountID, filter.ToCursorPagination()) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to get balances on repo", err) + + logger.Errorf("Error getting balances on repo: %v", err) + + if errors.Is(err, services.ErrDatabaseItemNotFound) { + return nil, http.CursorPagination{}, pkg.ValidateBusinessError(constant.ErrNoBalancesFound, reflect.TypeOf(mmodel.Balance{}).Name()) + } + + return nil, http.CursorPagination{}, err + } + + if balance != nil { + metadata, err := uc.MetadataRepo.FindList(ctx, reflect.TypeOf(mmodel.Balance{}).Name(), filter) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to get metadata on mongodb operation", err) + + return nil, http.CursorPagination{}, pkg.ValidateBusinessError(constant.ErrNoOperationsFound, reflect.TypeOf(operation.Operation{}).Name()) + } + + metadataMap := make(map[string]map[string]any, len(metadata)) + + for _, meta := range metadata { + metadataMap[meta.EntityID] = meta.Data + } + + for i := range balance { + if data, ok := metadataMap[balance[i].ID]; ok { + balance[i].Metadata = data + } + } + } + + return balance, cur, nil +} diff --git a/components/transaction/internal/services/query/get-all-balances-account_test.go b/components/transaction/internal/services/query/get-all-balances-account_test.go new file mode 100644 index 00000000..7305aab6 --- /dev/null +++ b/components/transaction/internal/services/query/get-all-balances-account_test.go @@ -0,0 +1,69 @@ +package query + +import ( + "context" + "errors" + "github.com/LerianStudio/midaz/components/transaction/internal/adapters/postgres/balance" + "github.com/LerianStudio/midaz/pkg" + "github.com/LerianStudio/midaz/pkg/mmodel" + "github.com/LerianStudio/midaz/pkg/net/http" + "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" + "testing" + "time" +) + +// TestGetAllBalancesByAccountID is responsible to test GetAllBalancesByAccountID with success and error +func TestGetAllBalancesByAccountID(t *testing.T) { + organizationID := pkg.GenerateUUIDv7() + ledgerID := pkg.GenerateUUIDv7() + filter := http.QueryHeader{ + Limit: 10, + Page: 1, + SortOrder: "asc", + StartDate: time.Now().AddDate(0, -1, 0), + EndDate: time.Now(), + ToAssetCodes: []string{"BRL"}, + } + mockCur := http.CursorPagination{ + Next: "next", + Prev: "prev", + } + + t.Parallel() + ctrl := gomock.NewController(t) + defer ctrl.Finish() + mockBalanceRepo := balance.NewMockRepository(ctrl) + + uc := UseCase{ + BalanceRepo: mockBalanceRepo, + } + + t.Run("Success", func(t *testing.T) { + trans := []*mmodel.Balance{{}} + mockBalanceRepo. + EXPECT(). + ListAll(gomock.Any(), organizationID, ledgerID, filter.ToCursorPagination()). + Return(trans, mockCur, nil). + Times(1) + res, cur, err := uc.BalanceRepo.ListAll(context.TODO(), organizationID, ledgerID, filter.ToCursorPagination()) + + assert.NoError(t, err) + assert.Len(t, res, 1) + assert.NotNil(t, cur) + }) + + t.Run("Error", func(t *testing.T) { + errMsg := "errDatabaseItemNotFound" + mockBalanceRepo. + EXPECT(). + ListAll(gomock.Any(), organizationID, ledgerID, filter.ToCursorPagination()). + Return(nil, http.CursorPagination{}, errors.New(errMsg)). + Times(1) + res, cur, err := uc.BalanceRepo.ListAll(context.TODO(), organizationID, ledgerID, filter.ToCursorPagination()) + + assert.EqualError(t, err, errMsg) + assert.Nil(t, res) + assert.Equal(t, cur, http.CursorPagination{}) + }) +} diff --git a/components/transaction/internal/services/query/get-all-balances.go b/components/transaction/internal/services/query/get-all-balances.go new file mode 100644 index 00000000..7d76211d --- /dev/null +++ b/components/transaction/internal/services/query/get-all-balances.go @@ -0,0 +1,63 @@ +package query + +import ( + "context" + "errors" + "github.com/LerianStudio/midaz/pkg/mmodel" + "reflect" + + "github.com/LerianStudio/midaz/components/transaction/internal/adapters/postgres/operation" + "github.com/LerianStudio/midaz/components/transaction/internal/services" + "github.com/LerianStudio/midaz/pkg" + "github.com/LerianStudio/midaz/pkg/constant" + "github.com/LerianStudio/midaz/pkg/mopentelemetry" + "github.com/LerianStudio/midaz/pkg/net/http" + + "github.com/google/uuid" +) + +func (uc *UseCase) GetAllBalances(ctx context.Context, organizationID, ledgerID uuid.UUID, filter http.QueryHeader) ([]*mmodel.Balance, http.CursorPagination, error) { + logger := pkg.NewLoggerFromContext(ctx) + tracer := pkg.NewTracerFromContext(ctx) + + ctx, span := tracer.Start(ctx, "query.get_all_balances") + defer span.End() + + logger.Infof("Retrieving all balances") + + balance, cur, err := uc.BalanceRepo.ListAll(ctx, organizationID, ledgerID, filter.ToCursorPagination()) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to get balances on repo", err) + + logger.Errorf("Error getting balances on repo: %v", err) + + if errors.Is(err, services.ErrDatabaseItemNotFound) { + return nil, http.CursorPagination{}, pkg.ValidateBusinessError(constant.ErrNoBalancesFound, reflect.TypeOf(mmodel.Balance{}).Name()) + } + + return nil, http.CursorPagination{}, err + } + + if balance != nil { + metadata, err := uc.MetadataRepo.FindList(ctx, reflect.TypeOf(mmodel.Balance{}).Name(), filter) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to get metadata on mongodb operation", err) + + return nil, http.CursorPagination{}, pkg.ValidateBusinessError(constant.ErrNoOperationsFound, reflect.TypeOf(operation.Operation{}).Name()) + } + + metadataMap := make(map[string]map[string]any, len(metadata)) + + for _, meta := range metadata { + metadataMap[meta.EntityID] = meta.Data + } + + for i := range balance { + if data, ok := metadataMap[balance[i].ID]; ok { + balance[i].Metadata = data + } + } + } + + return balance, cur, nil +} diff --git a/components/transaction/internal/services/query/get-all-balances_test.go b/components/transaction/internal/services/query/get-all-balances_test.go new file mode 100644 index 00000000..c4ef323b --- /dev/null +++ b/components/transaction/internal/services/query/get-all-balances_test.go @@ -0,0 +1,71 @@ +package query + +import ( + "context" + "errors" + "github.com/LerianStudio/midaz/components/transaction/internal/adapters/postgres/balance" + "github.com/LerianStudio/midaz/pkg" + "github.com/LerianStudio/midaz/pkg/mmodel" + "github.com/LerianStudio/midaz/pkg/net/http" + "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" + "testing" + "time" +) + +// TestGetAllBalances is responsible to test GetAllBalances with success and error +func TestGetAllBalances(t *testing.T) { + organizationID := pkg.GenerateUUIDv7() + ledgerID := pkg.GenerateUUIDv7() + accountID := pkg.GenerateUUIDv7() + + filter := http.QueryHeader{ + Limit: 10, + Page: 1, + SortOrder: "asc", + StartDate: time.Now().AddDate(0, -1, 0), + EndDate: time.Now(), + ToAssetCodes: []string{"BRL"}, + } + mockCur := http.CursorPagination{ + Next: "next", + Prev: "prev", + } + + t.Parallel() + ctrl := gomock.NewController(t) + defer ctrl.Finish() + mockBalanceRepo := balance.NewMockRepository(ctrl) + + uc := UseCase{ + BalanceRepo: mockBalanceRepo, + } + + t.Run("Success", func(t *testing.T) { + trans := []*mmodel.Balance{{}} + mockBalanceRepo. + EXPECT(). + ListAllByAccountID(gomock.Any(), organizationID, ledgerID, accountID, filter.ToCursorPagination()). + Return(trans, mockCur, nil). + Times(1) + res, cur, err := uc.BalanceRepo.ListAllByAccountID(context.TODO(), organizationID, ledgerID, accountID, filter.ToCursorPagination()) + + assert.NoError(t, err) + assert.Len(t, res, 1) + assert.NotNil(t, cur) + }) + + t.Run("Error", func(t *testing.T) { + errMsg := "errDatabaseItemNotFound" + mockBalanceRepo. + EXPECT(). + ListAllByAccountID(gomock.Any(), organizationID, ledgerID, accountID, filter.ToCursorPagination()). + Return(nil, http.CursorPagination{}, errors.New(errMsg)). + Times(1) + res, cur, err := uc.BalanceRepo.ListAllByAccountID(context.TODO(), organizationID, ledgerID, accountID, filter.ToCursorPagination()) + + assert.EqualError(t, err, errMsg) + assert.Nil(t, res) + assert.Equal(t, cur, http.CursorPagination{}) + }) +} diff --git a/components/transaction/internal/services/query/get-id-balance.go b/components/transaction/internal/services/query/get-id-balance.go new file mode 100644 index 00000000..3a448aeb --- /dev/null +++ b/components/transaction/internal/services/query/get-id-balance.go @@ -0,0 +1,49 @@ +package query + +import ( + "context" + "github.com/LerianStudio/midaz/pkg/mmodel" + "reflect" + + "github.com/LerianStudio/midaz/pkg" + "github.com/LerianStudio/midaz/pkg/mopentelemetry" + + "github.com/google/uuid" +) + +// GetBalanceByID gets data in the repository. +func (uc *UseCase) GetBalanceByID(ctx context.Context, organizationID, ledgerID, balanceID uuid.UUID) (*mmodel.Balance, error) { + logger := pkg.NewLoggerFromContext(ctx) + tracer := pkg.NewTracerFromContext(ctx) + + ctx, span := tracer.Start(ctx, "query.get_balance_by_id") + defer span.End() + + logger.Infof("Trying to get balance") + + balance, err := uc.BalanceRepo.Find(ctx, organizationID, ledgerID, balanceID) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to get balance on repo by id", err) + + logger.Errorf("Error getting balance: %v", err) + + return nil, err + } + + if balance != nil { + metadata, err := uc.MetadataRepo.FindByEntity(ctx, reflect.TypeOf(mmodel.Balance{}).Name(), balanceID.String()) + if err != nil { + mopentelemetry.HandleSpanError(&span, "Failed to get metadata on mongodb balance", err) + + logger.Errorf("Error get metadata on mongodb balance: %v", err) + + return nil, err + } + + if metadata != nil { + balance.Metadata = metadata.Data + } + } + + return balance, nil +} \ No newline at end of file diff --git a/components/transaction/internal/services/query/get-id-balance_test.go b/components/transaction/internal/services/query/get-id-balance_test.go new file mode 100644 index 00000000..8d7654b0 --- /dev/null +++ b/components/transaction/internal/services/query/get-id-balance_test.go @@ -0,0 +1,60 @@ +package query + +import ( + "context" + "errors" + "github.com/LerianStudio/midaz/components/transaction/internal/adapters/postgres/balance" + "github.com/LerianStudio/midaz/pkg" + "github.com/LerianStudio/midaz/pkg/mmodel" + "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" + "testing" +) + +func TestGetBalanceByID(t *testing.T) { + ID := pkg.GenerateUUIDv7() + organizationID := pkg.GenerateUUIDv7() + ledgerID := pkg.GenerateUUIDv7() + + balanceRes := &mmodel.Balance{ + ID: ID.String(), + OrganizationID: organizationID.String(), + LedgerID: ledgerID.String(), + } + + uc := UseCase{ + BalanceRepo: balance.NewMockRepository(gomock.NewController(t)), + } + + uc.BalanceRepo.(*balance.MockRepository). + EXPECT(). + Find(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Return(balanceRes, nil). + Times(1) + res, err := uc.BalanceRepo.Find(context.TODO(), organizationID, ledgerID, ID) + + assert.Equal(t, balanceRes, res) + assert.Nil(t, err) +} + +func TestGetBalanceIDError(t *testing.T) { + errMSG := "err to get balance on database" + ID := pkg.GenerateUUIDv7() + organizationID := pkg.GenerateUUIDv7() + ledgerID := pkg.GenerateUUIDv7() + + uc := UseCase{ + BalanceRepo: balance.NewMockRepository(gomock.NewController(t)), + } + + uc.BalanceRepo.(*balance.MockRepository). + EXPECT(). + Find(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Return(nil, errors.New(errMSG)). + Times(1) + res, err := uc.BalanceRepo.Find(context.TODO(), organizationID, ledgerID, ID) + + assert.NotEmpty(t, err) + assert.Equal(t, err.Error(), errMSG) + assert.Nil(t, res) +} diff --git a/go.mod b/go.mod index f2755d76..b355c10d 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,16 @@ module github.com/LerianStudio/midaz -go 1.23 +go 1.23.0 -toolchain go1.23.0 +toolchain go1.23.2 require ( github.com/Masterminds/squirrel v1.5.4 github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 github.com/antlr4-go/antlr/v4 v4.13.1 - github.com/casdoor/casdoor-go-sdk v1.3.0 + github.com/casdoor/casdoor-go-sdk v1.4.0 github.com/charmbracelet/bubbles v0.20.0 - github.com/charmbracelet/bubbletea v1.3.2 + github.com/charmbracelet/bubbletea v1.3.3 github.com/go-playground/locales v0.14.1 github.com/go-playground/universal-translator v0.18.1 github.com/gofiber/fiber/v2 v2.52.6 @@ -91,8 +91,8 @@ require ( golang.org/x/net v0.35.0 // indirect golang.org/x/oauth2 v0.26.0 // indirect golang.org/x/tools v0.30.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20250207221924-e9438ea467c6 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20250207221924-e9438ea467c6 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20250212204824-5a70512c5d8b // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250212204824-5a70512c5d8b // indirect ) require ( @@ -121,7 +121,7 @@ require ( go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.33.0 // indirect - golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac // indirect + golang.org/x/exp v0.0.0-20250215185904-eff6e970281f // indirect golang.org/x/sync v0.11.0 // indirect golang.org/x/text v0.22.0 gopkg.in/go-playground/assert.v1 v1.2.1 // indirect @@ -143,10 +143,9 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rivo/uniseg v0.4.7 // indirect - github.com/spf13/cobra v1.8.1 + github.com/spf13/cobra v1.9.1 github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasthttp v1.58.0 // indirect - github.com/valyala/tcplisten v1.0.0 // indirect + github.com/valyala/fasthttp v1.59.0 // indirect go.uber.org/zap v1.27.0 golang.org/x/sys v0.30.0 // indirect gopkg.in/go-playground/validator.v9 v9.31.0 diff --git a/go.sum b/go.sum index 33aa4417..bf637766 100644 --- a/go.sum +++ b/go.sum @@ -29,16 +29,16 @@ github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/bxcodec/dbresolver/v2 v2.2.0 h1:3Xg5Cw64khndjnWYiadP1mL1XU8eVxtkqcDadfihP6k= github.com/bxcodec/dbresolver/v2 v2.2.0/go.mod h1:xWb3HT8vrWUnoLVA7KQ+IcD9RvnzfRBqOkO9rKsg1rQ= -github.com/casdoor/casdoor-go-sdk v1.3.0 h1:iUZKsrNUkhtAoyitFIFw3e6TchctAdoxmVgLDtNAgpc= -github.com/casdoor/casdoor-go-sdk v1.3.0/go.mod h1:cMnkCQJgMYpgAlgEx8reSt1AVaDIQLcJ1zk5pzBaz+4= +github.com/casdoor/casdoor-go-sdk v1.4.0 h1:EhnIcMeCPiDE66tedy6EISkVjndR78slnwXqTfUnyhU= +github.com/casdoor/casdoor-go-sdk v1.4.0/go.mod h1:cMnkCQJgMYpgAlgEx8reSt1AVaDIQLcJ1zk5pzBaz+4= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE= github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU= -github.com/charmbracelet/bubbletea v1.3.2 h1:nc+gDivH0P8ii8CUcf3zCN/PiUz7LKbp3Iz+vYPScNY= -github.com/charmbracelet/bubbletea v1.3.2/go.mod h1:dtcUCyCGEX3g9tosuYiut3MXgY/Jsv9nKVdibKKRRXo= +github.com/charmbracelet/bubbletea v1.3.3 h1:WpU6fCY0J2vDWM3zfS3vIDi/ULq3SYphZhkAGGvmEUY= +github.com/charmbracelet/bubbletea v1.3.3/go.mod h1:dtcUCyCGEX3g9tosuYiut3MXgY/Jsv9nKVdibKKRRXo= github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg= github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo= github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE= @@ -48,7 +48,7 @@ github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNE github.com/corpix/uarand v0.0.0-20170723150923-031be390f409 h1:9A+mfQmwzZ6KwUXPc8nHxFtKgn9VIvO3gXAOspIcE3s= github.com/corpix/uarand v0.0.0-20170723150923-031be390f409/go.mod h1:JSm890tOkDN+M1jqN8pUGDKnzJrsVbJwSMHBY4zwz7M= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI= github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= @@ -256,9 +256,8 @@ github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMT github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= -github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= +github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -294,9 +293,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.35.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I= github.com/valyala/fasthttp v1.36.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I= -github.com/valyala/fasthttp v1.58.0 h1:GGB2dWxSbEprU9j0iMJHgdKYJVDyjrOwF9RE59PbRuE= -github.com/valyala/fasthttp v1.58.0/go.mod h1:SYXvHHaFp7QZHGKSHmoMipInhrI5StHrhDTYVEjK/Kw= -github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= +github.com/valyala/fasthttp v1.59.0 h1:Qu0qYHfXvPk1mSLNqcFtEk6DpxgA26hy6bmydotDpRI= +github.com/valyala/fasthttp v1.59.0/go.mod h1:GTxNb9Bc6r2a9D0TWNSPwDz78UxnTGBViY3xZNEqyYU= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= @@ -360,8 +358,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= -golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac h1:l5+whBCLH3iH2ZNHYLbAe58bo7yrN4mVcnkHDYz5vvs= -golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac/go.mod h1:hH+7mtFmImwwcMvScyxUhjuVHR3HGaDPMn9rMSUUbxo= +golang.org/x/exp v0.0.0-20250215185904-eff6e970281f h1:oFMYAjX0867ZD2jcNiLBrI9BdpmEkvPyi5YrBGXbamg= +golang.org/x/exp v0.0.0-20250215185904-eff6e970281f/go.mod h1:BHOTPb3L19zxehTsLoJXVaTktb06DFgmdW6Wb9s8jqk= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM= @@ -423,10 +421,10 @@ golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/api v0.0.0-20250207221924-e9438ea467c6 h1:L9JNMl/plZH9wmzQUHleO/ZZDSN+9Gh41wPczNy+5Fk= -google.golang.org/genproto/googleapis/api v0.0.0-20250207221924-e9438ea467c6/go.mod h1:iYONQfRdizDB8JJBybql13nArx91jcUk7zCXEsOofM4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250207221924-e9438ea467c6 h1:2duwAxN2+k0xLNpjnHTXoMUgnv6VPSp5fiqTuwSxjmI= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250207221924-e9438ea467c6/go.mod h1:8BS3B93F/U1juMFq9+EDk+qOT5CO1R9IzXxG3PTqiRk= +google.golang.org/genproto/googleapis/api v0.0.0-20250212204824-5a70512c5d8b h1:i+d0RZa8Hs2L/MuaOQYI+krthcxdEbEM2N+Tf3kJ4zk= +google.golang.org/genproto/googleapis/api v0.0.0-20250212204824-5a70512c5d8b/go.mod h1:iYONQfRdizDB8JJBybql13nArx91jcUk7zCXEsOofM4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250212204824-5a70512c5d8b h1:FQtJ1MxbXoIIrZHZ33M+w5+dAP9o86rgpjoKr/ZmT7k= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250212204824-5a70512c5d8b/go.mod h1:8BS3B93F/U1juMFq9+EDk+qOT5CO1R9IzXxG3PTqiRk= google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ= google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw= google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= diff --git a/pkg/constant/errors.go b/pkg/constant/errors.go index afe2b26a..d1594421 100644 --- a/pkg/constant/errors.go +++ b/pkg/constant/errors.go @@ -98,4 +98,6 @@ var ( ErrTransactionIDIsAlreadyARevert = errors.New("0088") ErrTransactionCantRevert = errors.New("0089") ErrTransactionAmbiguous = errors.New("0090") -) + ErrBalanceIDNotFound = errors.New("0091") + ErrNoBalancesFound = errors.New("0092") +) \ No newline at end of file diff --git a/pkg/constant/http.go b/pkg/constant/http.go index 23e529ed..44a4d1a3 100644 --- a/pkg/constant/http.go +++ b/pkg/constant/http.go @@ -13,4 +13,5 @@ var UUIDPathParameters = []string{ "asset_rate_id", "external_id", "audit_id", + "balance_id", } diff --git a/pkg/mmodel/account.go b/pkg/mmodel/account.go index 4ea5c643..6408f029 100644 --- a/pkg/mmodel/account.go +++ b/pkg/mmodel/account.go @@ -31,7 +31,7 @@ type UpdateAccountInput struct { SegmentID *string `json:"segmentId" validate:"omitempty,uuid" example:"00000000-0000-0000-0000-000000000000"` PortfolioID *string `json:"portfolioId" validate:"omitempty,uuid" example:"00000000-0000-0000-0000-000000000000"` Status Status `json:"status"` - Metadata map[string]any `json:"metadata" validate:"dive,keys,keymax=100,endkeys,nonested,valuemax=2000"` + Metadata map[string]any `json:"metadata" validate:"dive,keys,keymax=100,endkeys,omitempty,nonested,valuemax=2000"` } // @name UpdateAccountInput // Account is a struct designed to encapsulate response payload data. diff --git a/pkg/mmodel/asset.go b/pkg/mmodel/asset.go index c0d2c35e..19942002 100644 --- a/pkg/mmodel/asset.go +++ b/pkg/mmodel/asset.go @@ -23,7 +23,7 @@ type CreateAssetInput struct { type UpdateAssetInput struct { Name string `json:"name" validate:"max=256" example:"Bitcoin"` Status Status `json:"status"` - Metadata map[string]any `json:"metadata" validate:"dive,keys,keymax=100,endkeys,nonested,valuemax=2000"` + Metadata map[string]any `json:"metadata" validate:"dive,keys,keymax=100,endkeys,omitempty,nonested,valuemax=2000"` } // @name UpdateAssetInput // Asset is a struct designed to encapsulate payload data. diff --git a/pkg/mmodel/balance.go b/pkg/mmodel/balance.go index 5728d054..1b211aa8 100644 --- a/pkg/mmodel/balance.go +++ b/pkg/mmodel/balance.go @@ -29,6 +29,11 @@ type Balance struct { Metadata map[string]any `json:"metadata,omitempty"` } +type UpdateBalance struct { + AllowSending *bool `json:"allowSending" example:"true"` + AllowReceiving *bool `json:"allowReceiving" example:"true"` +} + // IDtoUUID is a func that convert UUID string to uuid.UUID func (b *Balance) IDtoUUID() uuid.UUID { return uuid.MustParse(b.ID) diff --git a/pkg/mmodel/ledger.go b/pkg/mmodel/ledger.go index 9f02951b..e9cd885c 100644 --- a/pkg/mmodel/ledger.go +++ b/pkg/mmodel/ledger.go @@ -19,7 +19,7 @@ type CreateLedgerInput struct { type UpdateLedgerInput struct { Name string `json:"name" validate:"max=256" example:"Lerian Studio Updated"` Status Status `json:"status"` - Metadata map[string]any `json:"metadata" validate:"dive,keys,keymax=100,endkeys,nonested,valuemax=2000"` + Metadata map[string]any `json:"metadata" validate:"dive,keys,keymax=100,endkeys,omitempty,nonested,valuemax=2000"` } // @name UpdateLedgerInput // Ledger is a struct designed to encapsulate payload data. diff --git a/pkg/mmodel/organization.go b/pkg/mmodel/organization.go index 0a67db3d..74ae5365 100644 --- a/pkg/mmodel/organization.go +++ b/pkg/mmodel/organization.go @@ -21,12 +21,12 @@ type CreateOrganizationInput struct { // // swagger:model UpdateOrganizationInput // @Description UpdateOrganizationInput is the input payload to update an organization. type UpdateOrganizationInput struct { - LegalName string `json:"legalName" validate:"required,max=256" example:"Lerian Studio Updated"` + LegalName string `json:"legalName" validate:"max=256" example:"Lerian Studio Updated"` ParentOrganizationID *string `json:"parentOrganizationId" validate:"omitempty,uuid" example:"00000000-0000-0000-0000-000000000000"` - DoingBusinessAs *string `json:"doingBusinessAs" validate:"max=256" example:"The ledger.io"` + DoingBusinessAs string `json:"doingBusinessAs" validate:"max=256" example:"The ledger.io"` Address Address `json:"address"` Status Status `json:"status"` - Metadata map[string]any `json:"metadata" validate:"dive,keys,keymax=100,endkeys,nonested,valuemax=2000"` + Metadata map[string]any `json:"metadata" validate:"dive,keys,keymax=100,endkeys,omitempty,nonested,valuemax=2000"` } // @name UpdateOrganizationInput // Organization is a struct designed to encapsulate response payload data. diff --git a/pkg/mmodel/portfolio.go b/pkg/mmodel/portfolio.go index 357235dc..2e2d92ab 100644 --- a/pkg/mmodel/portfolio.go +++ b/pkg/mmodel/portfolio.go @@ -20,7 +20,7 @@ type CreatePortfolioInput struct { type UpdatePortfolioInput struct { Name string `json:"name" validate:"max=256" example:"My Portfolio Updated"` Status Status `json:"status"` - Metadata map[string]any `json:"metadata" validate:"dive,keys,keymax=100,endkeys,nonested,valuemax=2000"` + Metadata map[string]any `json:"metadata" validate:"dive,keys,keymax=100,endkeys,omitempty,nonested,valuemax=2000"` } // @name UpdatePortfolioInput // Portfolio is a struct designed to encapsulate request update payload data. diff --git a/pkg/mmodel/segment.go b/pkg/mmodel/segment.go index e5d57b8b..47f52eb9 100644 --- a/pkg/mmodel/segment.go +++ b/pkg/mmodel/segment.go @@ -19,7 +19,7 @@ type CreateSegmentInput struct { type UpdateSegmentInput struct { Name string `json:"name" validate:"max=256" example:"My Segment Updated"` Status Status `json:"status"` - Metadata map[string]any `json:"metadata" validate:"dive,keys,keymax=100,endkeys,nonested,valuemax=2000"` + Metadata map[string]any `json:"metadata" validate:"dive,keys,keymax=100,endkeys,omitempty,nonested,valuemax=2000"` } // @name UpdateSegmentInput // Segment is a struct designed to encapsulate payload data. diff --git a/postman/MIDAZ.postman_collection.json b/postman/MIDAZ.postman_collection.json index 1d7e89dd..44e05517 100644 --- a/postman/MIDAZ.postman_collection.json +++ b/postman/MIDAZ.postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "b65ce2ce-d594-48c4-9ff9-49f6af023cd3", + "_postman_id": "466b36cf-9d1a-45ad-8800-b20825152983", "name": "MIDAZ", "description": "## **How generate token to use on MIDAZ**\n\n\n\n\n\n\n\n\n\n", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", @@ -566,7 +566,7 @@ ], "body": { "mode": "raw", - "raw": "{\n \"legalName\": \"{{$randomCompanyName}}\",\n \"parentOrganizationId\": \"{{organization_id}}\",\n \"doingBusinessAs\": \"The ledger.io\", //opcional\n \"status\": {\n \"code\": \"BLOCKED\",\n \"description\": \"My blocked organization\"\n },\n \"address\": {\n \"line1\": \"Avenida Paulista, 1234\",\n \"line2\": \"CJ 203\",\n \"zipCode\": \"01310916\",\n \"city\": \"{{$randomCity}}\",\n \"state\": \"{{$randomCountryCode}}\",\n \"country\": \"{{$randomCountryCode}}\" //de acordo com a ISO 3166-1 alpha2\n },\n \"metadata\": {\n \"chave\": \"metadata_sample_update\",\n \"bitcoinn\": \"{{$randomBitcoin}}\",\n \"boolean\": {{$randomBoolean}},\n \"double\": 10.5,\n \"int\": 1\n }\n}", + "raw": "{\n \"legalName\": \"{{$randomCompanyName}}\",\n //\"parentOrganizationId\": \"{{organization_id}}\",\n \"doingBusinessAs\": \"The ledger.io 2\", //opcional\n \"status\": {\n \"code\": \"BLOCKED\",\n \"description\": \"My blocked organization\"\n },\n \"address\": {\n \"line1\": \"Avenida Paulista, 1234\",\n \"line2\": \"CJ 203\",\n \"zipCode\": \"01310916\",\n \"city\": \"{{$randomCity}}\",\n \"state\": \"{{$randomCountryCode}}\",\n \"country\": \"{{$randomCountryCode}}\" //de acordo com a ISO 3166-1 alpha2\n },\n \"metadata\": {\n \"chave\": \"testettetetete\"\n },\n \"metadatas\": {\n \"zozo\": null\n }\n}", "options": { "raw": { "language": "json" @@ -2750,6 +2750,247 @@ } ] }, + { + "name": "Balances", + "item": [ + { + "name": "Operations", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "" + ], + "type": "text/javascript", + "packages": {} + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Request-Id", + "value": "{{$randomUUID}}", + "type": "text", + "disabled": true + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"allowSending\": true,\n \"allowReceiving\": false\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{url_transaction}}/v1/organizations/{{organization_id}}/ledgers/{{ledger_id}}/balances/{{balance_id}}", + "host": [ + "{{url_transaction}}" + ], + "path": [ + "v1", + "organizations", + "{{organization_id}}", + "ledgers", + "{{ledger_id}}", + "balances", + "{{balance_id}}" + ] + }, + "description": "This is a POST request, submitting data to an API via the request body. This request submits JSON data, and the data is reflected in the response.\n\nA successful POST request typically returns a `200 OK` or `201 Created` response code." + }, + "response": [] + }, + { + "name": "List All", + "request": { + "method": "GET", + "header": [ + { + "key": "X-Request-Id", + "value": "{{$randomUUID}}", + "type": "text", + "disabled": true + } + ], + "url": { + "raw": "{{url_transaction}}/v1/organizations/{{organization_id}}/ledgers/{{ledger_id}}/balances", + "host": [ + "{{url_transaction}}" + ], + "path": [ + "v1", + "organizations", + "{{organization_id}}", + "ledgers", + "{{ledger_id}}", + "balances" + ], + "query": [ + { + "key": "start_date", + "value": "2021-01-01", + "description": "Date in the format yyyy-mm-dd", + "disabled": true + }, + { + "key": "cursor", + "value": "", + "description": "Cursor Pagination", + "disabled": true + }, + { + "key": "end_date", + "value": "2025-01-01", + "description": "Date in the format yyyy-mm-dd", + "disabled": true + }, + { + "key": "sort_order", + "value": "asc", + "description": "Enum(asc,desc)", + "disabled": true + }, + { + "key": "limit", + "value": "10", + "description": "Default 10", + "disabled": true + } + ] + } + }, + "response": [] + }, + { + "name": "List All By Account", + "request": { + "method": "GET", + "header": [ + { + "key": "X-Request-Id", + "value": "{{$randomUUID}}", + "type": "text", + "disabled": true + } + ], + "url": { + "raw": "{{url_transaction}}/v1/organizations/{{organization_id}}/ledgers/{{ledger_id}}/accounts/{{account_id}}/balances", + "host": [ + "{{url_transaction}}" + ], + "path": [ + "v1", + "organizations", + "{{organization_id}}", + "ledgers", + "{{ledger_id}}", + "accounts", + "{{account_id}}", + "balances" + ], + "query": [ + { + "key": "start_date", + "value": "2021-01-01", + "description": "Date in the format yyyy-mm-dd", + "disabled": true + }, + { + "key": "cursor", + "value": null, + "description": "Cursor Pagination", + "disabled": true + }, + { + "key": "end_date", + "value": "2025-01-01", + "description": "Date in the format yyyy-mm-dd", + "disabled": true + }, + { + "key": "sort_order", + "value": "asc", + "description": "Enum(asc,desc)", + "disabled": true + }, + { + "key": "limit", + "value": "10", + "description": "Default 10", + "disabled": true + } + ] + } + }, + "response": [] + }, + { + "name": "Find", + "request": { + "method": "GET", + "header": [ + { + "key": "X-Request-Id", + "value": "{{$randomUUID}}", + "type": "text", + "disabled": true + } + ], + "url": { + "raw": "{{url_transaction}}/v1/organizations/{{organization_id}}/ledgers/{{ledger_id}}/balances/{{balance_id}}", + "host": [ + "{{url_transaction}}" + ], + "path": [ + "v1", + "organizations", + "{{organization_id}}", + "ledgers", + "{{ledger_id}}", + "balances", + "{{balance_id}}" + ] + } + }, + "response": [] + }, + { + "name": "Delete", + "request": { + "method": "DELETE", + "header": [ + { + "key": "X-Request-Id", + "value": "{{$randomUUID}}", + "type": "text", + "disabled": true + } + ], + "url": { + "raw": "{{url_transaction}}/v1/organizations/{{organization_id}}/ledgers/{{ledger_id}}/balances/{{balance_id}}", + "host": [ + "{{url_transaction}}" + ], + "path": [ + "v1", + "organizations", + "{{organization_id}}", + "ledgers", + "{{ledger_id}}", + "balances", + "{{balance_id}}" + ] + } + }, + "response": [] + } + ] + }, { "name": "Asset Rates", "item": [ @@ -3391,6 +3632,11 @@ "key": "audit_id", "value": "", "type": "string" + }, + { + "key": "balance_id", + "value": "", + "type": "string" } ] } \ No newline at end of file