diff --git a/src/core/DigitalData.MessagingService.Application/OAuth2/Queries/GetOAuth2AuthorizationUrlQuery.cs b/src/core/DigitalData.MessagingService.Application/OAuth2/Queries/GetOAuth2AuthorizationUrlQuery.cs index c07d760..6dadbce 100644 --- a/src/core/DigitalData.MessagingService.Application/OAuth2/Queries/GetOAuth2AuthorizationUrlQuery.cs +++ b/src/core/DigitalData.MessagingService.Application/OAuth2/Queries/GetOAuth2AuthorizationUrlQuery.cs @@ -17,7 +17,7 @@ public record GetOAuth2AuthorizationUrlQuery : IRequest /// /// ID of the email account to authorize. /// - public required int AccountId { get; init; } + public required string Username { get; init; } /// /// The redirect URI registered with the OAuth2 provider. @@ -32,8 +32,8 @@ public class GetOAuth2AuthorizationUrlQueryHandler( { public async Task Handle(GetOAuth2AuthorizationUrlQuery request, CancellationToken cancellationToken) { - var account = await Repo.GetByIdAsync(request.AccountId, cancellationToken) - ?? throw new NotFoundException($"No email account found with Id: {request.AccountId}."); + var account = await Repo.FindFirstAsync(e => e.Username == request.Username, cancellationToken) + ?? throw new NotFoundException($"No email account found with username: {request.Username}."); if (account.OAuth2Provider == OAuth2Provider.None) throw new BadRequestException(