diff --git a/web/backend/API/API.Specs/Steps/AuthSteps.cs b/web/backend/API/API.Specs/Steps/AuthSteps.cs index 444fa624..a49f1308 100644 --- a/web/backend/API/API.Specs/Steps/AuthSteps.cs +++ b/web/backend/API/API.Specs/Steps/AuthSteps.cs @@ -1020,9 +1020,7 @@ public class AuthSteps(ScenarioContext scenario) public async Task WhenISubmitAResendConfirmationRequestWithoutAnAccessToken() { HttpClient client = GetClient(); - Guid userId = scenario.TryGetValue(RegisteredUserIdKey, out Guid id) - ? id - : Guid.NewGuid(); + Guid userId = scenario.TryGetValue(RegisteredUserIdKey, out Guid id) ? id : Guid.NewGuid(); HttpRequestMessage requestMessage = new( HttpMethod.Post, diff --git a/web/backend/Database/Database.Seed/Database.Seed.csproj b/web/backend/Database/Database.Seed/Database.Seed.csproj index 8c02e66d..10fca1b3 100644 --- a/web/backend/Database/Database.Seed/Database.Seed.csproj +++ b/web/backend/Database/Database.Seed/Database.Seed.csproj @@ -8,20 +8,23 @@ - - - - + + + + - - - - - + + + + + - + diff --git a/web/backend/Database/Database.Seed/DatabaseHelpers/ConnectionStrings.cs b/web/backend/Database/Database.Seed/DatabaseHelpers/ConnectionStrings.cs index cc0733f2..f43c8bc8 100644 --- a/web/backend/Database/Database.Seed/DatabaseHelpers/ConnectionStrings.cs +++ b/web/backend/Database/Database.Seed/DatabaseHelpers/ConnectionStrings.cs @@ -12,5 +12,6 @@ public class ConnectionStrings public static string GetSqlServerConnectionString(IConfiguration configuration) => SqlConnectionStringHelper.BuildConnectionString(configuration); - public static string SqliteConnectionString => "Data Source=SeedData/biergarten_seed_2026-08-24T01-52-09.841693Z.sqlite"; + public static string SqliteConnectionString => + "Data Source=SeedData/biergarten_seed_2026-08-24T01-52-09.841693Z.sqlite"; } diff --git a/web/backend/Database/Database.Seed/Geocoding/NominatimReverseGeocoder.cs b/web/backend/Database/Database.Seed/Geocoding/NominatimReverseGeocoder.cs index 28d82c71..91aef2ef 100644 --- a/web/backend/Database/Database.Seed/Geocoding/NominatimReverseGeocoder.cs +++ b/web/backend/Database/Database.Seed/Geocoding/NominatimReverseGeocoder.cs @@ -79,8 +79,8 @@ public sealed class NominatimReverseGeocoder : IDisposable string addressLine1 = string.Join( ' ', - new[] { response.Address.HouseNumber, response.Address.Road }.Where( - part => !string.IsNullOrWhiteSpace(part) + new[] { response.Address.HouseNumber, response.Address.Road }.Where(part => + !string.IsNullOrWhiteSpace(part) ) ); diff --git a/web/backend/Database/Database.Seed/Program.cs b/web/backend/Database/Database.Seed/Program.cs index a504e03e..9473da33 100644 --- a/web/backend/Database/Database.Seed/Program.cs +++ b/web/backend/Database/Database.Seed/Program.cs @@ -26,9 +26,7 @@ static async Task RunAsync() { try { - IConfiguration configuration = new ConfigurationBuilder() - .AddEnvironmentVariables() - .Build(); + IConfiguration configuration = new ConfigurationBuilder().AddEnvironmentVariables().Build(); ServiceCollection services = []; services.AddSingleton(configuration); @@ -39,21 +37,17 @@ static async Task RunAsync() await using ServiceProvider provider = services.BuildServiceProvider(); - IBreweryRepository breweryRepository = - provider.GetRequiredService(); - ILocationRepository locationRepository = - provider.GetRequiredService(); - UserManager userManager = - provider.GetRequiredService>(); + IBreweryRepository breweryRepository = provider.GetRequiredService(); + ILocationRepository locationRepository = provider.GetRequiredService(); + UserManager userManager = provider.GetRequiredService< + UserManager + >(); - AnsiConsole.Write(new Rule("[bold green]Database Seeder[/]") - .LeftJustified()); - AnsiConsole.MarkupLine( - "[grey]Connecting to SQLite source and loading seed data...[/]"); + AnsiConsole.Write(new Rule("[bold green]Database Seeder[/]").LeftJustified()); + AnsiConsole.MarkupLine("[grey]Connecting to SQLite source and loading seed data...[/]"); AnsiConsole.WriteLine(); - PipelineSeedDataReader reader = - new(ConnectionStrings.SqliteConnectionString); + PipelineSeedDataReader reader = new(ConnectionStrings.SqliteConnectionString); SeedData seedData = null!; IReadOnlyList postedByIds = []; @@ -79,16 +73,14 @@ static async Task RunAsync() AnsiConsole.Write(BuildBreweryTable(seedData.Breweries)); AnsiConsole.WriteLine(); - AnsiConsole.MarkupLine( - $"[green]✓[/] Loaded [bold]{seedData.Users.Count}[/] users."); + AnsiConsole.MarkupLine($"[green]✓[/] Loaded [bold]{seedData.Users.Count}[/] users."); AnsiConsole.Write(BuildUserTable(seedData.Users)); AnsiConsole.WriteLine(); AnsiConsole.WriteLine("Seed data loaded successfully."); AnsiConsole.Write( - new Rule("[bold green]Loading seed data into target database.[/]") - .LeftJustified() + new Rule("[bold green]Loading seed data into target database.[/]").LeftJustified() ); await AnsiConsole @@ -193,8 +185,7 @@ static async Task LoadBreweriesIntoDatabaseAsync( const string placeholderAddressLine1 = "Address unavailable"; if (posterUserIds.Count == 0) - throw new InvalidOperationException( - "Cannot load breweries without any registered users."); + throw new InvalidOperationException("Cannot load breweries without any registered users."); for (int i = 0; i < breweries.Count; i++) { @@ -294,4 +285,4 @@ static Table BuildUserTable(IReadOnlyList users) } return table; -} \ No newline at end of file +} diff --git a/web/backend/Domain/Domain.Entities/Entities/UserAccount.cs b/web/backend/Domain/Domain.Entities/Entities/UserAccount.cs index e4dab7c6..1a07ff2e 100644 --- a/web/backend/Domain/Domain.Entities/Entities/UserAccount.cs +++ b/web/backend/Domain/Domain.Entities/Entities/UserAccount.cs @@ -18,6 +18,5 @@ public sealed class UserAccount public byte[]? RowVersion { get; set; } // Navigation properties - public UserCredential? UserCredential { get; set; } - + public UserCredential? UserCredential { get; set; } } diff --git a/web/backend/Features/Features.Auth.Tests/Commands/RegisterUserHandlerTests.cs b/web/backend/Features/Features.Auth.Tests/Commands/RegisterUserHandlerTests.cs index d51279c2..367b50cc 100644 --- a/web/backend/Features/Features.Auth.Tests/Commands/RegisterUserHandlerTests.cs +++ b/web/backend/Features/Features.Auth.Tests/Commands/RegisterUserHandlerTests.cs @@ -103,7 +103,11 @@ public class RegisterUserHandlerTests .Setup(x => x.CreateAsync(It.IsAny(), command.Password)) .ReturnsAsync( IdentityResult.Failed( - new IdentityError { Code = "DuplicateUserName", Description = "Username taken." } + new IdentityError + { + Code = "DuplicateUserName", + Description = "Username taken.", + } ) ); diff --git a/web/backend/Features/Features.Auth.Tests/Commands/ResendConfirmationEmailHandlerTests.cs b/web/backend/Features/Features.Auth.Tests/Commands/ResendConfirmationEmailHandlerTests.cs index c275e09d..eae3ab0f 100644 --- a/web/backend/Features/Features.Auth.Tests/Commands/ResendConfirmationEmailHandlerTests.cs +++ b/web/backend/Features/Features.Auth.Tests/Commands/ResendConfirmationEmailHandlerTests.cs @@ -14,7 +14,8 @@ public class ResendConfirmationEmailHandlerTests private readonly ResendConfirmationEmailHandler _handler; private readonly Mock _mediatorMock = new(); private readonly Mock _tokenServiceMock = new(); - private readonly Mock> _userManagerMock = UserManagerMockFactory.Create(); + private readonly Mock> _userManagerMock = + UserManagerMockFactory.Create(); public ResendConfirmationEmailHandlerTests() { diff --git a/web/backend/Features/Features.Auth.Tests/Queries/LoginHandlerTests.cs b/web/backend/Features/Features.Auth.Tests/Queries/LoginHandlerTests.cs index 484b7414..157b3bdb 100644 --- a/web/backend/Features/Features.Auth.Tests/Queries/LoginHandlerTests.cs +++ b/web/backend/Features/Features.Auth.Tests/Queries/LoginHandlerTests.cs @@ -87,7 +87,9 @@ public class LoginHandlerTests ApplicationUser user = new() { Id = Guid.NewGuid(), UserName = username }; _userManagerMock.Setup(x => x.FindByNameAsync(username)).ReturnsAsync(user); - _userManagerMock.Setup(x => x.CheckPasswordAsync(user, It.IsAny())).ReturnsAsync(false); + _userManagerMock + .Setup(x => x.CheckPasswordAsync(user, It.IsAny())) + .ReturnsAsync(false); Func> act = async () => await _handler.Handle(new LoginCommand(username, "password"), CancellationToken.None); @@ -104,7 +106,9 @@ public class LoginHandlerTests ApplicationUser user = new() { Id = Guid.NewGuid(), UserName = username }; _userManagerMock.Setup(x => x.FindByNameAsync(username)).ReturnsAsync(user); - _userManagerMock.Setup(x => x.CheckPasswordAsync(user, It.IsAny())).ReturnsAsync(false); + _userManagerMock + .Setup(x => x.CheckPasswordAsync(user, It.IsAny())) + .ReturnsAsync(false); Func> act = async () => await _handler.Handle( diff --git a/web/backend/Features/Features.Auth/Commands/ConfirmUser/ConfirmUserHandler.cs b/web/backend/Features/Features.Auth/Commands/ConfirmUser/ConfirmUserHandler.cs index 90387e45..a64495a7 100644 --- a/web/backend/Features/Features.Auth/Commands/ConfirmUser/ConfirmUserHandler.cs +++ b/web/backend/Features/Features.Auth/Commands/ConfirmUser/ConfirmUserHandler.cs @@ -29,9 +29,7 @@ public class ConfirmUserHandler( request.Token ); - ApplicationUser? user = await userManager.FindByIdAsync( - validatedToken.UserId.ToString() - ); + ApplicationUser? user = await userManager.FindByIdAsync(validatedToken.UserId.ToString()); if (user == null) throw new UnauthorizedException("User account not found"); diff --git a/web/backend/Features/Features.Auth/Commands/DeleteAccount/DeleteAccountHandler.cs b/web/backend/Features/Features.Auth/Commands/DeleteAccount/DeleteAccountHandler.cs index dd05b719..c99fa263 100644 --- a/web/backend/Features/Features.Auth/Commands/DeleteAccount/DeleteAccountHandler.cs +++ b/web/backend/Features/Features.Auth/Commands/DeleteAccount/DeleteAccountHandler.cs @@ -27,7 +27,9 @@ public class DeleteAccountHandler(UserManager userManager) throw new ConflictException( "Account cannot be deleted while it still has associated posts, comments, photos, or follows." ); - throw new ConflictException(string.Join("; ", result.Errors.Select(e => e.Description))); + throw new ConflictException( + string.Join("; ", result.Errors.Select(e => e.Description)) + ); } } } diff --git a/web/backend/Features/Features.Auth/Commands/Login/LoginHandler.cs b/web/backend/Features/Features.Auth/Commands/Login/LoginHandler.cs index f8bb07dd..aee0a4c9 100644 --- a/web/backend/Features/Features.Auth/Commands/Login/LoginHandler.cs +++ b/web/backend/Features/Features.Auth/Commands/Login/LoginHandler.cs @@ -18,7 +18,10 @@ public class LoginHandler(UserManager userManager, ITokenServic /// Thrown when the username does not match any account or the supplied password does not match /// the stored hash. /// - public async Task Handle(LoginCommand request, CancellationToken cancellationToken) + public async Task Handle( + LoginCommand request, + CancellationToken cancellationToken + ) { ApplicationUser user = await userManager.FindByNameAsync(request.Username) diff --git a/web/backend/Features/Features.Auth/Commands/RegisterUser/RegisterUserHandler.cs b/web/backend/Features/Features.Auth/Commands/RegisterUser/RegisterUserHandler.cs index 93e8629d..889b9b3c 100644 --- a/web/backend/Features/Features.Auth/Commands/RegisterUser/RegisterUserHandler.cs +++ b/web/backend/Features/Features.Auth/Commands/RegisterUser/RegisterUserHandler.cs @@ -43,7 +43,9 @@ public class RegisterUserHandler( { if (result.Errors.Any(e => e.Code is "DuplicateUserName" or "DuplicateEmail")) throw new ConflictException("Username or email already exists"); - throw new ConflictException(string.Join("; ", result.Errors.Select(e => e.Description))); + throw new ConflictException( + string.Join("; ", result.Errors.Select(e => e.Description)) + ); } string accessToken = tokenService.GenerateAccessToken(user.Id, user.UserName); @@ -51,7 +53,13 @@ public class RegisterUserHandler( string confirmationToken = tokenService.GenerateConfirmationToken(user.Id, user.UserName); if (string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(refreshToken)) - return new RegistrationPayload(user.Id, user.UserName, string.Empty, string.Empty, false); + return new RegistrationPayload( + user.Id, + user.UserName, + string.Empty, + string.Empty, + false + ); bool emailSent = false; try @@ -68,6 +76,12 @@ public class RegisterUserHandler( Console.WriteLine("Could not send email."); } - return new RegistrationPayload(user.Id, user.UserName, refreshToken, accessToken, emailSent); + return new RegistrationPayload( + user.Id, + user.UserName, + refreshToken, + accessToken, + emailSent + ); } } diff --git a/web/backend/Features/Features.Auth/Commands/UpdateEmail/UpdateEmailCommand.cs b/web/backend/Features/Features.Auth/Commands/UpdateEmail/UpdateEmailCommand.cs index 78c4dfb3..b8818c81 100644 --- a/web/backend/Features/Features.Auth/Commands/UpdateEmail/UpdateEmailCommand.cs +++ b/web/backend/Features/Features.Auth/Commands/UpdateEmail/UpdateEmailCommand.cs @@ -11,4 +11,5 @@ namespace Features.Auth.Commands.UpdateEmail; /// The authenticated caller's own ID, extracted from the access token -- never bind this from /// client-supplied input. /// -public record UpdateEmailCommand(Guid UserAccountId, string NewEmail) : IRequest; +public record UpdateEmailCommand(Guid UserAccountId, string NewEmail) + : IRequest; diff --git a/web/backend/Features/Features.Auth/Commands/UpdateEmail/UpdateEmailHandler.cs b/web/backend/Features/Features.Auth/Commands/UpdateEmail/UpdateEmailHandler.cs index 1507f3a9..8ef0613d 100644 --- a/web/backend/Features/Features.Auth/Commands/UpdateEmail/UpdateEmailHandler.cs +++ b/web/backend/Features/Features.Auth/Commands/UpdateEmail/UpdateEmailHandler.cs @@ -31,7 +31,9 @@ public class UpdateEmailHandler(UserManager userManager) { if (result.Errors.Any(e => e.Code == "DuplicateEmail")) throw new ConflictException("Email address already exists"); - throw new ConflictException(string.Join("; ", result.Errors.Select(e => e.Description))); + throw new ConflictException( + string.Join("; ", result.Errors.Select(e => e.Description)) + ); } return new UpdateEmailPayload(user.Id, user.Email, user.EmailConfirmed); diff --git a/web/backend/Features/Features.Auth/Commands/UpdatePassword/UpdatePasswordHandler.cs b/web/backend/Features/Features.Auth/Commands/UpdatePassword/UpdatePasswordHandler.cs index 03bff2b2..a0a9e8ec 100644 --- a/web/backend/Features/Features.Auth/Commands/UpdatePassword/UpdatePasswordHandler.cs +++ b/web/backend/Features/Features.Auth/Commands/UpdatePassword/UpdatePasswordHandler.cs @@ -34,7 +34,9 @@ public class UpdatePasswordHandler(UserManager userManager) { if (result.Errors.Any(e => e.Code == "PasswordMismatch")) throw new UnauthorizedException("Current password is incorrect"); - throw new ConflictException(string.Join("; ", result.Errors.Select(e => e.Description))); + throw new ConflictException( + string.Join("; ", result.Errors.Select(e => e.Description)) + ); } return new UpdatePasswordPayload(user.Id, DateTime.UtcNow); diff --git a/web/backend/Features/Features.Auth/Commands/UpdateProfile/UpdateProfileHandler.cs b/web/backend/Features/Features.Auth/Commands/UpdateProfile/UpdateProfileHandler.cs index eb47adec..55282ab1 100644 --- a/web/backend/Features/Features.Auth/Commands/UpdateProfile/UpdateProfileHandler.cs +++ b/web/backend/Features/Features.Auth/Commands/UpdateProfile/UpdateProfileHandler.cs @@ -31,7 +31,9 @@ public class UpdateProfileHandler(UserManager userManager) IdentityResult result = await userManager.UpdateAsync(user); if (!result.Succeeded) - throw new ConflictException(string.Join("; ", result.Errors.Select(e => e.Description))); + throw new ConflictException( + string.Join("; ", result.Errors.Select(e => e.Description)) + ); return new UpdateProfilePayload(user.Id, user.FirstName, user.LastName, user.DateOfBirth); } diff --git a/web/backend/Features/Features.Auth/Commands/UpdateUsername/UpdateUsernameHandler.cs b/web/backend/Features/Features.Auth/Commands/UpdateUsername/UpdateUsernameHandler.cs index b19828ba..22af13d3 100644 --- a/web/backend/Features/Features.Auth/Commands/UpdateUsername/UpdateUsernameHandler.cs +++ b/web/backend/Features/Features.Auth/Commands/UpdateUsername/UpdateUsernameHandler.cs @@ -26,7 +26,9 @@ public class UpdateUsernameHandler(UserManager userManager) { if (result.Errors.Any(e => e.Code == "DuplicateUserName")) throw new ConflictException("Username already exists"); - throw new ConflictException(string.Join("; ", result.Errors.Select(e => e.Description))); + throw new ConflictException( + string.Join("; ", result.Errors.Select(e => e.Description)) + ); } return new UpdateUsernamePayload(user.Id, user.UserName); diff --git a/web/backend/Features/Features.Auth/Controllers/AuthController.cs b/web/backend/Features/Features.Auth/Controllers/AuthController.cs index 51d7751d..f49ebc49 100644 --- a/web/backend/Features/Features.Auth/Controllers/AuthController.cs +++ b/web/backend/Features/Features.Auth/Controllers/AuthController.cs @@ -71,7 +71,9 @@ public class AuthController(IMediator mediator) : ControllerBase /// [AllowAnonymous] [HttpPost("login")] - public async Task>> Login([FromBody] LoginCommand command) + public async Task>> Login( + [FromBody] LoginCommand command + ) { LoginPayload payload = await mediator.Send(command); return Ok( diff --git a/web/backend/Features/Features.Auth/Features.Auth.csproj b/web/backend/Features/Features.Auth/Features.Auth.csproj index 7a6ad02a..96377056 100644 --- a/web/backend/Features/Features.Auth/Features.Auth.csproj +++ b/web/backend/Features/Features.Auth/Features.Auth.csproj @@ -22,6 +22,6 @@ - + diff --git a/web/backend/Features/Features.Auth/Identity/DapperUserStore.cs b/web/backend/Features/Features.Auth/Identity/DapperUserStore.cs index 24b4433e..e43b0805 100644 --- a/web/backend/Features/Features.Auth/Identity/DapperUserStore.cs +++ b/web/backend/Features/Features.Auth/Identity/DapperUserStore.cs @@ -19,8 +19,7 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) IUserPasswordStore, IUserEmailStore { - private const string SelectUserSql = - """ + private const string SelectUserSql = """ SELECT UserAccountID AS Id, Username AS UserName, FirstName, LastName, Email, DateOfBirth FROM dbo.UserAccount """; @@ -33,8 +32,10 @@ public sealed class DapperUserStore(ISqlConnectionFactory connectionFactory) Task.FromResult(user.Id.ToString()); /// - public Task GetUserNameAsync(ApplicationUser user, CancellationToken cancellationToken) => - Task.FromResult(user.UserName); + public Task GetUserNameAsync( + ApplicationUser user, + CancellationToken cancellationToken + ) => Task.FromResult(user.UserName); /// public Task SetUserNameAsync( diff --git a/web/backend/Features/Features.Auth/Services/ITokenService.cs b/web/backend/Features/Features.Auth/Services/ITokenService.cs index de303f6e..3a61e917 100644 --- a/web/backend/Features/Features.Auth/Services/ITokenService.cs +++ b/web/backend/Features/Features.Auth/Services/ITokenService.cs @@ -21,7 +21,12 @@ public enum TokenType public record ValidatedToken(Guid UserId, string Username, ClaimsPrincipal Principal); /// Represents the result of refreshing a user's session. -public record RefreshTokenResult(Guid UserId, string Username, string RefreshToken, string AccessToken); +public record RefreshTokenResult( + Guid UserId, + string Username, + string RefreshToken, + string AccessToken +); /// /// Defines the expiration windows, in hours, for each type of token issued by . @@ -61,7 +66,6 @@ public interface ITokenService /// string GenerateConfirmationToken(Guid userId, string username); - /// Validates an access token's signature and expiration and extracts the caller's identity. /// /// Thrown when the token is missing required claims, has a malformed user ID, or otherwise fails validation. diff --git a/web/backend/Features/Features.Breweries/Commands/CreateBrewery/CreateBreweryValidator.cs b/web/backend/Features/Features.Breweries/Commands/CreateBrewery/CreateBreweryValidator.cs index 227d5e90..e2f08885 100644 --- a/web/backend/Features/Features.Breweries/Commands/CreateBrewery/CreateBreweryValidator.cs +++ b/web/backend/Features/Features.Breweries/Commands/CreateBrewery/CreateBreweryValidator.cs @@ -23,9 +23,7 @@ public class CreateBreweryValidator : AbstractValidator RuleFor(x => x.Location).NotNull().WithMessage("Location is required."); - RuleFor(x => x.Location.CityId) - .NotEmpty() - .WithMessage("CityId is required."); + RuleFor(x => x.Location.CityId).NotEmpty().WithMessage("CityId is required."); RuleFor(x => x.Location.AddressLine1) .NotEmpty() diff --git a/web/backend/Features/Features.Breweries/Repository/BreweryRepository.cs b/web/backend/Features/Features.Breweries/Repository/BreweryRepository.cs index a4053853..792d3052 100644 --- a/web/backend/Features/Features.Breweries/Repository/BreweryRepository.cs +++ b/web/backend/Features/Features.Breweries/Repository/BreweryRepository.cs @@ -70,8 +70,7 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) } /// - public async Task> GetAllAsync(int? limit, - int? offset) + public async Task> GetAllAsync(int? limit, int? offset) { await using DbConnection connection = await CreateConnection(); return await connection.QueryAsync< @@ -122,25 +121,24 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) public async Task UpdateAsync(BreweryPost brewery) { await using DbConnection connection = await CreateConnection(); - await using DbTransaction transaction = - await connection.BeginTransactionAsync(); + await using DbTransaction transaction = await connection.BeginTransactionAsync(); try { bool breweryExists = await connection.ExecuteScalarAsync( - new CommandDefinition( - """ - SELECT 1 FROM - dbo.BreweryPost - WHERE - BreweryPostID = @BreweryPostId - """, - new { brewery.BreweryPostId }, - transaction - ) + new CommandDefinition( + """ + SELECT 1 FROM + dbo.BreweryPost + WHERE + BreweryPostID = @BreweryPostId + """, + new { brewery.BreweryPostId }, + transaction ) - is not null; + ) + is not null; if (!breweryExists) throw new NotFoundException("Brewery not found."); @@ -149,13 +147,13 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) { bool cityExists = await connection.ExecuteScalarAsync( - new CommandDefinition( - "SELECT 1 FROM dbo.City WHERE CityID = @CityId", - new { brewery.Location.CityId }, - transaction - ) + new CommandDefinition( + "SELECT 1 FROM dbo.City WHERE CityID = @CityId", + new { brewery.Location.CityId }, + transaction ) - is not null; + ) + is not null; if (!cityExists) throw new NotFoundException("City not found."); @@ -207,17 +205,17 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) { bool locationExists = await connection.ExecuteScalarAsync( - new CommandDefinition( - """ - SELECT 1 - FROM dbo.BreweryPostLocation - WHERE BreweryPostID = @BreweryPostId - """, - new { brewery.BreweryPostId }, - transaction - ) + new CommandDefinition( + """ + SELECT 1 + FROM dbo.BreweryPostLocation + WHERE BreweryPostID = @BreweryPostId + """, + new { brewery.BreweryPostId }, + transaction ) - is not null; + ) + is not null; if (locationExists) await connection.ExecuteAsync( @@ -288,9 +286,9 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) } return await GetByIdAsync(brewery.BreweryPostId) - ?? throw new InvalidOperationException( - $"Brewery '{brewery.BreweryPostId}' was not found after a successful update." - ); + ?? throw new InvalidOperationException( + $"Brewery '{brewery.BreweryPostId}' was not found after a successful update." + ); } /// @@ -315,49 +313,47 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory) public async Task CreateAsync(BreweryPost brewery) { if (brewery.Location is null) - throw new ArgumentException( - "Location must be provided when creating a brewery."); + throw new ArgumentException("Location must be provided when creating a brewery."); await using DbConnection connection = await CreateConnection(); - await using DbTransaction transaction = - await connection.BeginTransactionAsync(); + await using DbTransaction transaction = await connection.BeginTransactionAsync(); try { bool userExists = await connection.ExecuteScalarAsync( - new CommandDefinition( - """ - SELECT 1 - FROM - dbo.UserAccount - WHERE - UserAccountID = @PostedById - """, - new { brewery.PostedById }, - transaction - ) + new CommandDefinition( + """ + SELECT 1 + FROM + dbo.UserAccount + WHERE + UserAccountID = @PostedById + """, + new { brewery.PostedById }, + transaction ) - is not null; + ) + is not null; if (!userExists) throw new NotFoundException("User not found."); bool cityExists = await connection.ExecuteScalarAsync( - new CommandDefinition( - """ - SELECT 1 - FROM - dbo.City - WHERE - CityID = @CityId - """, - new { brewery.Location.CityId }, - transaction - ) + new CommandDefinition( + """ + SELECT 1 + FROM + dbo.City + WHERE + CityID = @CityId + """, + new { brewery.Location.CityId }, + transaction ) - is not null; + ) + is not null; if (!cityExists) throw new NotFoundException("City not found."); diff --git a/web/backend/Features/Features.Locations/Repository/LocationRepository.cs b/web/backend/Features/Features.Locations/Repository/LocationRepository.cs index e716cc9b..d904006a 100644 --- a/web/backend/Features/Features.Locations/Repository/LocationRepository.cs +++ b/web/backend/Features/Features.Locations/Repository/LocationRepository.cs @@ -51,7 +51,8 @@ public class LocationRepository(ISqlConnectionFactory connectionFactory) WHERE CityName = @CityName AND StateProvinceID = @StateProvinceId """, new { location.CityName, StateProvinceId = stateProvinceId } - ) is not null; + ) + is not null; if (!cityExists) await connection.ExecuteAsync( @@ -83,7 +84,8 @@ public class LocationRepository(ISqlConnectionFactory connectionFactory) WHERE ISO3166_1 = @ISO3166_1 """, new { ISO3166_1 = isoCode } - ) is not null; + ) + is not null; if (!exists) // A concurrent caller may create this country between the check above and here; that @@ -128,7 +130,8 @@ public class LocationRepository(ISqlConnectionFactory connectionFactory) WHERE ISO3166_2 = @ISO3166_2 """, new { ISO3166_2 = isoCode } - ) is not null; + ) + is not null; if (!exists) await connection.ExecuteAsync( diff --git a/web/backend/Infrastructure/Infrastructure.Sql/SqlConnectionStringHelper.cs b/web/backend/Infrastructure/Infrastructure.Sql/SqlConnectionStringHelper.cs index 9c03babb..c639c3af 100644 --- a/web/backend/Infrastructure/Infrastructure.Sql/SqlConnectionStringHelper.cs +++ b/web/backend/Infrastructure/Infrastructure.Sql/SqlConnectionStringHelper.cs @@ -52,8 +52,7 @@ public static class SqlConnectionStringHelper return !bool.TryParse( configuration["DB_TRUST_SERVER_CERTIFICATE"], out bool trustServerCertificate - ) - || trustServerCertificate; + ) || trustServerCertificate; } private static string Required(IConfiguration configuration, string key) => diff --git a/web/backend/Infrastructure/Infrastructure.Sql/SqlErrorCodes.cs b/web/backend/Infrastructure/Infrastructure.Sql/SqlErrorCodes.cs index aecd1361..5a55e566 100644 --- a/web/backend/Infrastructure/Infrastructure.Sql/SqlErrorCodes.cs +++ b/web/backend/Infrastructure/Infrastructure.Sql/SqlErrorCodes.cs @@ -1 +1 @@ -namespace Infrastructure.Sql; \ No newline at end of file +namespace Infrastructure.Sql;