Switch src & dst and remove some no longer needed code

This commit is contained in:
Amelia 2025-05-08 09:23:48 +02:00
parent 9844503671
commit a01f656654
No known key found for this signature in database
GPG key ID: D6D0ECE365407EAA
7 changed files with 13 additions and 40 deletions

View file

@ -40,7 +40,7 @@ public class PersonServiceTests: AbstractDbTest
UnitOfWork.PersonRepository.Attach(person2);
await UnitOfWork.CommitAsync();
await ps.MergePeopleAsync(person1, person2);
await ps.MergePeopleAsync(person2, person1);
var allPeople = await UnitOfWork.PersonRepository.GetAllPeople();
Assert.Single(allPeople);
@ -76,7 +76,7 @@ public class PersonServiceTests: AbstractDbTest
UnitOfWork.PersonRepository.Attach(person2);
await UnitOfWork.CommitAsync();
await ps.MergePeopleAsync(person1, person2);
await ps.MergePeopleAsync(person2, person1);
var allPeople = await UnitOfWork.PersonRepository.GetAllPeople();
Assert.Single(allPeople);
}
@ -124,7 +124,7 @@ public class PersonServiceTests: AbstractDbTest
UnitOfWork.SeriesRepository.Add(series2);
await UnitOfWork.CommitAsync();
await ps.MergePeopleAsync(person, person2);
await ps.MergePeopleAsync(person2, person);
var allPeople = await UnitOfWork.PersonRepository.GetAllPeople();
Assert.Single(allPeople);
@ -201,7 +201,7 @@ public class PersonServiceTests: AbstractDbTest
UnitOfWork.SeriesRepository.Add(series2);
await UnitOfWork.CommitAsync();
await ps.MergePeopleAsync(person, person2);
await ps.MergePeopleAsync(person2, person);
var allPeople = await UnitOfWork.PersonRepository.GetAllPeople();
Assert.Single(allPeople);

View file

@ -59,16 +59,6 @@ public class PersonController : BaseApiController
return Ok(await _unitOfWork.PersonRepository.GetRolesForPersonByName(personId, User.GetUserId()));
}
[HttpGet("aliases")]
public async Task<ActionResult<IList<string>>> GetAliasesForPerson([FromQuery] int personId)
{
var person = await _unitOfWork.PersonRepository.GetPersonById(personId);
if (person == null) return NotFound();
if (person.Aliases == null || person.Aliases.Count == 0) return new List<string>();
return Ok(person.Aliases.Select(a => a.Alias).ToList());
}
/// <summary>
/// Returns a list of authors and artists for browsing
@ -207,7 +197,7 @@ public class PersonController : BaseApiController
var src = await _unitOfWork.PersonRepository.GetPersonById(dto.SrcId, PersonIncludes.All);
if (src == null) return BadRequest();
await _personService.MergePeopleAsync(dst, src);
await _personService.MergePeopleAsync(src, dst);
await _eventHub.SendMessageAsync(MessageFactory.PersonMerged, MessageFactory.PersonMergedMessage(dst, src));
return Ok(_mapper.Map<PersonDto>(dst));

View file

