From db07d87f970422d4fc75c82715534b3ec2e1cb14 Mon Sep 17 00:00:00 2001 From: Aaron Po Date: Fri, 28 Aug 2026 00:32:13 -0400 Subject: [PATCH] Extract shared RollbackQuietlyAsync helper into DapperRepository base class Avoids duplicating the transaction-rollback-swallowing logic in every repository that needs it, starting with BreweryRepository. --- .../Database.Connection/Repository.cs | 17 ++++++++++++++ .../Domain/Domain.Entities/Entities/Photo.cs | 0 .../Repository/BreweryRepository.cs | 16 -------------- .../Features.PhotoUpload.csproj | 22 +++++++++++++++++++ 4 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 web/backend/Domain/Domain.Entities/Entities/Photo.cs create mode 100644 web/backend/Features/Features.PhotoUpload/Features.PhotoUpload.csproj diff --git a/web/backend/Database/Database.Connection/Repository.cs b/web/backend/Database/Database.Connection/Repository.cs index b4a9f08f..4bce5bb3 100644 --- a/web/backend/Database/Database.Connection/Repository.cs +++ b/web/backend/Database/Database.Connection/Repository.cs @@ -18,4 +18,21 @@ public abstract class DapperRepository(ISqlConnectionFactory connectionFactory) await connection.OpenAsync(); return connection; } + + /// + /// Rolls back , swallowing any exception the rollback itself + /// raises (for example when the provider has already completed the transaction after a + /// connection failure) so the exception that triggered the rollback is what propagates. + /// + protected static async Task RollbackQuietlyAsync(DbTransaction transaction) + { + try + { + await transaction.RollbackAsync(); + } + catch + { + // Ignore: the original exception (rethrown by the caller) is what matters here. + } + } } diff --git a/web/backend/Domain/Domain.Entities/Entities/Photo.cs b/web/backend/Domain/Domain.Entities/Entities/Photo.cs new file mode 100644 index 00000000..e69de29b diff --git a/web/backend/Features/Features.Breweries/Repository/BreweryRepository.cs b/web/backend/Features/Features.Breweries/Repository/BreweryRepository.cs index 52862175..40f3a5b0 100644 --- a/web/backend/Features/Features.Breweries/Repository/BreweryRepository.cs +++ b/web/backend/Features/Features.Breweries/Repository/BreweryRepository.cs @@ -441,22 +441,6 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) } } - /// - /// Rolls back , swallowing any exception the rollback itself - /// raises (for example when the provider has already completed the transaction after a - /// connection failure) so the exception that triggered the rollback is what propagates. - /// - private static async Task RollbackQuietlyAsync(DbTransaction transaction) - { - try - { - await transaction.RollbackAsync(); - } - catch - { - // Ignore: the original exception (rethrown by the caller) is what matters here. - } - } /// /// Composes a joined row's , , diff --git a/web/backend/Features/Features.PhotoUpload/Features.PhotoUpload.csproj b/web/backend/Features/Features.PhotoUpload/Features.PhotoUpload.csproj new file mode 100644 index 00000000..e30a34d5 --- /dev/null +++ b/web/backend/Features/Features.PhotoUpload/Features.PhotoUpload.csproj @@ -0,0 +1,22 @@ + + + net10.0 + enable + enable + Features.ImageUploads + + + + + + + + + + + + + + + +