Persist structured CV section data

This commit is contained in:
cesnimda
2026-03-23 23:48:39 +01:00
parent 8f04637cff
commit c33640986e
5 changed files with 32 additions and 2 deletions
@@ -1,4 +1,5 @@
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using JobTrackerApi.Services;
using JobTrackerApi.Models;
@@ -86,6 +87,8 @@ public sealed class ProfileCvController : ControllerBase
}
user.ProfileCvText = text;
user.ProfileCvStructureJson = JsonSerializer.Serialize(
ParseSections(text).Select(section => new ParsedCvSectionDto(section.Name, section.Content, CountWords(section.Content))).ToList());
var result = await _users.UpdateAsync(user);
if (!result.Succeeded)
{
@@ -114,6 +117,8 @@ public sealed class ProfileCvController : ControllerBase
}
user.ProfileCvText = rebuilt.Trim();
user.ProfileCvStructureJson = JsonSerializer.Serialize(
ParseSections(user.ProfileCvText).Select(section => new ParsedCvSectionDto(section.Name, section.Content, CountWords(section.Content))).ToList());
var result = await _users.UpdateAsync(user);
if (!result.Succeeded)
{
@@ -161,6 +166,13 @@ public sealed class ProfileCvController : ControllerBase
.Select(section => new ParsedCvSectionDto(section.Name, section.Content, CountWords(section.Content)))
.ToList();
user.ProfileCvStructureJson = JsonSerializer.Serialize(sections);
var update = await _users.UpdateAsync(user);
if (!update.Succeeded)
{
return BadRequest(string.Join("; ", update.Errors.Select(e => e.Description)));
}
return Ok(new { sections, totalWords = CountWords(source) });
}
@@ -183,6 +195,8 @@ public sealed class ProfileCvController : ControllerBase
}
user.ProfileCvText = improved.Trim();
user.ProfileCvStructureJson = JsonSerializer.Serialize(
ParseSections(user.ProfileCvText).Select(section => new ParsedCvSectionDto(section.Name, section.Content, CountWords(section.Content))).ToList());
var result = await _users.UpdateAsync(user);
if (!result.Succeeded)
{