2026-02-05 21:35:26 +01:00
|
|
|
using Books.Api.Domain;
|
Add all backend domain, commands, repositories, and tests
This commit includes all previously untracked backend files:
Domain:
- Accounts, Attachments, BankConnections, Customers
- FiscalYears, Invoices, JournalEntryDrafts
- Orders, Products, UserAccess
Commands & Handlers:
- Full CQRS command structure for all domains
Repositories:
- PostgreSQL repositories for all read models
- Bank transaction and ledger repositories
GraphQL:
- Input types, scalars, and types for all entities
- Mutations and queries
Infrastructure:
- Banking integration (Enable Banking client)
- File storage, Invoicing, Reporting, SAF-T export
- Database migrations (003-029)
Tests:
- Integration tests for GraphQL endpoints
- Domain tests
- Invoicing and reporting tests
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 22:19:42 +01:00
|
|
|
using Books.Api.Domain.Accounts;
|
2026-02-05 21:35:26 +01:00
|
|
|
using Books.Api.EventFlow.Repositories;
|
Add all backend domain, commands, repositories, and tests
This commit includes all previously untracked backend files:
Domain:
- Accounts, Attachments, BankConnections, Customers
- FiscalYears, Invoices, JournalEntryDrafts
- Orders, Products, UserAccess
Commands & Handlers:
- Full CQRS command structure for all domains
Repositories:
- PostgreSQL repositories for all read models
- Bank transaction and ledger repositories
GraphQL:
- Input types, scalars, and types for all entities
- Mutations and queries
Infrastructure:
- Banking integration (Enable Banking client)
- File storage, Invoicing, Reporting, SAF-T export
- Database migrations (003-029)
Tests:
- Integration tests for GraphQL endpoints
- Domain tests
- Invoicing and reporting tests
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 22:19:42 +01:00
|
|
|
using EventFlow.Commands;
|
|
|
|
|
|
|
|
|
|
namespace Books.Api.Commands.Accounts;
|
|
|
|
|
|
2026-02-05 21:35:26 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Command handler for creating a new account.
|
|
|
|
|
/// Validates that the account number is unique within the company.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class CreateAccountCommandHandler(
|
|
|
|
|
IAccountRepository accountRepository)
|
|
|
|
|
: CommandHandler<AccountAggregate, AccountId, CreateAccountCommand>
|
Add all backend domain, commands, repositories, and tests
This commit includes all previously untracked backend files:
Domain:
- Accounts, Attachments, BankConnections, Customers
- FiscalYears, Invoices, JournalEntryDrafts
- Orders, Products, UserAccess
Commands & Handlers:
- Full CQRS command structure for all domains
Repositories:
- PostgreSQL repositories for all read models
- Bank transaction and ledger repositories
GraphQL:
- Input types, scalars, and types for all entities
- Mutations and queries
Infrastructure:
- Banking integration (Enable Banking client)
- File storage, Invoicing, Reporting, SAF-T export
- Database migrations (003-029)
Tests:
- Integration tests for GraphQL endpoints
- Domain tests
- Invoicing and reporting tests
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 22:19:42 +01:00
|
|
|
{
|
2026-02-05 21:35:26 +01:00
|
|
|
public override async Task ExecuteAsync(
|
Add all backend domain, commands, repositories, and tests
This commit includes all previously untracked backend files:
Domain:
- Accounts, Attachments, BankConnections, Customers
- FiscalYears, Invoices, JournalEntryDrafts
- Orders, Products, UserAccess
Commands & Handlers:
- Full CQRS command structure for all domains
Repositories:
- PostgreSQL repositories for all read models
- Bank transaction and ledger repositories
GraphQL:
- Input types, scalars, and types for all entities
- Mutations and queries
Infrastructure:
- Banking integration (Enable Banking client)
- File storage, Invoicing, Reporting, SAF-T export
- Database migrations (003-029)
Tests:
- Integration tests for GraphQL endpoints
- Domain tests
- Invoicing and reporting tests
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 22:19:42 +01:00
|
|
|
AccountAggregate aggregate,
|
|
|
|
|
CreateAccountCommand command,
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
{
|
2026-02-05 21:35:26 +01:00
|
|
|
// Check if an account with the same number already exists for this company
|
|
|
|
|
var existingAccount = await accountRepository.GetByCompanyAndNumberAsync(
|
|
|
|
|
command.CompanyId, command.AccountNumber, cancellationToken);
|
|
|
|
|
|
|
|
|
|
if (existingAccount != null)
|
|
|
|
|
{
|
|
|
|
|
throw new DomainException(
|
|
|
|
|
"ACCOUNT_NUMBER_EXISTS",
|
|
|
|
|
$"Account number {command.AccountNumber} already exists for this company",
|
|
|
|
|
$"Kontonummer {command.AccountNumber} eksisterer allerede");
|
|
|
|
|
}
|
|
|
|
|
|
Add all backend domain, commands, repositories, and tests
This commit includes all previously untracked backend files:
Domain:
- Accounts, Attachments, BankConnections, Customers
- FiscalYears, Invoices, JournalEntryDrafts
- Orders, Products, UserAccess
Commands & Handlers:
- Full CQRS command structure for all domains
Repositories:
- PostgreSQL repositories for all read models
- Bank transaction and ledger repositories
GraphQL:
- Input types, scalars, and types for all entities
- Mutations and queries
Infrastructure:
- Banking integration (Enable Banking client)
- File storage, Invoicing, Reporting, SAF-T export
- Database migrations (003-029)
Tests:
- Integration tests for GraphQL endpoints
- Domain tests
- Invoicing and reporting tests
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 22:19:42 +01:00
|
|
|
aggregate.Create(
|
|
|
|
|
command.CompanyId,
|
|
|
|
|
command.AccountNumber,
|
|
|
|
|
command.Name,
|
|
|
|
|
command.AccountType,
|
|
|
|
|
command.ParentId,
|
|
|
|
|
command.Description,
|
|
|
|
|
command.VatCodeId,
|
|
|
|
|
command.IsSystemAccount,
|
|
|
|
|
command.StandardAccountNumber);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class UpdateAccountCommandHandler : CommandHandler<AccountAggregate, AccountId, UpdateAccountCommand>
|
|
|
|
|
{
|
|
|
|
|
public override Task ExecuteAsync(
|
|
|
|
|
AccountAggregate aggregate,
|
|
|
|
|
UpdateAccountCommand command,
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
aggregate.Update(
|
|
|
|
|
command.Name,
|
|
|
|
|
command.ParentId,
|
|
|
|
|
command.Description,
|
|
|
|
|
command.VatCodeId);
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class DeactivateAccountCommandHandler : CommandHandler<AccountAggregate, AccountId, DeactivateAccountCommand>
|
|
|
|
|
{
|
|
|
|
|
public override Task ExecuteAsync(
|
|
|
|
|
AccountAggregate aggregate,
|
|
|
|
|
DeactivateAccountCommand command,
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
aggregate.Deactivate();
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ReactivateAccountCommandHandler : CommandHandler<AccountAggregate, AccountId, ReactivateAccountCommand>
|
|
|
|
|
{
|
|
|
|
|
public override Task ExecuteAsync(
|
|
|
|
|
AccountAggregate aggregate,
|
|
|
|
|
ReactivateAccountCommand command,
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
aggregate.Reactivate();
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|