Skip to content
This repository has been archived by the owner on Apr 8, 2023. It is now read-only.

update mapping #149

Merged
merged 9 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Server/Features/OfferMatching/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ public async Task<OfferMatchingListResult> Handle(ListQuery request, Cancellatio

var offerMatches = await _dbContext.Players
.Include(p => p.Bids)
.ThenInclude(b => b.Team)
.Where(p => p.State == PlayerState.OfferMatching)
.ProjectTo<OfferMatchingListResult.OfferMatchingItem>(_mapper.ConfigurationProvider, new { currentUserTeamId })
.ToListAsync(cancellationToken);


return new OfferMatchingListResult
{
OfferMatches = offerMatches
Expand All @@ -64,7 +66,7 @@ public ListMappingProfile()

CreateMap<Player, OfferMatchingListResult.OfferMatchingItem>()
.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()));
Expand Down
1 change: 1 addition & 0 deletions src/Server/Models/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions src/Tests/Models/PlayerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down