feat(gl): expose ledger application and grpc operations

This commit is contained in:
2026-08-14 19:11:29 +03:30
parent 0b3eaa0c3d
commit 76905ab451
17 changed files with 1724 additions and 16 deletions
@@ -9,17 +9,15 @@ import (
"gl/domain/ledger"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
)
var (
ErrIdempotencyConflict = errors.New("idempotency key belongs to a different payload")
ErrIncompleteJournal = errors.New("idempotency key belongs to an unsealed journal")
ErrIdempotencyConflict = ledger.ErrIdempotencyConflict
ErrIncompleteJournal = ledger.ErrIncompleteJournal
)
type AppendResult struct {
JournalID string
AlreadyExists bool
}
type AppendResult = ledger.AppendResult
type JournalRepository struct {
database Database
@@ -76,6 +74,10 @@ func (r *JournalRepository) Append(ctx context.Context, journal ledger.Journal)
return r.resolveDuplicate(ctx, journal)
}
if err != nil {
var postgresError *pgconn.PgError
if errors.As(err, &postgresError) && postgresError.ConstraintName == "journals_one_reversal_idx" {
return AppendResult{}, ledger.ErrAlreadyReversed
}
return AppendResult{}, fmt.Errorf("insert journal: %w", err)
}