This repository has been archived by the owner on Apr 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show offer matching for everyone but only matching team can actually …
…match. (#134)
- Loading branch information
1 parent
2bce12d
commit 2fcc50e
Showing
12 changed files
with
245 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 2 additions & 5 deletions
7
...r/Features/OidcConfigurationController.cs → ...entication/OidcConfigurationController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using DynamoLeagueBlazor.Server.Infrastructure.Identity; | ||
using DynamoLeagueBlazor.Shared.Features.OfferMatching; | ||
|
||
namespace DynamoLeagueBlazor.Server.Features.OfferMatching; | ||
|
||
[ApiController] | ||
[Route(MatchPlayerRouteFactory.Uri)] | ||
public class MatchPlayerController : ControllerBase | ||
{ | ||
private readonly IMediator _mediator; | ||
|
||
public MatchPlayerController(IMediator mediator) | ||
{ | ||
_mediator = mediator; | ||
} | ||
|
||
[HttpPost] | ||
public async Task<Unit> PostAsync([FromBody] MatchPlayerRequest request, CancellationToken cancellationToken) | ||
{ | ||
return await _mediator.Send(new MatchPlayerCommand(request.PlayerId), cancellationToken); | ||
} | ||
} | ||
|
||
public record MatchPlayerCommand(int PlayerId) : IRequest { } | ||
|
||
public class MatchPlayerHandler : IRequestHandler<MatchPlayerCommand> | ||
{ | ||
private readonly ApplicationDbContext _dbContext; | ||
|
||
public MatchPlayerHandler(ApplicationDbContext dbContext) | ||
{ | ||
_dbContext = dbContext; | ||
} | ||
|
||
public async Task<Unit> Handle(MatchPlayerCommand request, CancellationToken cancellationToken) | ||
{ | ||
var player = (await _dbContext.Players | ||
.AsTracking() | ||
.Include(p => p.Bids) | ||
.SingleAsync(p => p.Id == request.PlayerId, cancellationToken)); | ||
|
||
player.MatchOffer(); | ||
|
||
await _dbContext.SaveChangesAsync(cancellationToken); | ||
|
||
return Unit.Value; | ||
} | ||
} | ||
|
||
public class MatchPlayerValidator : IMatchPlayerValidator | ||
{ | ||
private readonly IHttpContextAccessor _httpContextAccessor; | ||
private readonly ApplicationDbContext _dbContext; | ||
|
||
public MatchPlayerValidator(IHttpContextAccessor httpContextAccessor, ApplicationDbContext dbContext) | ||
{ | ||
_httpContextAccessor = httpContextAccessor; | ||
_dbContext = dbContext; | ||
} | ||
|
||
public async Task<bool> CanOfferMatchAsync(int playerId, CancellationToken cancellationToken) | ||
{ | ||
var currentUserTeamId = _httpContextAccessor.HttpContext!.User.GetTeamId(); | ||
|
||
var canOfferMatch = await _dbContext.Players | ||
.AnyAsync(p => p.TeamId == currentUserTeamId | ||
&& p.Id == playerId, cancellationToken); | ||
|
||
return canOfferMatch; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,23 @@ | ||
namespace DynamoLeagueBlazor.Shared.Features.OfferMatching | ||
namespace DynamoLeagueBlazor.Shared.Features.OfferMatching; | ||
|
||
public record MatchPlayerRequest(int PlayerId); | ||
|
||
public class MatchPlayerRequestValidator : AbstractValidator<MatchPlayerRequest> | ||
{ | ||
public class MatchPlayerRequest | ||
public MatchPlayerRequestValidator(IMatchPlayerValidator offerMatchingValidator) | ||
{ | ||
public int PlayerId { get; set; } | ||
RuleFor(x => x.PlayerId) | ||
.GreaterThan(0) | ||
.MustAsync(async (request, value, token) => await offerMatchingValidator.CanOfferMatchAsync(value, token)); | ||
} | ||
} | ||
|
||
public static class MatchPlayerRouteFactory | ||
{ | ||
public const string Uri = "api/matchplayer"; | ||
} | ||
|
||
public interface IMatchPlayerValidator | ||
{ | ||
Task<bool> CanOfferMatchAsync(int playerId, CancellationToken cancellationToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.