Skip to content

Add read-model merchant schedule endpoint and use it in schedule creation validation#1659

Merged
StuartFerguson merged 18 commits intomasterfrom
copilot/add-merchant-schedule-endpoint
Mar 16, 2026
Merged

Add read-model merchant schedule endpoint and use it in schedule creation validation#1659
StuartFerguson merged 18 commits intomasterfrom
copilot/add-merchant-schedule-endpoint

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 15, 2026

Merchant schedules could be created and updated, but the validation flow was still reading schedule state from the aggregate path. This change adds a dedicated read-model-backed merchant schedule endpoint and updates the SpecFlow schedule creation flow to validate the projected database state by merchant and year.

  • Read-model schedule API

    • Added GET /api/estates/{estateId}/merchants/{merchantId}/schedules/{year}/readmodel
    • Returns MerchantScheduleResponse for a single merchant/year from the read-model database
    • Keeps the existing aggregate-backed GetMerchantSchedule endpoint unchanged
  • Repository and query path

    • Added a read-model repository lookup for merchant schedule + month rows
    • Wired the new path through:
      • repository
      • manager
      • MediatR query/handler
      • HTTP handler/endpoint
      • client API
  • SpecFlow validation

    • Updated WhenICreateTheFollowingMerchantSchedules to validate via the new read-model endpoint
    • This now checks the projected schedule that the system persists to the read model, not just aggregate state
    • Closed-day comparison remains order-insensitive
  • Robustness

    • Read-model ClosedDays parsing now tolerates malformed persisted values instead of throwing during schedule retrieval
merchantGroup.MapGet(
    "/{merchantId:guid}/schedules/{year:int}/readmodel",
    MerchantHandlers.GetMerchantScheduleFromReadModel)
    .WithName("GetMerchantScheduleFromReadModel");

// SpecFlow validation now uses the read-model projection
await this.TransactionProcessorClient.GetMerchantScheduleFromReadModel(
    accessToken,
    scheduleRequest.estate.EstateId,
    scheduleRequest.merchantId,
    scheduleRequest.request.Year,
    CancellationToken.None);

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.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj --filter TransactionProcessorManager_GetMerchantSchedule -p:RestoreIgnoreFailedSources=true -nologo (dns block)
    • Triggering command: /usr/bin/dotnet dotnet test /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj --filter GetMerchantScheduleFromReadModel -p:RestoreIgnoreFailedSources=true -nologo (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (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>Merchant Schedule</issue_title>
<issue_description>New endpoint to allow setting of merchant open/closed days over a year.

This can vary each year,

Can you give me a plan of how to implement this in a new Merchant Schedule Aggregate including requests to create/update schedules over the year, I am using event sourcing so ideas for events would be great also.

What I don't want however is an event for every date stating the merchant is open or closed.

Maybe have a event per month to keep the event size down.

Have a look at the other Aggregates to get a feel for how they are structured.</issue_description>

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


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits March 15, 2026 16:33
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] Add new endpoint for setting merchant schedule Add year-based Merchant Schedule aggregate with month-level events Mar 15, 2026
Copilot AI requested a review from StuartFerguson March 15, 2026 16:38
@StuartFerguson
Copy link
Copy Markdown
Member

@copilot is there any need for the MerchantScheduleCreatedEvent ?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 15, 2026

@copilot is there any need for the MerchantScheduleCreatedEvent ?

Not strictly. It’s only useful if we want to represent a schedule year existing before any month overrides are added, or allow an intentionally empty schedule for a year. Because the month event already carries EstateId, MerchantId and Year, we could remove MerchantScheduleCreatedEvent and treat the first month update as implicit creation; the trade-off is losing that explicit lifecycle/empty-schedule state. If you want, I can simplify it that way in a follow-up.

@StuartFerguson
Copy link
Copy Markdown
Member

@copilot ok maybe a compromise and have the created event and the update events only indicate which days the merchant is closed?

Copilot AI and others added 2 commits March 15, 2026 16:48
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 15, 2026

@copilot ok maybe a compromise and have the created event and the update events only indicate which days the merchant is closed?

Done in 642c43a. I kept the created event for the explicit schedule lifecycle, and simplified the month update event/model/request path so month updates now only carry ClosedDays.

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.Aggregates.Tests/TransactionProcessor.Aggregates.Tests.csproj --no-restore --filter MerchantScheduleAggregateTests -nologo (dns block)
    • Triggering command: /usr/bin/dotnet dotnet test /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.Aggregates.Tests/TransactionProcessor.Aggregates.Tests.csproj --filter MerchantScheduleAggregateTests -p:RestoreIgnoreFailedSources=true -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)

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

