using Microsoft.AspNetCore.Mvc;
using TrajetKmTracker.Api.Models.DTOs;
using TrajetKmTracker.Api.Services;
namespace TrajetKmTracker.Api.Controllers;
///
/// Endpoints de gestion du profil utilisateur (singleton) et de son état de configuration.
///
[ApiController]
[Route("api/profil")]
public class ProfilController : ControllerBase
{
private readonly IProfilService _profilService;
public ProfilController(IProfilService profilService)
{
_profilService = profilService;
}
/// Récupère le profil (créé à la volée s'il est absent).
[HttpGet]
[ProducesResponseType(typeof(ProfilDto), StatusCodes.Status200OK)]
public async Task> GetProfil(CancellationToken cancellationToken)
{
var profil = await _profilService.GetProfilAsync(cancellationToken);
return Ok(profil);
}
///
/// Sauvegarde le profil. La validation du matricule (≤ 8 car.) est assurée par FluentValidation.
/// Le géocodage de l'Adresse_Domicile est effectué au mieux : un échec BAN n'empêche pas la sauvegarde.
///
[HttpPut]
[ProducesResponseType(typeof(ProfilDto), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task> SaveProfil(
[FromBody] SaveProfilDto dto,
CancellationToken cancellationToken)
{
var profil = await _profilService.SaveProfilAsync(dto, cancellationToken);
return Ok(profil);
}
/// État de configuration du profil (onboarding).
[HttpGet("etat")]
[ProducesResponseType(typeof(EtatProfilDto), StatusCodes.Status200OK)]
public async Task> GetEtat(CancellationToken cancellationToken)
{
var etat = await _profilService.GetEtatAsync(cancellationToken);
return Ok(etat);
}
}