refactor(application): change GetOAuth2AuthorizationUrlQuery to look up account by Username instead of Id

This commit is contained in:
2026-08-17 16:05:16 +02:00
parent 408ad14c9f
commit c189a2d6ef

View File

@@ -17,7 +17,7 @@ public record GetOAuth2AuthorizationUrlQuery : IRequest<string>
/// <summary>
/// ID of the email account to authorize.
/// </summary>
public required int AccountId { get; init; }
public required string Username { get; init; }
/// <summary>
/// The redirect URI registered with the OAuth2 provider.
@@ -32,8 +32,8 @@ public class GetOAuth2AuthorizationUrlQueryHandler(
{
public async Task<string> 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(