Optimized one lookup in search api and added maxRecords to API
This commit is contained in:
parent
5abc0fefd6
commit
50273db00c
5 changed files with 48 additions and 20 deletions
|
|
@ -2,6 +2,7 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.Data;
|
||||
using API.Data.Repositories;
|
||||
using API.DTOs;
|
||||
using API.DTOs.Search;
|
||||
using API.Extensions;
|
||||
|
|
@ -51,23 +52,21 @@ public class SearchController : BaseApiController
|
|||
/// Search for different entities against the query string
|
||||
/// </summary>
|
||||
/// <param name="queryString"></param>
|
||||
/// <param name="maxRecords">Defaults to 15, if 0 will not apply any limit to search results and may result in longer response times</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("search")]
|
||||
public async Task<ActionResult<SearchResultGroupDto>> Search(string queryString)
|
||||
public async Task<ActionResult<SearchResultGroupDto>> Search(string queryString, int maxRecords = 15)
|
||||
{
|
||||
queryString = Uri.UnescapeDataString(queryString)
|
||||
.Trim()
|
||||
.Replace(@"%", string.Empty)
|
||||
.Replace(":", string.Empty);
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
|
||||
|
||||
// Get libraries user has access to
|
||||
var libraries = (await _unitOfWork.LibraryRepository.GetLibrariesForUserIdAsync(user.Id)).ToList();
|
||||
if (!libraries.Any()) return BadRequest("User does not have access to any libraries");
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Library);
|
||||
if (!user.Libraries.Any()) return BadRequest("User does not have access to any libraries");
|
||||
|
||||
var isAdmin = await _unitOfWork.UserRepository.IsUserAdminAsync(user);
|
||||
var series = await _unitOfWork.SeriesRepository.SearchSeries(user.Id, isAdmin,
|
||||
libraries.Select(l => l.Id).ToArray(), queryString);
|
||||
user.Libraries.Select(l => l.Id).ToArray(), queryString, maxRecords);
|
||||
|
||||
return Ok(series);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue