Track cleanup progress and polish profile/system flows

This commit is contained in:
cesnimda
2026-03-23 19:49:41 +01:00
parent fcafda6f52
commit 90fdd8e1a5
14 changed files with 156 additions and 49 deletions
@@ -6,6 +6,7 @@ using JobTrackerApi.Services;
using JobTrackerApi.Services.JobImport;
using System.Security.Claims;
using System.Text.Json;
using Microsoft.AspNetCore.Identity;
namespace JobTrackerApi.Controllers
{
@@ -16,17 +17,44 @@ namespace JobTrackerApi.Controllers
private readonly JobTrackerContext _db;
private readonly ISummarizerService _summarizer;
private readonly IAppEmailSender _email;
private readonly UserManager<ApplicationUser> _users;
public JobApplicationsController(JobTrackerContext db, ISummarizerService summarizer, IAppEmailSender email)
public JobApplicationsController(JobTrackerContext db, ISummarizerService summarizer, IAppEmailSender email, UserManager<ApplicationUser> users)
{
_db = db;
_summarizer = summarizer;
_email = email;
_users = users;
}
private string? CurrentUserId =>
User?.FindFirstValue(ClaimTypes.NameIdentifier) ?? User?.FindFirstValue("sub");
private async Task<ApplicationUser?> GetCurrentUserAsync(CancellationToken cancellationToken)
{
var userId = CurrentUserId;
if (string.IsNullOrWhiteSpace(userId)) return null;
return await _users.FindByIdAsync(userId);
}
private static string GetPreferredDisplayName(ApplicationUser? user)
{
if (user is null) return "Your Name";
if (!string.IsNullOrWhiteSpace(user.DisplayName)) return user.DisplayName.Trim();
var fullName = string.Join(" ", new[] { user.FirstName?.Trim(), user.LastName?.Trim() }.Where(x => !string.IsNullOrWhiteSpace(x)));
if (!string.IsNullOrWhiteSpace(fullName)) return fullName;
if (!string.IsNullOrWhiteSpace(user.UserName)) return user.UserName.Trim();
if (!string.IsNullOrWhiteSpace(user.Email)) return user.Email.Trim();
return "Your Name";
}
private static string BuildGreeting(JobApplication job)
{
if (!string.IsNullOrWhiteSpace(job.Company?.RecruiterName)) return $"Hi {job.Company.RecruiterName.Trim()},";
if (!string.IsNullOrWhiteSpace(job.Company?.Name)) return $"Hi {job.Company.Name.Trim()} team,";
return "Hi there,";
}
private static IEnumerable<string> SplitTags(string? s)
{
if (string.IsNullOrWhiteSpace(s)) yield break;
@@ -1747,18 +1775,20 @@ Candidate master CV:
? (job.FollowUpAt is not null && job.FollowUpAt.Value.Date <= DateTime.Today ? "Scheduled follow-up is due." : "No recent response has been logged.")
: job.NextAction!;
var currentUser = await GetCurrentUserAsync(cancellationToken);
var signerName = GetPreferredDisplayName(currentUser);
var greeting = BuildGreeting(job);
var subject = $"Following up on {job.JobTitle} application";
var companyName = job.Company?.Name ?? "your team";
var reference = lastMessage?.Subject ?? job.JobTitle;
var summary = job.ShortSummary;
var body = string.Join("\n\n", new[]
{
$"Hi {companyName},",
greeting,
$"I wanted to follow up on my application for the {job.JobTitle} role. I'm still very interested in the opportunity and would love to hear if there are any updates on next steps.",
!string.IsNullOrWhiteSpace(summary) ? $"Quick reminder of fit: {summary}" : null,
$"Context: {reason}",
$"If helpful, I can also provide any additional information related to {reference}.",
"Thanks for your time,\n[Your name]"
$"Thanks for your time,\n{signerName}"
}.Where(x => !string.IsNullOrWhiteSpace(x)));
return Ok(new FollowUpDraftDto(subject, body, reason, DateTime.Today));