From 19d2e20f24409ba6c445285fad0b8ac88e90c47c Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Fri, 9 May 2025 15:25:49 -0500 Subject: [PATCH] Cleanup the search people API method --- API/Controllers/PersonController.cs | 11 ++++++++--- API/Data/Repositories/PersonRepository.cs | 10 ++++++---- UI/Web/src/app/_services/person.service.ts | 9 +++------ .../edit-person-modal/edit-person-modal.component.ts | 4 ++-- .../merge-person-modal.component.ts | 1 + .../src/app/person-detail/person-detail.component.ts | 4 ++-- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/API/Controllers/PersonController.cs b/API/Controllers/PersonController.cs index 40a0a5f58..87d0cc6c0 100644 --- a/API/Controllers/PersonController.cs +++ b/API/Controllers/PersonController.cs @@ -48,10 +48,15 @@ public class PersonController : BaseApiController return Ok(await _unitOfWork.PersonRepository.GetPersonDtoByName(name, User.GetUserId())); } - [HttpGet("search-people")] - public async Task>> SearchPeople([FromQuery] string name) + /// + /// Find a person by name or alias against a query string + /// + /// + /// + [HttpGet("search")] + public async Task>> SearchPeople([FromQuery] string queryString) { - var people = await _unitOfWork.PersonRepository.SearchPeople(name); + var people = await _unitOfWork.PersonRepository.SearchPeople(queryString); return Ok(people.Select(person => _mapper.Map(person)).ToList()); } diff --git a/API/Data/Repositories/PersonRepository.cs b/API/Data/Repositories/PersonRepository.cs index 4c95d137e..0c8dbbfc8 100644 --- a/API/Data/Repositories/PersonRepository.cs +++ b/API/Data/Repositories/PersonRepository.cs @@ -68,7 +68,7 @@ public interface IPersonRepository Task> GetPeopleByNames(List normalizedNames, PersonIncludes includes = PersonIncludes.Aliases); Task GetPersonByAniListId(int aniListId, PersonIncludes includes = PersonIncludes.Aliases); - Task> SearchPeople(string query, PersonIncludes includes = PersonIncludes.Aliases); + Task> SearchPeople(string searchQuery, PersonIncludes includes = PersonIncludes.Aliases); } public class PersonRepository : IPersonRepository @@ -305,12 +305,14 @@ public class PersonRepository : IPersonRepository .FirstOrDefaultAsync(); } - public async Task> SearchPeople(string query, PersonIncludes includes = PersonIncludes.Aliases) + public async Task> SearchPeople(string searchQuery, PersonIncludes includes = PersonIncludes.Aliases) { + searchQuery = searchQuery.ToNormalized(); + return await _context.Person .Includes(includes) - .Where(p => EF.Functions.Like(p.Name, $"%{query}%") - || p.Aliases.Any(pa => EF.Functions.Like(pa.Alias, $"%{query}%"))) + .Where(p => EF.Functions.Like(p.Name, $"%{searchQuery}%") + || p.Aliases.Any(pa => EF.Functions.Like(pa.Alias, $"%{searchQuery}%"))) .ToListAsync(); } diff --git a/UI/Web/src/app/_services/person.service.ts b/UI/Web/src/app/_services/person.service.ts index 240b750f2..e36889a0b 100644 --- a/UI/Web/src/app/_services/person.service.ts +++ b/UI/Web/src/app/_services/person.service.ts @@ -1,17 +1,14 @@ -import { Injectable } from '@angular/core'; -import { HttpClient, HttpParams } from "@angular/common/http"; +import {Injectable} from '@angular/core'; +import {HttpClient, HttpParams} from "@angular/common/http"; import {environment} from "../../environments/environment"; import {Person, PersonRole} from "../_models/metadata/person"; -import {SeriesFilterV2} from "../_models/metadata/v2/series-filter-v2"; import {PaginatedResult} from "../_models/pagination"; import {Series} from "../_models/series"; import {map} from "rxjs/operators"; import {UtilityService} from "../shared/_services/utility.service"; import {BrowsePerson} from "../_models/person/browse-person"; -import {Chapter} from "../_models/chapter"; import {StandaloneChapter} from "../_models/standalone-chapter"; import {TextResonse} from "../_types/text-response"; -import {al} from "@angular/router/router_module.d-6zbCxc1T"; @Injectable({ providedIn: 'root' @@ -31,7 +28,7 @@ export class PersonService { } searchPerson(name: string) { - return this.httpClient.get>(this.baseUrl + `person/search-people?name=${name}`); + return this.httpClient.get>(this.baseUrl + `person/search?queryString=${encodeURIComponent(name)}`); } getRolesForPerson(personId: number) { diff --git a/UI/Web/src/app/person-detail/_modal/edit-person-modal/edit-person-modal.component.ts b/UI/Web/src/app/person-detail/_modal/edit-person-modal/edit-person-modal.component.ts index 9904b48f7..ebb653a13 100644 --- a/UI/Web/src/app/person-detail/_modal/edit-person-modal/edit-person-modal.component.ts +++ b/UI/Web/src/app/person-detail/_modal/edit-person-modal/edit-person-modal.component.ts @@ -5,7 +5,8 @@ import { AsyncValidatorFn, FormControl, FormGroup, - ReactiveFormsModule, ValidationErrors, + ReactiveFormsModule, + ValidationErrors, Validators } from "@angular/forms"; import {Person} from "../../../_models/metadata/person"; @@ -27,7 +28,6 @@ import {SettingItemComponent} from "../../../settings/_components/setting-item/s import {AccountService} from "../../../_services/account.service"; import {ToastrService} from "ngx-toastr"; import {EditListComponent} from "../../../shared/edit-list/edit-list.component"; -import {al} from "@angular/router/router_module.d-6zbCxc1T"; enum TabID { General = 'general-tab', diff --git a/UI/Web/src/app/person-detail/_modal/merge-person-modal/merge-person-modal.component.ts b/UI/Web/src/app/person-detail/_modal/merge-person-modal/merge-person-modal.component.ts index a398939c3..ac9c33244 100644 --- a/UI/Web/src/app/person-detail/_modal/merge-person-modal/merge-person-modal.component.ts +++ b/UI/Web/src/app/person-detail/_modal/merge-person-modal/merge-person-modal.component.ts @@ -73,6 +73,7 @@ export class MergePersonModalComponent implements OnInit { } this.typeAheadSettings.fetchFn = (filter: string) => { if (filter.length == 0) return of([]); + return this.personService.searchPerson(filter).pipe(map(people => { return people.filter(p => this.utilityService.filter(p.name, filter) && p.id != this.person.id); })); diff --git a/UI/Web/src/app/person-detail/person-detail.component.ts b/UI/Web/src/app/person-detail/person-detail.component.ts index 2a0361015..2a3f1d63c 100644 --- a/UI/Web/src/app/person-detail/person-detail.component.ts +++ b/UI/Web/src/app/person-detail/person-detail.component.ts @@ -10,7 +10,7 @@ import { } from '@angular/core'; import {ActivatedRoute, Router} from "@angular/router"; import {PersonService} from "../_services/person.service"; -import {BehaviorSubject, EMPTY, Observable, of, switchMap, tap} from "rxjs"; +import {BehaviorSubject, EMPTY, Observable, switchMap, tap} from "rxjs"; import {Person, PersonRole} from "../_models/metadata/person"; import {AsyncPipe} from "@angular/common"; import {ImageComponent} from "../shared/image/image.component"; @@ -19,7 +19,7 @@ import { SideNavCompanionBarComponent } from "../sidenav/_components/side-nav-companion-bar/side-nav-companion-bar.component"; import {ReadMoreComponent} from "../shared/read-more/read-more.component"; -import {TagBadgeComponent, TagBadgeCursor} from "../shared/tag-badge/tag-badge.component"; +import {TagBadgeCursor} from "../shared/tag-badge/tag-badge.component"; import {PersonRolePipe} from "../_pipes/person-role.pipe"; import {CarouselReelComponent} from "../carousel/_components/carousel-reel/carousel-reel.component"; import {FilterComparison} from "../_models/metadata/v2/filter-comparison";