From 64385215067bdab53c255a57b047c82aa639c9e1 Mon Sep 17 00:00:00 2001 From: morkusporkus Date: Thu, 10 Nov 2022 14:38:05 -0600 Subject: [PATCH] update mapping (#149) --- src/Server/Features/OfferMatching/List.cs | 4 +++- src/Server/Models/Player.cs | 1 + src/Tests/Models/PlayerTests.cs | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Server/Features/OfferMatching/List.cs b/src/Server/Features/OfferMatching/List.cs index 169bb4e..ff2ba53 100644 --- a/src/Server/Features/OfferMatching/List.cs +++ b/src/Server/Features/OfferMatching/List.cs @@ -46,10 +46,12 @@ public async Task Handle(ListQuery request, Cancellatio var offerMatches = await _dbContext.Players .Include(p => p.Bids) + .ThenInclude(b => b.Team) .Where(p => p.State == PlayerState.OfferMatching) .ProjectTo(_mapper.ConfigurationProvider, new { currentUserTeamId }) .ToListAsync(cancellationToken); + return new OfferMatchingListResult { OfferMatches = offerMatches @@ -64,7 +66,7 @@ public ListMappingProfile() CreateMap() .ForMember(d => d.Team, mo => mo.MapFrom(s => s.Team.Name)) - .ForMember(d => d.OfferingTeam, mo => mo.MapFrom(s => s.Team != null ? s.Team.Name : string.Empty)) + .ForMember(d => d.OfferingTeam, mo => mo.MapFrom(s => s.GetOfferingTeam())) .ForMember(d => d.Offer, mo => mo.MapFrom(s => s.GetHighestBidAmount())) .ForMember(d => d.CurrentUserIsOfferMatching, mo => mo.MapFrom(s => s.TeamId == currentUserTeamId)) .ForMember(d => d.RemainingTime, mo => mo.MapFrom(s => s.GetRemainingFreeAgencyTime())); diff --git a/src/Server/Models/Player.cs b/src/Server/Models/Player.cs index 11e9d61..8870578 100644 --- a/src/Server/Models/Player.cs +++ b/src/Server/Models/Player.cs @@ -119,6 +119,7 @@ public Fine AddFine(decimal amount, string reason) } public int GetHighestBidAmount() => Bids.Any() ? Bids.FindHighestBid()!.Amount : Bid.MinimumAmount; + public string GetOfferingTeam() => Bids.Any() ? Bids.FindHighestBid()!.Team.Name : string.Empty; public TimeSpan GetRemainingFreeAgencyTime() => EndOfFreeAgency!.Value.AddDays(3) - DateTime.Now; diff --git a/src/Tests/Models/PlayerTests.cs b/src/Tests/Models/PlayerTests.cs index 049c533..05cf302 100644 --- a/src/Tests/Models/PlayerTests.cs +++ b/src/Tests/Models/PlayerTests.cs @@ -17,6 +17,12 @@ public void GivenAPlayerWithABid_ThenReturnsThatBidAmount() player.GetHighestBidAmount().Should().Be(int.MaxValue); } + + [Fact] + public void GivenAPlayerWithNoBids_WhenFindingTheHighestBiddingTeam_ThenEmptyString() + => CreateFakePlayer() + .GetOfferingTeam() + .Should().Be(string.Empty); } public class PlayerStateTests