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.EventFlow.ReadModels;
|
|
|
|
|
using Dapper;
|
|
|
|
|
using Npgsql;
|
|
|
|
|
|
|
|
|
|
namespace Books.Api.EventFlow.Repositories;
|
|
|
|
|
|
|
|
|
|
public class JournalEntryDraftRepository(NpgsqlDataSource dataSource) : IJournalEntryDraftRepository
|
|
|
|
|
{
|
|
|
|
|
private const string SelectColumns = """
|
|
|
|
|
aggregate_id AS Id,
|
|
|
|
|
company_id AS CompanyId,
|
|
|
|
|
name AS Name,
|
|
|
|
|
voucher_number AS VoucherNumber,
|
|
|
|
|
document_date AS DocumentDate,
|
|
|
|
|
description AS Description,
|
|
|
|
|
fiscal_year_id AS FiscalYearId,
|
|
|
|
|
lines AS Lines,
|
|
|
|
|
attachment_ids AS AttachmentIds,
|
|
|
|
|
status AS Status,
|
|
|
|
|
transaction_id AS TransactionId,
|
2026-02-05 21:35:26 +01:00
|
|
|
posted_at AS PostedAt,
|
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
|
|
|
created_by AS CreatedBy,
|
|
|
|
|
create_time AS CreatedAt,
|
2026-02-05 21:35:26 +01:00
|
|
|
updated_time AS UpdatedAt,
|
|
|
|
|
extraction_data AS ExtractionData
|
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
|
|
|
""";
|
|
|
|
|
|
|
|
|
|
public async Task<JournalEntryDraftReadModelDto?> GetByIdAsync(
|
|
|
|
|
string id,
|
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
await using var connection = await dataSource.OpenConnectionAsync(cancellationToken);
|
|
|
|
|
|
|
|
|
|
var sql = $"""
|
|
|
|
|
SELECT {SelectColumns}
|
|
|
|
|
FROM journal_entry_draft_read_models
|
|
|
|
|
WHERE aggregate_id = @Id
|
|
|
|
|
""";
|
|
|
|
|
|
|
|
|
|
return await connection.QuerySingleOrDefaultAsync<JournalEntryDraftReadModelDto>(
|
|
|
|
|
sql,
|
|
|
|
|
new { Id = id });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IReadOnlyList<JournalEntryDraftReadModelDto>> GetActiveByCompanyIdAsync(
|
|
|
|
|
string companyId,
|
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
await using var connection = await dataSource.OpenConnectionAsync(cancellationToken);
|
|
|
|
|
|
|
|
|
|
var sql = $"""
|
|
|
|
|
SELECT {SelectColumns}
|
|
|
|
|
FROM journal_entry_draft_read_models
|
|
|
|
|
WHERE company_id = @CompanyId AND status = 'active'
|
|
|
|
|
ORDER BY updated_time DESC
|
|
|
|
|
""";
|
|
|
|
|
|
|
|
|
|
var result = await connection.QueryAsync<JournalEntryDraftReadModelDto>(
|
|
|
|
|
sql,
|
|
|
|
|
new { CompanyId = companyId });
|
|
|
|
|
|
|
|
|
|
return result.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IReadOnlyList<JournalEntryDraftReadModelDto>> GetByCompanyIdAsync(
|
|
|
|
|
string companyId,
|
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
await using var connection = await dataSource.OpenConnectionAsync(cancellationToken);
|
|
|
|
|
|
|
|
|
|
var sql = $"""
|
|
|
|
|
SELECT {SelectColumns}
|
|
|
|
|
FROM journal_entry_draft_read_models
|
|
|
|
|
WHERE company_id = @CompanyId
|
|
|
|
|
ORDER BY updated_time DESC
|
|
|
|
|
""";
|
|
|
|
|
|
|
|
|
|
var result = await connection.QueryAsync<JournalEntryDraftReadModelDto>(
|
|
|
|
|
sql,
|
|
|
|
|
new { CompanyId = companyId });
|
|
|
|
|
|
|
|
|
|
return result.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|