Handle disconnected Gmail and bound CV rewrite prompts
This commit is contained in:
@@ -239,6 +239,10 @@ public sealed class GmailController : ControllerBase
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var ownerUserId = GetRequiredOwnerUserId();
|
||||
if (await GetOwnerGmailConnectionAsync(ownerUserId, cancellationToken) is null)
|
||||
{
|
||||
return GmailNotConnectedResult();
|
||||
}
|
||||
var jobs = await _db.JobApplications
|
||||
.Where(x => x.OwnerUserId == ownerUserId && !x.IsDeleted)
|
||||
.Include(x => x.Company)
|
||||
@@ -426,6 +430,10 @@ public sealed class GmailController : ControllerBase
|
||||
public async Task<ActionResult<GmailManualSyncResultDto>> ManualSync([FromBody] GmailManualSyncRequest? request, CancellationToken cancellationToken)
|
||||
{
|
||||
var ownerUserId = GetRequiredOwnerUserId();
|
||||
if (await GetOwnerGmailConnectionAsync(ownerUserId, cancellationToken) is null)
|
||||
{
|
||||
return GmailNotConnectedResult();
|
||||
}
|
||||
var jobs = await _db.JobApplications
|
||||
.Where(x => x.OwnerUserId == ownerUserId && !x.IsDeleted)
|
||||
.Include(x => x.Company)
|
||||
@@ -552,6 +560,10 @@ public sealed class GmailController : ControllerBase
|
||||
public async Task<ActionResult<GmailSuggestedJobsResponseDto>> SuggestedJobs(CancellationToken cancellationToken)
|
||||
{
|
||||
var ownerUserId = GetRequiredOwnerUserId();
|
||||
if (await GetOwnerGmailConnectionAsync(ownerUserId, cancellationToken) is null)
|
||||
{
|
||||
return GmailNotConnectedResult();
|
||||
}
|
||||
var reviewThreads = await ReviewCandidates(null, 6, cancellationToken);
|
||||
if (reviewThreads.Result is not OkObjectResult ok || ok.Value is not GmailReviewQueueResponseDto payload)
|
||||
{
|
||||
@@ -1084,6 +1096,20 @@ public sealed class GmailController : ControllerBase
|
||||
?? throw new InvalidOperationException("Authenticated user id is missing.");
|
||||
}
|
||||
|
||||
private async Task<GmailConnection?> GetOwnerGmailConnectionAsync(string ownerUserId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _gmail.GetConnectionAsync(ownerUserId, cancellationToken);
|
||||
}
|
||||
|
||||
private ActionResult GmailNotConnectedResult()
|
||||
{
|
||||
return Conflict(new
|
||||
{
|
||||
code = "gmail_not_connected",
|
||||
message = "Connect Gmail before using the Gmail review queue.",
|
||||
});
|
||||
}
|
||||
|
||||
private string GetRedirectUri()
|
||||
{
|
||||
var configured = (_cfg["Google:GmailRedirectUri"] ?? _cfg["Google:RedirectUri"] ?? "").Trim();
|
||||
|
||||
Reference in New Issue
Block a user