fix(email): retire legacy SMTP follow-up
Keep follow-up draft generation but remove the direct application SMTP delivery boundary. Route users to the provider-aware Job email flow and return 410 for legacy API callers.
This commit is contained in:
@@ -25,9 +25,7 @@ namespace JobTrackerApi.Controllers
|
||||
{
|
||||
private readonly JobTrackerContext _db;
|
||||
private readonly ISummarizerService _summarizer;
|
||||
private readonly IAppEmailSender _email;
|
||||
private readonly UserManager<ApplicationUser> _users;
|
||||
private readonly ILogger<JobApplicationsController> _logger;
|
||||
private readonly ICvTemplateRenderer _cvTemplateRenderer;
|
||||
private readonly ICvPdfExporter _cvPdfExporter;
|
||||
private readonly AnalyticsService _analytics;
|
||||
@@ -35,14 +33,12 @@ namespace JobTrackerApi.Controllers
|
||||
private readonly IMemoryCache _cache;
|
||||
private readonly IApplicationChecklistService _checklist;
|
||||
|
||||
public JobApplicationsController(JobTrackerContext db, ISummarizerService summarizer, IAppEmailSender email, UserManager<ApplicationUser> users, ILogger<JobApplicationsController> logger, ICvTemplateRenderer? cvTemplateRenderer = null, ICvPdfExporter? cvPdfExporter = null, AnalyticsService? analytics = null, IJobCvMatchService? matchService = null, IMemoryCache? cache = null, IApplicationChecklistService? checklist = null)
|
||||
public JobApplicationsController(JobTrackerContext db, ISummarizerService summarizer, UserManager<ApplicationUser> users, ICvTemplateRenderer? cvTemplateRenderer = null, ICvPdfExporter? cvPdfExporter = null, AnalyticsService? analytics = null, IJobCvMatchService? matchService = null, IMemoryCache? cache = null, IApplicationChecklistService? checklist = null)
|
||||
{
|
||||
_checklist = checklist ?? new ApplicationChecklistService(db);
|
||||
_db = db;
|
||||
_summarizer = summarizer;
|
||||
_email = email;
|
||||
_users = users;
|
||||
_logger = logger;
|
||||
_cvTemplateRenderer = cvTemplateRenderer ?? new CvTemplateRenderer();
|
||||
_cvPdfExporter = cvPdfExporter ?? new ThrowingCvPdfExporter();
|
||||
_analytics = analytics ?? new AnalyticsService(db);
|
||||
@@ -2252,55 +2248,13 @@ Job description:
|
||||
}
|
||||
|
||||
[HttpPost("{id:int}/send-followup")]
|
||||
public async Task<IActionResult> SendFollowUp([FromRoute] int id, [FromBody] SendFollowUpRequest request, CancellationToken cancellationToken)
|
||||
public IActionResult SendFollowUp([FromRoute] int id, [FromBody] SendFollowUpRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var job = await _db.JobApplications
|
||||
.Include(j => j.Company)
|
||||
.FirstOrDefaultAsync(j => j.Id == id, cancellationToken);
|
||||
|
||||
if (job is null) return NotFound();
|
||||
if (string.IsNullOrWhiteSpace(request.Subject)) return BadRequest("Subject is required.");
|
||||
if (string.IsNullOrWhiteSpace(request.Body)) return BadRequest("Body is required.");
|
||||
|
||||
var toEmail = (request.ToEmail ?? job.Company?.RecruiterEmail ?? string.Empty).Trim();
|
||||
if (string.IsNullOrWhiteSpace(toEmail)) return BadRequest("Recipient email is required.");
|
||||
|
||||
try
|
||||
return StatusCode(StatusCodes.Status410Gone, new ProblemDetails
|
||||
{
|
||||
await _email.SendAsync(toEmail, request.Subject.Trim(), request.Body.Trim(), cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to send follow-up email for job {JobId} to {Email}", id, toEmail);
|
||||
return Problem(statusCode: StatusCodes.Status503ServiceUnavailable, title: "Email delivery unavailable", detail: "Follow-up email could not be sent right now. Please try again later.");
|
||||
}
|
||||
|
||||
_db.Correspondences.Add(new Correspondence
|
||||
{
|
||||
JobApplicationId = id,
|
||||
From = "Me",
|
||||
Subject = request.Subject.Trim(),
|
||||
Channel = "Email",
|
||||
Content = request.Body.Trim(),
|
||||
Date = DateTime.Now,
|
||||
Title = "Legacy email delivery retired",
|
||||
Detail = "Use Job email to review the connected provider and explicitly confirm delivery.",
|
||||
});
|
||||
|
||||
if (job.Company is not null)
|
||||
{
|
||||
job.Company.LastContactedAt = DateTime.Now;
|
||||
if (request.NextFollowUpAt is not null)
|
||||
{
|
||||
job.Company.NextContactAt = request.NextFollowUpAt.Value;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.NextFollowUpAt is not null)
|
||||
{
|
||||
job.FollowUpAt = request.NextFollowUpAt.Value;
|
||||
}
|
||||
|
||||
await _db.SaveChangesAsync(cancellationToken);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpGet("ai-metrics")]
|
||||
|
||||
Reference in New Issue
Block a user