2b57d65715
Phase 3, frontend. /career now reads and writes the master profile through the
relational source of truth instead of the legacy blob path.
- CareerProfilePage loads GET /career/profile (structured profile from the
relational children + cvText + completeness) and saves PUT /career/profile
({ profile, cvText }). This keeps the relational store authoritative — the
previous PUT /auth/profile blob write left it stale after first load.
- Added a "Profile completeness" overview (percent bar + missing sections) at the
top of /career, from the server scorecard.
- PUT /career/profile now accepts { profile, cvText } so the single /career save
covers both the structured profile and the raw imported text; GET returns cvText.
Tests: career-save asserts the /career/profile payload; new completeness-overview
test; controller tests updated for the request wrapper. 75/76 frontend pass (the
1 failure is the unrelated pre-existing settings-view suite); prod build clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
88 lines
4.1 KiB
C#
88 lines
4.1 KiB
C#
using JobTrackerApi.Data;
|
|
using JobTrackerApi.Models;
|
|
using JobTrackerApi.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace JobTrackerApi.Controllers;
|
|
|
|
// Phase 3: the master career profile API. /career reads and writes the structured profile through
|
|
// here. The relational children (via CareerProfileService) are the source of truth; the
|
|
// ApplicationUser.ProfileCvStructureJson blob is kept in sync as a derived projection so the legacy
|
|
// read paths (CV rendering, tailoring, match-score) keep working. See
|
|
// docs/architecture/career-profile-model.md.
|
|
[ApiController]
|
|
[Route("api/career/profile")]
|
|
[Authorize]
|
|
public sealed class CareerProfileController : ControllerBase
|
|
{
|
|
private readonly UserManager<ApplicationUser> _users;
|
|
private readonly ICareerProfileService _career;
|
|
private readonly JobTrackerContext _db;
|
|
|
|
public CareerProfileController(UserManager<ApplicationUser> users, ICareerProfileService career, JobTrackerContext db)
|
|
{
|
|
_users = users;
|
|
_career = career;
|
|
_db = db;
|
|
}
|
|
|
|
/// <summary>The master career profile, assembled from the relational children.</summary>
|
|
[HttpGet]
|
|
public async Task<ActionResult<CareerProfileDto>> Get(CancellationToken cancellationToken)
|
|
{
|
|
var user = await _users.GetUserAsync(User);
|
|
if (user is null) return Unauthorized();
|
|
|
|
var profile = await _career.LoadStructuredAsync(user.Id, cancellationToken);
|
|
return Ok(new CareerProfileDto(profile, CareerCompleteness.Evaluate(profile), user.ProfileCvText));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Replaces the master career profile. Persists the relational children + an append-only
|
|
/// version, then serializes the result back into the ProfileCvStructureJson projection so the
|
|
/// legacy readers stay consistent. Identity fields are untouched (they belong to /profile).
|
|
/// </summary>
|
|
[HttpPut]
|
|
[Authorize(AuthenticationSchemes = "local")]
|
|
public async Task<ActionResult<CareerProfileDto>> Put([FromBody] CareerProfileSaveRequest? request, CancellationToken cancellationToken)
|
|
{
|
|
var user = await _users.GetUserAsync(User);
|
|
if (user is null) return StatusCode(501, "The career profile can only be edited on local accounts.");
|
|
|
|
var profile = StructuredCvProfileJson.Normalize(request?.Profile);
|
|
var error = CareerProfileValidator.Validate(profile);
|
|
if (error is not null) return BadRequest(error);
|
|
|
|
var saved = await _career.SaveVersionAsync(user.Id, profile, "manual", cancellationToken);
|
|
|
|
// Keep the derived projection in sync for legacy readers. CvText (the raw imported text) is
|
|
// part of the career profile and is set here too; identity fields are never touched.
|
|
user.ProfileCvStructureJson = StructuredCvProfileJson.Serialize(saved);
|
|
if (request?.CvText is not null) user.ProfileCvText = string.IsNullOrWhiteSpace(request.CvText) ? null : request.CvText;
|
|
var res = await _users.UpdateAsync(user);
|
|
if (!res.Succeeded) return BadRequest(string.Join("; ", res.Errors.Select(e => e.Description)));
|
|
|
|
return Ok(new CareerProfileDto(saved, CareerCompleteness.Evaluate(saved), user.ProfileCvText));
|
|
}
|
|
|
|
/// <summary>Just the completeness scorecard, for the /career overview.</summary>
|
|
[HttpGet("completeness")]
|
|
public async Task<ActionResult<CareerCompletenessDto>> Completeness(CancellationToken cancellationToken)
|
|
{
|
|
var user = await _users.GetUserAsync(User);
|
|
if (user is null) return Unauthorized();
|
|
var profile = await _career.LoadStructuredAsync(user.Id, cancellationToken);
|
|
return Ok(CareerCompleteness.Evaluate(profile));
|
|
}
|
|
}
|
|
|
|
public sealed record CareerProfileSaveRequest(StructuredCvProfile? Profile, string? CvText);
|
|
|
|
public sealed record CareerProfileDto(StructuredCvProfile Profile, CareerCompletenessDto Completeness, string? CvText);
|
|
|
|
public sealed record CareerCompletenessDto(int Percent, List<string> Missing, List<CareerSectionStatusDto> Sections);
|
|
|
|
public sealed record CareerSectionStatusDto(string Key, string Label, bool Complete, int Count);
|