Add confirmation for deletion

This commit is contained in:
cesnimda
2026-03-21 21:17:05 +01:00
parent 5ed5b340a5
commit 5b96465eaa
4 changed files with 128 additions and 9 deletions
@@ -722,6 +722,88 @@ namespace JobTrackerApi.Controllers
return NoContent();
}
[HttpPost("{id:int}/refresh-ai")]
public async Task<ActionResult<JobApplicationDto>> RefreshAi([FromRoute] int id, CancellationToken cancellationToken)
{
var job = await _db.JobApplications
.Include(j => j.Company)
.FirstOrDefaultAsync(j => j.Id == id, cancellationToken);
if (job is null) return NotFound();
var sourceText = string.Join("
", new[] { job.Description, job.TranslatedDescription, job.Notes }
.Where(x => !string.IsNullOrWhiteSpace(x)));
if (string.IsNullOrWhiteSpace(sourceText))
{
return BadRequest("This job does not have enough description or notes to generate a summary and skills.");
}
var tags = SkillTagger.Detect(sourceText)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
job.Tags = tags.Count == 0 ? null : JsonSerializer.Serialize(tags);
var shortSummary = await _summarizer.SummarizeAsync(sourceText, 160, 60);
job.ShortSummary = string.IsNullOrWhiteSpace(shortSummary) ? job.ShortSummary : shortSummary;
_db.JobEvents.Add(new JobEvent
{
JobApplicationId = job.Id,
Type = "AiRefreshed",
Note = "Summary and tags were manually refreshed.",
At = DateTime.Now
});
await _db.SaveChangesAsync(cancellationToken);
var settings = await RulesEngine.GetSettings(_db, cancellationToken);
var lastMsg = await _db.Correspondences
.AsNoTracking()
.Where(c => c.JobApplicationId == id)
.OrderByDescending(c => c.Date)
.Select(c => (DateTime?)c.Date)
.FirstOrDefaultAsync(cancellationToken);
var followUp = RulesEngine.Evaluate(settings, job, DateTime.Now, lastMsg);
return Ok(new JobApplicationDto(
Id: job.Id,
CompanyId: job.CompanyId,
Company: job.Company,
JobTitle: job.JobTitle,
Status: job.Status,
DateApplied: job.DateApplied,
ResponseReceived: job.ResponseReceived,
ResponseDate: job.ResponseDate,
Notes: job.Notes,
CoverLetterText: job.CoverLetterText,
JobUrl: job.JobUrl,
Description: job.Description,
TranslatedDescription: job.TranslatedDescription,
DescriptionLanguage: job.DescriptionLanguage,
Tags: job.Tags,
Deadline: job.Deadline,
Location: job.Location,
Salary: job.Salary,
NextAction: job.NextAction,
FollowUpAt: job.FollowUpAt,
FeedbackRequestedAt: job.FeedbackRequestedAt,
HasResume: job.HasResume,
HasCoverLetter: job.HasCoverLetter,
HasPortfolio: job.HasPortfolio,
HasOtherAttachment: job.HasOtherAttachment,
IsDeleted: job.IsDeleted,
DeletedAt: job.DeletedAt,
DaysSince: job.DaysSince,
NeedsFollowUp: followUp.NeedsFollowUp,
FollowUpReason: followUp.Reason,
ShortSummary: job.ShortSummary,
FullSummary: null
));
}
[HttpDelete("{id:int}")]
public async Task<IActionResult> SoftDelete([FromRoute] int id, CancellationToken cancellationToken)
{