Skip to content

fix: operation route delete when operation missing#2093

Merged
ClaraTersi merged 7 commits into
developfrom
fix/MDZ-2010
May 1, 2026
Merged

fix: operation route delete when operation missing#2093
ClaraTersi merged 7 commits into
developfrom
fix/MDZ-2010

Conversation

@ClaraTersi
Copy link
Copy Markdown
Member

Summary

  • Scope operation route delete link checks by organization and ledger.
  • Return not found when deleting missing or already-deleted operation routes.
  • Improve operation route repository observability and structured logging.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 534a9af0-7419-4118-85f5-5127ca05b943

📥 Commits

Reviewing files that changed from the base of the PR and between 709db77 and 79cc0cc.

📒 Files selected for processing (9)
  • CLAUDE.md
  • components/ledger/internal/adapters/http/in/operation_route_test.go
  • components/ledger/internal/adapters/postgres/operationroute/operationroute.postgresql.go
  • components/ledger/internal/adapters/postgres/operationroute/operationroute.postgresql_integration_test.go
  • components/ledger/internal/adapters/postgres/operationroute/operationroute.postgresql_mock.go
  • components/ledger/internal/services/command/delete_operation_route.go
  • components/ledger/internal/services/command/delete_operation_route_test.go
  • pkg/net/http/httputils.go
  • pkg/net/http/httputils_test.go

Walkthrough

Updates the HasTransactionRouteLinks repository method to accept organization and ledger identifiers for multi-tenant isolation. Refactors operation route repository to use Squirrel for SQL construction, adds OTEL span attributes and structured logging throughout, and enhances delete error handling. Tests are updated accordingly, and HTTP utilities extract pagination date range computation into a reusable helper.

Changes

Cohort / File(s) Summary
Operation Route Repository Interface & Implementation
components/ledger/internal/adapters/postgres/operationroute/operationroute.postgresql.go
Signature change: HasTransactionRouteLinks now requires organizationID and ledgerID parameters. Migrated SQL construction to Squirrel (Insert/Select/Update). Added OTEL span attributes for request scope and DB metrics, early ctx.Err() checks, and structured logging (logger.Log with libLog.Err). Enhanced Delete to check RowsAffected and return business error when zero rows updated. Expanded HasTransactionRouteLinks query to scope results within organization/ledger context.
Operation Route Repository Tests
components/ledger/internal/adapters/postgres/operationroute/operationroute.postgresql_integration_test.go, components/ledger/internal/adapters/http/in/operation_route_test.go, components/ledger/internal/adapters/postgres/operationroute/operationroute.postgresql_mock.go
Updated all mock and integration test expectations to pass orgID and ledgerID to HasTransactionRouteLinks. Added new integration test for non-existent entity deletion error handling. Added scope isolation test (HasTransactionRouteLinks_WrongScope) to verify cross-organization/ledger boundary enforcement.
Delete Operation Route Service
components/ledger/internal/services/command/delete_operation_route.go, components/ledger/internal/services/command/delete_operation_route_test.go
Enriched OpenTelemetry span with request-scoped attributes (organization_id, ledger_id, operation_route_id). Added early context cancellation check. Updated repository link-check calls to include organizationID and ledgerID. Replaced formatted logs with structured logger calls. Added test case for pre-canceled context behavior.
HTTP Utilities
pkg/net/http/httputils.go, pkg/net/http/httputils_test.go
Extracted default date-range computation into new defaultPaginationDateRange helper function. Converts provided time to UTC and computes start/end boundaries normalized to UTC. Added corresponding unit test validating UTC normalization behavior.
Documentation
CLAUDE.md
Condensed from comprehensive technical reference to concise agent-focused reference. Preserved core architecture flow and key file locations; replaced extensive sections (full env var reference, build/test matrices, long-form conventions) with targeted guidelines. Added/clarified logging constraints, observability/span rules, and explicit "Commands"/"Do Not" lists. Condensed error-handling and conventions sections.

Review rate limit: 4/5 reviews remaining, refill in 12 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@lerian-studio
Copy link
Copy Markdown
Contributor

🔒 Security Scan Results — crm

Trivy

Filesystem Scan

✅ No vulnerabilities or secrets found.

Docker Image Scan

✅ No vulnerabilities found.


Docker Hub Health Score Compliance

✅ Policies — 4/4 met

Policy Status
Default non-root user ✅ Passed
No fixable critical/high CVEs ✅ Passed
No high-profile vulnerabilities ✅ Passed
No AGPL v3 licenses ✅ Passed

Pre-release Version Check

✅ No unstable version pins found.


🔍 View full scan logs

@lerian-studio
Copy link
Copy Markdown
Contributor

📊 Unit Test Coverage Report: midaz-ledger

Metric Value
Overall Coverage 85.4% ✅ PASS
Threshold 85%

Coverage by Package

Package Coverage
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/http/in 85.7%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/mongodb/onboarding 66.7%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/mongodb/transaction 66.7%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/postgres/account 100.0%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/postgres/accounttype 66.7%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/postgres/asset 100.0%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/postgres/assetrate 100.0%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/postgres/balance 97.5%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/postgres/ledger 100.0%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/postgres/operation 89.9%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/postgres/operationroute 100.0%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/postgres/organization 100.0%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/postgres/portfolio 100.0%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/postgres/segment 100.0%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/postgres/transaction 94.9%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/postgres/transactionroute 100.0%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/rabbitmq 91.5%
github.com/LerianStudio/midaz/v3/components/ledger/internal/adapters/redis/transaction/balance 100.0%
github.com/LerianStudio/midaz/v3/components/ledger/internal/services/command 87.0%
github.com/LerianStudio/midaz/v3/components/ledger/internal/services/query 93.1%
github.com/LerianStudio/midaz/v3/components/ledger/internal/services 0.0%

Generated by Go PR Analysis workflow

@lerian-studio
Copy link
Copy Markdown
Contributor

🔒 Security Scan Results — ledger

Trivy

Filesystem Scan

✅ No vulnerabilities or secrets found.

Docker Image Scan

✅ No vulnerabilities found.


Docker Hub Health Score Compliance

✅ Policies — 4/4 met

Policy Status
Default non-root user ✅ Passed
No fixable critical/high CVEs ✅ Passed
No high-profile vulnerabilities ✅ Passed
No AGPL v3 licenses ✅ Passed

Pre-release Version Check

✅ No unstable version pins found.


🔍 View full scan logs

Copy link
Copy Markdown
Contributor

@gandalf-at-lerian gandalf-at-lerian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid work. The org+ledger scoping on HasTransactionRouteLinks closes a real cross-tenant gap. Delete returning not-found on zero RowsAffected is correct behavior. squirrel migration, structured logging, OTel attributes, ctx.Err() checks — all consistent with project standards.

Minor suggestion for a follow-up: FindTransactionRouteIDs still lacks org/ledger scoping.

CI green. LGTM. 🧙

@ClaraTersi ClaraTersi merged commit 01a18d5 into develop May 1, 2026
22 checks passed
@ClaraTersi ClaraTersi deleted the fix/MDZ-2010 branch May 1, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants