Skip to content

Refactor GetMerchantContracts to meet repository complexity limits#1674

Merged
StuartFerguson merged 3 commits intomasterfrom
copilot/fix-merchant-contracts-complexity
Mar 18, 2026
Merged

Refactor GetMerchantContracts to meet repository complexity limits#1674
StuartFerguson merged 3 commits intomasterfrom
copilot/fix-merchant-contracts-complexity

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 18, 2026

TransactionProcessorReadModelRepository.GetMerchantContracts exceeded the repository complexity threshold due to inline contract assembly and product deduplication logic. This change reduces the method size without changing the query shape or returned model data.

  • Refactor contract assembly

    • Extract merchant-specific contract creation into GetOrCreateMerchantContract(...)
    • Keep GetMerchantContracts(...) focused on query execution and result projection
  • Reuse existing product deduplication path

    • Replace inline product-add logic with the existing AddProductIfRequired(...) helper
    • Preserve duplicate detection by ContractProductId
  • Scope of change

    • No query behavior changes
    • No model shape changes
    • No cross-cutting repository changes outside this method path
foreach (var contractData in query)
{
    ContractModel contract =
        this.GetOrCreateMerchantContract(contracts, estateId, contractData.Contract, contractData.Operator);

    this.AddProductIfRequired(contract, contractData.Product);
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • f.feedz.io
    • Triggering command: /usr/bin/dotnet dotnet test /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.Tests/TransactionProcessor.Tests.csproj --filter VerifyBootstrapperIsValid --no-restore -nologo (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.sln --packages /tmp/codeql-scratch-7ae8d40573b4aa77/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-7ae8d40573b4aa77/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-7ae8d40573b4aa77/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Complexity] Method TransactionProcessorReadModelRepository::GetMerchantContracts has 53 lines of code (limit is 50)</issue_title>
<issue_description>Codacy ID: e262ac9ef045b9f2b7777bb7d8fc63fd

File: TransactionProcessor.Repository/ITransactionProcessorReadModelRepository.cs
Line: 776
Rule: Complexity (Warning)
Commit: 5b8f3e64d731c7b181b225e9d4117fda74faa3ac

Message: Method TransactionProcessorReadModelRepository::GetMerchantContracts has 53 lines of code (limit is 50)

**Code Snippet:**
```csharp
        public async Task<Result<List<ContractModel>>> GetMerchantContracts(Guid estateId, 
```

</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI changed the title [WIP] [Complexity] Reduce method lines in GetMerchantContracts Refactor GetMerchantContracts to meet repository complexity limits Mar 18, 2026
Copilot AI requested a review from StuartFerguson March 18, 2026 07:36
@StuartFerguson StuartFerguson marked this pull request as ready for review March 18, 2026 08:29
@StuartFerguson StuartFerguson merged commit f64a661 into master Mar 18, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Complexity] Method TransactionProcessorReadModelRepository::GetMerchantContracts has 53 lines of code (limit is 50)

2 participants