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

Commit

Permalink
update mapping (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
morkusporkus authored Nov 10, 2022
1 parent a6e260c commit 6438521
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
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

0 comments on commit 6438521

Please sign in to comment.