public async Task <IActionResult> GetListings([FromQuery] PaginationParams paginationParams, [FromQuery] FilterParams filterParams) { var userId = User != null?int.Parse(User?.FindFirst(ClaimTypes.NameIdentifier)?.Value) : -1; if ((filterParams.MyListingsOnly || filterParams.WatchlistOnly) && userId == -1) { return(Unauthorized()); } var listings = await _repo.GetListings(paginationParams, filterParams, userId); var listingsToReturn = _mapper.Map <IEnumerable <ListingSearchResultsDto> >(listings); if (userId != -1) { var userWatchlist = await _repo.GetWatchingIds(userId); foreach (var item in listingsToReturn) { if (userWatchlist.Contains(item.id)) { item.watching = true; } } } Response.AddPagination(listings.PageNumber, listings.PageSize, listings.TotalPages, listings.TotalItems); return(Ok(listingsToReturn)); }