Display aliases in the UI, allow adding and removing aliases from the Person Edit modal

Adds forgotten translation string
This commit is contained in:
Amelia 2025-05-06 19:51:28 +02:00
parent c36123a58f
commit d1c5f4a377
No known key found for this signature in database
GPG key ID: D6D0ECE365407EAA
21 changed files with 228 additions and 18 deletions

View file

@ -1,6 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using API.Data;
using API.Entities.Person;
using API.Extensions;
namespace API.Services;
@ -13,6 +16,15 @@ public interface IPersonService
/// <param name="src">Merged person</param>
/// <returns></returns>
Task MergePeopleAsync(Person dst, Person src);
/// <summary>
/// Adds the alias to the person, requires that the alias is not shared with anyone else
/// </summary>
/// <remarks>This method does NOT commit changes</remarks>
/// <param name="person"></param>
/// <param name="aliases"></param>
/// <returns></returns>
Task<bool> UpdatePersonAliasesAsync(Person person, IList<string> aliases);
}
public class PersonService(IUnitOfWork unitOfWork): IPersonService
@ -84,4 +96,32 @@ public class PersonService(IUnitOfWork unitOfWork): IPersonService
unitOfWork.PersonRepository.Update(dst);
await unitOfWork.CommitAsync();
}
public async Task<bool> UpdatePersonAliasesAsync(Person person, IList<string> aliases)
{
var normalizedAliases = aliases
.Select(a => a.ToNormalized().Trim())
.Where(a => !string.IsNullOrWhiteSpace(a))
.Where(a => a != person.NormalizedName)
.ToList();
if (normalizedAliases.Count == 0)
{
person.Aliases = [];
return true;
}
var others = await unitOfWork.PersonRepository.GetPeopleByNames(normalizedAliases);
others = others.Where(p => p.Id != person.Id).ToList();
if (others.Count != 0) return false;
person.Aliases = aliases.Select(a => new PersonAlias
{
Alias = a.Trim(),
NormalizedAlias = a.Trim().ToNormalized()
}).ToList();
return true;
}
}