📌 Description
Several handlers likely hand-roll BEGIN/COMMIT/ROLLBACK transaction boilerplate around pgx calls. A small WithTx(ctx, fn) helper in internal/db/db.go would reduce duplication and the risk of a forgotten rollback-on-error path.
🧩 Requirements and context
- Add a
WithTx(ctx context.Context, fn func(pgx.Tx) error) error helper that commits on nil error and rolls back otherwise.
- Ensure panics inside
fn still trigger a rollback (recover + re-panic).
- Migrate at least one existing multi-statement handler to use the new helper as a proof of adoption.
🛠️ Suggested execution
- Add the helper to
internal/db/db.go.
- Add a unit test covering commit, explicit error rollback, and panic-triggers-rollback.
- Refactor one handler (e.g. in
internal/handlers/) that currently hand-rolls a transaction.
✅ Acceptance criteria
🔒 Security notes
Reduces the risk of a forgotten rollback leaving a transaction open/locked under error conditions, which is a minor availability concern under load.
📋 Guidelines
- Minimum 95% test coverage
- Clear documentation
- Timeframe: 96 hours
📌 Description
Several handlers likely hand-roll
BEGIN/COMMIT/ROLLBACKtransaction boilerplate around pgx calls. A smallWithTx(ctx, fn)helper in internal/db/db.go would reduce duplication and the risk of a forgotten rollback-on-error path.🧩 Requirements and context
WithTx(ctx context.Context, fn func(pgx.Tx) error) errorhelper that commits on nil error and rolls back otherwise.fnstill trigger a rollback (recover + re-panic).🛠️ Suggested execution
internal/db/db.go.internal/handlers/) that currently hand-rolls a transaction.✅ Acceptance criteria
WithTxhelper exists with commit/rollback/panic-safety tests.🔒 Security notes
Reduces the risk of a forgotten rollback leaving a transaction open/locked under error conditions, which is a minor availability concern under load.
📋 Guidelines