Skip to content

Commit

Permalink
fixing bgg no results returned exception thrown (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkieres authored Nov 5, 2023
1 parent 512ca23 commit 803e4fb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ namespace BGC.Core.Models.Dtos.BoardGameGeek;
public class BoardGameSearchResponseDto
{
[XmlElement(typeof(BoardGameSearchItemDto), ElementName = "item")]
public BoardGameSearchItemDto[] BoardGames { get; init; } = Array.Empty<BoardGameSearchItemDto>();
public BoardGameSearchItemDto[]? BoardGames { get; init; } = Array.Empty<BoardGameSearchItemDto>();

[XmlIgnore]
public bool IsEmpty => !BoardGames.Any();
public bool IsEmpty => !(BoardGames?.Any() ?? false);

[XmlAttribute(AttributeName = "total")]
public int Total { get; set; }

[XmlAttribute(AttributeName = "termsofuse")]
public string TermsOfUse { get; set; }
public string? TermsOfUse { get; set; }
}
4 changes: 2 additions & 2 deletions backend/BGC.SearchApi/Services/SearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public async Task<IReadOnlyCollection<BoardGameSummaryDto>> Search(string query,
return Array.Empty<BoardGameSummaryDto>();
}

var boardGameSummaries = bggSearchResponse.BoardGames.Select(boardGame => new BoardGameSummaryDto(boardGame.Id.ToString(), boardGame.Name.Value, boardGame.YearPublished?.Value))
.ToArray();
var boardGameSummaries = bggSearchResponse.BoardGames!.Select(boardGame => new BoardGameSummaryDto(boardGame.Id.ToString(), boardGame.Name.Value, boardGame.YearPublished?.Value))
.ToArray();

var boardGamesDetails = await _boardGamesRepository.GetBoardGames(boardGameSummaries.Select(boardGame => boardGame.Id), cancellationToken);
var boardGamesDetailsDict = boardGamesDetails.ToDictionary(boardGame => boardGame.Id);
Expand Down
5 changes: 5 additions & 0 deletions backend/BGC.SearchApi/search.http
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ X-Api-Key: whatever

###

GET https://{{hostname}}:{{port}}/api/search?query=smallworld
X-Api-Key: whatever

###

GET https://{{hostname}}:{{port}}/api/search?query=My Little Scythe

###
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using BGC.Core;
using BGC.Core.Extensions;
using BGC.Core.Models.Domain;
using BGC.Core.Models.Dtos.BoardGameGeek;
Expand Down Expand Up @@ -112,6 +113,7 @@ public async Task Search_EnrichesBoardGameDetails_ReturnsEnrichedGameDetailResul
var enrichedBoardGameDetails = new BoardGame()
{
Id = "1238",
Type = Constants.BggApi.BoardGameTypes.MainGame,
ImageUrl = "https://fancy.image.net/funny.jpg",
Prices = new[]
{
Expand All @@ -131,6 +133,7 @@ public async Task Search_EnrichesBoardGameDetails_ReturnsEnrichedGameDetailResul
searchResults.Should().HaveCount(bggSearchResposne.BoardGames.Length);
searchResults.Should().ContainEquivalentOf(new BoardGameSummaryDto("1238", "Scythe", 1987)
{
Type = Constants.Domain.BoardGameTypes.MainGame,
ImageUrl = enrichedBoardGameDetails.ImageUrl,
Prices = new BoardGameSummaryPriceDto[]
{
Expand Down

0 comments on commit 803e4fb

Please sign in to comment.