feat(postit): allow username updates in profile flow

This commit is contained in:
Paul Schneider 2026-10-07 12:26:02 +01:00
commit 05e35d0677
Signed by: notazof
GPG key ID: AD4B9B545FBD7D12
5 changed files with 39 additions and 10 deletions

View file

@ -1,3 +1,4 @@
using Yavsc.Abstract.Identity;
using PostIt.ViewModels; using PostIt.ViewModels;
namespace PostIt.Tests; namespace PostIt.Tests;
@ -66,11 +67,23 @@ public class HomePageProviderFlowTests
Assert.NotNull(vm.RefreshCommand); Assert.NotNull(vm.RefreshCommand);
} }
[Fact]
public void ProfileUpdateRequest_allows_username_updates()
{
var request = new ProfileUpdateRequest
{
UserName = "alice.new"
};
Assert.Equal("alice.new", request.UserName);
}
[Fact] [Fact]
public void UserProfilePage_can_save_profile_values() public void UserProfilePage_can_save_profile_values()
{ {
var vm = new UserProfilePageViewModel var vm = new UserProfilePageViewModel
{ {
UserName = "alice.new",
FullName = "Alice Example", FullName = "Alice Example",
Address = "14 rue de l’Érable", Address = "14 rue de l’Érable",
DedicatedGoogleCalendar = "calendar-123", DedicatedGoogleCalendar = "calendar-123",

View file

@ -109,10 +109,11 @@ public partial class UserProfilePageViewModel : ViewModelBase
{ {
var payload = new ProfileUpdateRequest var payload = new ProfileUpdateRequest
{ {
FullName = FullName, UserName = string.IsNullOrWhiteSpace(UserName) ? string.Empty : UserName.Trim(),
Address = Address, FullName = string.IsNullOrWhiteSpace(FullName) ? string.Empty : FullName.Trim(),
GoogleCalendarId = DedicatedGoogleCalendar == "Non configuré" ? string.Empty : DedicatedGoogleCalendar, Address = string.IsNullOrWhiteSpace(Address) ? string.Empty : Address.Trim(),
BankInfoSummary = BankInfoSummary == "Aucune information bancaire" ? string.Empty : BankInfoSummary GoogleCalendarId = DedicatedGoogleCalendar == "Non configuré" ? string.Empty : DedicatedGoogleCalendar.Trim(),
BankInfoSummary = BankInfoSummary == "Aucune information bancaire" ? string.Empty : BankInfoSummary.Trim()
}; };
var endpoint = new Uri(new Uri(_api.Settings.ApiUrl.TrimEnd('/') + "/", UriKind.Absolute), "account/me").ToString(); var endpoint = new Uri(new Uri(_api.Settings.ApiUrl.TrimEnd('/') + "/", UriKind.Absolute), "account/me").ToString();

View file

@ -18,12 +18,13 @@
IsIndeterminate="True" IsIndeterminate="True"
Height="8"/> Height="8"/>
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="*" RowSpacing="8"> <Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="*" RowSpacing="8">
<TextBox Watermark="Nom complet" Text="{Binding FullName}"/> <TextBox Watermark="Nom d’utilisateur" Text="{Binding UserName}"/>
<TextBox Grid.Row="1" Watermark="Adresse" Text="{Binding Address}" AcceptsReturn="True" TextWrapping="Wrap"/> <TextBox Grid.Row="1" Watermark="Nom complet" Text="{Binding FullName}"/>
<TextBox Grid.Row="2" Watermark="Calendrier Google" Text="{Binding DedicatedGoogleCalendar}"/> <TextBox Grid.Row="2" Watermark="Adresse" Text="{Binding Address}" AcceptsReturn="True" TextWrapping="Wrap"/>
<TextBox Grid.Row="3" Watermark="Détails bancaires" Text="{Binding BankInfoSummary}" AcceptsReturn="True" TextWrapping="Wrap"/> <TextBox Grid.Row="3" Watermark="Calendrier Google" Text="{Binding DedicatedGoogleCalendar}"/>
<Button Grid.Row="4" Content="Enregistrer" Command="{Binding SaveProfileCommand}" IsEnabled="{Binding !IsBusy}"/> <TextBox Grid.Row="4" Watermark="Détails bancaires" Text="{Binding BankInfoSummary}" AcceptsReturn="True" TextWrapping="Wrap"/>
<Button Grid.Row="5" Content="Enregistrer" Command="{Binding SaveProfileCommand}" IsEnabled="{Binding !IsBusy}"/>
</Grid> </Grid>
<TextBlock Text="{Binding UserName, StringFormat='Nom d’utilisateur : {0}'}"/> <TextBlock Text="{Binding UserName, StringFormat='Nom d’utilisateur : {0}'}"/>

View file

@ -4,6 +4,7 @@ namespace Yavsc.Abstract.Identity;
public class ProfileUpdateRequest public class ProfileUpdateRequest
{ {
public string? UserName { get; set; }
public string? FullName { get; set; } public string? FullName { get; set; }
public string? Address { get; set; } public string? Address { get; set; }
public string? GoogleCalendarId { get; set; } public string? GoogleCalendarId { get; set; }

View file

@ -103,6 +103,19 @@ namespace Yavsc.WebApi.Controllers
return NotFound(); return NotFound();
} }
if (!string.IsNullOrWhiteSpace(request.UserName))
{
var trimmedUserName = request.UserName.Trim();
if (!string.Equals(user.UserName, trimmedUserName, StringComparison.Ordinal))
{
var usernameUpdate = await _userManager.SetUserNameAsync(user, trimmedUserName);
if (!usernameUpdate.Succeeded)
{
return BadRequest(new { error = "Unable to update username.", details = usernameUpdate.Errors.Select(e => e.Description) });
}
}
}
if (!string.IsNullOrWhiteSpace(request.FullName)) if (!string.IsNullOrWhiteSpace(request.FullName))
{ {
user.FullName = request.FullName.Trim(); user.FullName = request.FullName.Trim();