diff --git a/src/Client/Features/FreeAgents/List.razor b/src/Client/Features/FreeAgents/List.razor index 4371025..1b94534 100644 --- a/src/Client/Features/FreeAgents/List.razor +++ b/src/Client/Features/FreeAgents/List.razor @@ -40,15 +40,21 @@ @context.Position @context.Team - @context.BiddingEnds.ToShortDateString() + + @context.BiddingEnds.ToShortDateString() + -
- @context.HighestBid + + @context.HighestBid.ToString("C") @if (context.CurrentUserIsHighestBidder) { - You! + You! + } + else if(context.WinningTeam != null) + { + @context.WinningTeam } -
+
diff --git a/src/Server/Features/FreeAgents/List.cs b/src/Server/Features/FreeAgents/List.cs index be7f53e..c8a0e18 100644 --- a/src/Server/Features/FreeAgents/List.cs +++ b/src/Server/Features/FreeAgents/List.cs @@ -53,6 +53,7 @@ public async Task Handle(ListQuery request, CancellationTok var freeAgents = await _dbContext.Players .Include(p => p.Team) .Include(p => p.Bids) + .ThenInclude(b => b.Team) .WhereIsFreeAgent() .OrderBy(p => p.EndOfFreeAgency) .ProjectTo(_mapper.ConfigurationProvider, new { currentUserTeamId }) @@ -78,6 +79,7 @@ public ListMappingProfile() s.Bids.FindHighestBid()!.TeamId == currentUserTeamId) ) .ForMember(d => d.BiddingEnds, mo => mo.MapFrom(s => s.EndOfFreeAgency!.Value)) - .ForMember(d => d.HighestBid, mo => mo.MapFrom(s => s.GetHighestBidAmount())); + .ForMember(d => d.HighestBid, mo => mo.MapFrom(s => s.GetHighestBidAmount())) + .ForMember(d => d.WinningTeam, mo => mo.MapFrom(s => s.Bids.Any() ? s.Bids.FindHighestBid()!.Team.Name : null)); } } diff --git a/src/Shared/Features/FreeAgents/List.cs b/src/Shared/Features/FreeAgents/List.cs index 0cec9ed..d4f1024 100644 --- a/src/Shared/Features/FreeAgents/List.cs +++ b/src/Shared/Features/FreeAgents/List.cs @@ -14,6 +14,7 @@ public class FreeAgentItem public DateTime BiddingEnds { get; set; } public int HighestBid { get; set; } public bool CurrentUserIsHighestBidder { get; set; } + public string? WinningTeam { get; set; } } } diff --git a/src/Tests/Features/FreeAgents/ListTests.cs b/src/Tests/Features/FreeAgents/ListTests.cs index 2b61601..5ced2e4 100644 --- a/src/Tests/Features/FreeAgents/ListTests.cs +++ b/src/Tests/Features/FreeAgents/ListTests.cs @@ -66,4 +66,34 @@ public async Task GivenAnyAuthenticatedUser_WhenThereIsOnePlayerWhoIsAFreeAgent_ freeAgent.BiddingEnds.Should().Be(biddingEnds); freeAgent.CurrentUserIsHighestBidder.Should().BeTrue(); } + + [Fact] + public async Task GivenAnyAuthenticatedUser_WhenAFreeAgentHasABidByAnotherTeam_ThenThatTeamShowsAsTheWinningTeam() + { + var application = CreateUserAuthenticatedApplication(); + + var mockTeam = CreateFakeTeam(); + await application.AddAsync(mockTeam); + + var mockPlayer = CreateFakePlayer(); + mockPlayer.TeamId = mockTeam.Id; + mockPlayer.SetToRostered(DateTime.MinValue.Year, int.MaxValue); + var biddingEnds = DateTime.MaxValue; + mockPlayer.SetToFreeAgent(biddingEnds); + await application.AddAsync(mockPlayer); + + var winningTeam = CreateFakeTeam(); + await application.AddAsync(winningTeam); + + var bidAmount = int.MaxValue; + mockPlayer.AddBid(bidAmount, winningTeam.Id); + await application.UpdateAsync(mockPlayer); + + var client = application.CreateClient(); + + var result = await client.GetFromJsonAsync(FreeAgentListRouteFactory.Uri); + + var freeAgent = result!.FreeAgents.First(); + freeAgent.WinningTeam.Should().Be(winningTeam.Name); + } }