Copilot AI changed the title Add year-based Merchant Schedule aggregate with month-level events Add year-based Merchant Schedule aggregate with closed-day month events Mar 15, 2026
@StuartFerguson
Copy link
Copy Markdown
Member

@copilot ok can you now expand this get the request from the minimal api endpoint to the aggregate, this means changes to the domain service and request handler

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 15, 2026

@copilot ok can you now expand this get the request from the minimal api endpoint to the aggregate, this means changes to the domain service and request handler

Done in f622296. I wired create/update merchant schedule requests from the merchant minimal API endpoints through MerchantHandlers, MerchantCommands, MerchantRequestHandler, and MerchantDomainService into MerchantScheduleAggregate, using a deterministic aggregate id based on estate, merchant, and year.

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.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj --filter MerchantSchedule -p:RestoreIgnoreFailedSources=true -nologo (dns block)
    • Triggering command: /usr/bin/dotnet dotnet test /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj --filter Mediator_Send_RequestHandled -p:RestoreIgnoreFailedSources=true -nologo _TOKEN&#34;; }; f (dns block)
    • Triggering command: /usr/bin/dotnet dotnet test /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj --filter MerchantSchedule -p:RestoreIgnoreFailedSources=true -nologo _TOKEN&#34;; }; f (dns block)

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

Copilot AI changed the title Add year-based Merchant Schedule aggregate with closed-day month events Add year-based Merchant Schedule aggregate and merchant schedule write flow Mar 15, 2026
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title Add year-based Merchant Schedule aggregate and merchant schedule write flow Wire merchant schedule requests from minimal API to aggregate Mar 15, 2026
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title Wire merchant schedule requests from minimal API to aggregate Expand merchant schedule coverage and add Create Merchant SpecFlow schedule step Mar 15, 2026
@StuartFerguson
Copy link
Copy Markdown
Member

@copilot i need you to now update my ReadModelDomainEventHandler, Repository and Database context to get this data feeing into my Read Model

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 16, 2026

@copilot i need you to now update my ReadModelDomainEventHandler, Repository and Database context to get this data feeing into my Read Model

Done in 297c0a2. I wired MerchantScheduleCreatedEvent and MerchantScheduleMonthUpdatedEvent through ReadModelDomainEventHandler into the read-model repository, added DbContext/entities plus a migration for persisted schedule header/month rows, and mapped projected schedules back onto the merchant read model/API response. Targeted validation was attempted, but sandbox restore is still blocked by the private Feedz NuGet source (NU1801/NU1101).

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.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj --filter ReadModelDomainEventHandler -p:RestoreIgnoreFailedSources=true -nologo (dns block)
    • Triggering command: /usr/bin/dotnet dotnet test /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj --filter MerchantScheduleDomainEventHandler -p:RestoreIgnoreFailedSources=true -nologo (dns block)
    • Triggering command: /usr/bin/dotnet dotnet test /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.Tests/TransactionProcessor.Tests.csproj --filter ModelFactory_Merchant_IsConverted -p:RestoreIgnoreFailedSources=true -nologo (dns block)

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

Copilot AI changed the title Expand merchant schedule coverage and add Create Merchant SpecFlow schedule step Project merchant schedule end-to-end, add read model support, and extend Create Merchant SpecFlow coverage Mar 16, 2026
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title Project merchant schedule end-to-end, add read model support, and extend Create Merchant SpecFlow coverage Sync EstateManagementContext migration metadata for merchant schedule read model Mar 16, 2026
Copilot AI and others added 5 commits March 16, 2026 10:47
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title Sync EstateManagementContext migration metadata for merchant schedule read model Add merchant schedule read endpoint and align EF migration metadata with the current model Mar 16, 2026
Copilot AI and others added 2 commits March 16, 2026 11:23
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title Add merchant schedule read endpoint and align EF migration metadata with the current model Add read-model merchant schedule endpoint and use it in schedule creation validation Mar 16, 2026
Introduced merchant schedule functionality in domain, database, and event handling. Registered MerchantScheduleAggregate repository and updated DTOs and helpers. Added new domain events for schedule creation and month updates. Refactored integration tests for clarity and coverage, including new merchant schedule scenarios. Cleaned up migration attributes and ensured correct model types.
@StuartFerguson StuartFerguson marked this pull request as ready for review March 16, 2026 13:22
@StuartFerguson StuartFerguson merged commit c81f202 into master Mar 16, 2026
7 checks passed
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.

Merchant Schedule

2 participants