@ -13,11 +13,11 @@ public interface IPersonService
/// <summary>
/// Adds src as an alias to dst, this is a destructive operation
/// </summary>
/// <param name="dst">Remaining person</param>
/// <param name="src">Merged person</param>
/// <param name="dst">Remaining person</param>
/// <remarks>The entities passed as arguments **must** include all relations</remarks>
/// <returns></returns>
Task MergePeopleAsync(Person dst, Person src);
Task MergePeopleAsync(Person src, Person dst);
/// <summary>
/// Adds the alias to the person, requires that the aliases are not shared with anyone else
@ -32,7 +32,7 @@ public interface IPersonService
public class PersonService(IUnitOfWork unitOfWork): IPersonService
{
public async Task MergePeopleAsync(Person dst, Person src)
public async Task MergePeopleAsync(Person src, Person dst)
{
if (dst.Id == src.Id) return;

View file

@ -99,9 +99,9 @@
<li [ngbNavItem]="TabID.Aliases">
<a ngbNavLink>{{t(TabID.Aliases)}}</a>
<ng-template ngbNavContent>
<app-edit-list [items]="aliases"
<app-edit-list [items]="person.aliases"
[asyncValidators]="[aliasValidator()]"
(updateItems)="aliases = $event"
(updateItems)="person.aliases = $event"
[errorMessage]="t('alias-overlap')"
[label]="t('aliases-label')"/>
</ng-template>

View file

@ -68,7 +68,6 @@ export class EditPersonModalComponent implements OnInit {
protected readonly TabID = TabID;
@Input({required: true}) person!: Person;
@Input({required: true}) aliases!: string[];
active = TabID.General;
editForm: FormGroup = new FormGroup({
@ -118,8 +117,7 @@ export class EditPersonModalComponent implements OnInit {
apis.push(this.uploadService.updatePersonCoverImage(this.person.id, this.selectedCover, !this.coverImageReset));
}
// UpdatePersonDto allows for aliases
const person: Person & { aliases: string[] } = {
const person: Person = {
id: this.person.id,
coverImageLocked: this.person.coverImageLocked,
name: this.editForm.get('name')!.value || '',
@ -130,7 +128,7 @@ export class EditPersonModalComponent implements OnInit {
// @ts-ignore
malId: this.editForm.get('malId')!.value === '' ? null : parseInt(this.editForm.get('malId').value, 10),
hardcoverId: this.editForm.get('hardcoverId')!.value || '',
aliases: this.aliases,
aliases: this.person.aliases,
};
apis.push(this.personService.updatePerson(person));

View file

@ -38,7 +38,6 @@ export class MergePersonModalComponent implements OnInit {
@Input({required: true}) person!: Person;
mergee: Person | null = null;
aliases: string[] = [];
save() {
if (!this.mergee) {
@ -81,9 +80,6 @@ export class MergePersonModalComponent implements OnInit {
this.typeAheadUnfocus.emit(this.typeAheadSettings.id);
this.mergee = people[0];
this.personService.getAliases(this.mergee.id).subscribe(aliases => {
this.aliases = aliases;
});
}
protected readonly FilterField = FilterField;
@ -91,6 +87,6 @@ export class MergePersonModalComponent implements OnInit {
allNewAliases() {
if (!this.mergee) return [];
return [this.mergee.name, ...this.aliases]
return [this.mergee.name, ...this.mergee.aliases]
}
}

View file

@ -60,7 +60,6 @@ interface PersonMergeEvent {
ImageComponent,
SideNavCompanionBarComponent,
ReadMoreComponent,
TagBadgeComponent,
PersonRolePipe,
CarouselReelComponent,
CardItemComponent,
@ -101,8 +100,6 @@ export class PersonDetailComponent implements OnInit {
roles: PersonRole[] | null = null;
works$: Observable<Series[]> | null = null;
filter: SeriesFilterV2 | null = null;
aliases$: Observable<string[]> | null = null;
aliases: string[] = [];
personActions: Array<ActionItem<Person>> = this.actionService.getPersonActions(this.handleAction.bind(this));
chaptersByRole: any = {};
anilistUrl: string = '';
@ -182,11 +179,6 @@ export class PersonDetailComponent implements OnInit {
takeUntilDestroyed(this.destroyRef)
);
this.aliases$ = this.personService.getAliases(person.id).pipe(
tap(aliases => this.aliases = aliases),
takeUntilDestroyed(this.destroyRef)
);
}
createFilter(roles: PersonRole[]) {
@ -244,17 +236,14 @@ export class PersonDetailComponent implements OnInit {
case(Action.Edit):
const ref = this.modalService.open(EditPersonModalComponent, DefaultModalOptions);
ref.componentInstance.person = this.person;
ref.componentInstance.aliases = this.aliases;
ref.closed.subscribe(r => {
if (r.success) {
const nameChanged = this.personName !== r.person.name;
this.person = {...r.person};
this.aliases = r.person.aliases; // UpdatePersonDto does include them
this.personName = this.person!.name;
this.personSubject.next(this.person);
this.aliases$ = of(this.aliases);
// Update the url to reflect the new name change
if (nameChanged) {