-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce35a07
commit f4a9d18
Showing
26 changed files
with
460 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using FluentResults; | ||
using MediatR; | ||
|
||
namespace Football.Management.Application.Abstractions; | ||
|
||
public interface ICommand : IRequest<Result> {} | ||
public interface ICommand<TResponse> : IRequest<Result<TResponse>> {} |
7 changes: 7 additions & 0 deletions
7
Football.Management.Application/Abstractions/ICommandHandler.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using FluentResults; | ||
using MediatR; | ||
|
||
namespace Football.Management.Application.Abstractions; | ||
|
||
public interface ICommandHandler<TCommand> : IRequestHandler<TCommand, Result> where TCommand : ICommand {} | ||
public interface ICommandHandler<TCommand, TResponse> : IRequestHandler<TCommand, Result<TResponse>> where TCommand : ICommand<TResponse> {} |
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,6 @@ | ||
using FluentResults; | ||
using MediatR; | ||
|
||
namespace Football.Management.Application.Abstractions; | ||
|
||
public interface IQuery<TResponse> : IRequest<Result<TResponse>> {} |
6 changes: 6 additions & 0 deletions
6
Football.Management.Application/Abstractions/IQueryHandler.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using FluentResults; | ||
using MediatR; | ||
|
||
namespace Football.Management.Application.Abstractions; | ||
|
||
public interface IQueryHandler<TQuery, TResponse> : IRequestHandler<TQuery, Result<TResponse>> where TQuery : IQuery<TResponse> {} |
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,8 @@ | ||
using System.Reflection; | ||
|
||
namespace Football.Management.Application; | ||
|
||
public class AssemblyReference | ||
{ | ||
public static readonly Assembly Assembly = typeof(AssemblyReference).Assembly; | ||
} |
18 changes: 18 additions & 0 deletions
18
Football.Management.Application/Football.Management.Application.csproj
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Football.Management.Domain\Football.Management.Domain.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentResults" Version="3.15.2" /> | ||
<PackageReference Include="MediatR" Version="12.2.0" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
6 changes: 6 additions & 0 deletions
6
Football.Management.Application/Players/Commands/CreatePlayer/CreatePlayerCommand.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using Football.Management.Application.Abstractions; | ||
using Football.Management.Domain.Identities; | ||
|
||
namespace Football.Management.Application.Players.Commands.CreatePlayer; | ||
|
||
public sealed record CreatePlayerCommand(string FirstName, string LastName, int AttackSkill, int MidfieldSkill, int DefenseSkill) : ICommand<PlayerId>; |
72 changes: 72 additions & 0 deletions
72
Football.Management.Application/Players/Commands/CreatePlayer/CreatePlayerCommandHander.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using FluentResults; | ||
using Football.Management.Application.Abstractions; | ||
using Football.Management.Domain.Entities; | ||
using Football.Management.Domain.Identities; | ||
using Football.Management.Domain.Repositories; | ||
using Football.Management.Domain.ValueObjects; | ||
|
||
namespace Football.Management.Application.Players.Commands.CreatePlayer; | ||
|
||
internal sealed class CreatePlayerCommandHander : ICommandHandler<CreatePlayerCommand, PlayerId> | ||
{ | ||
private readonly IPlayerRepository _playerRepository; | ||
|
||
public CreatePlayerCommandHander(IPlayerRepository playerRepository) | ||
{ | ||
_playerRepository = playerRepository; | ||
} | ||
|
||
public async Task<Result<PlayerId>> Handle(CreatePlayerCommand request, CancellationToken cancellationToken) | ||
{ | ||
var firstName = PlayerFirstName.Create(request.FirstName); | ||
|
||
if (firstName.IsFailed) | ||
{ | ||
return firstName.ToResult<PlayerId>(); | ||
} | ||
|
||
var lastName = PlayerLastName.Create(request.LastName); | ||
|
||
if (lastName.IsFailed) | ||
{ | ||
return lastName.ToResult<PlayerId>(); | ||
} | ||
|
||
var attackSkill = PlayerAttackSkill.Create(request.AttackSkill); | ||
|
||
if (attackSkill.IsFailed) | ||
{ | ||
return attackSkill.ToResult<PlayerId>(); | ||
} | ||
|
||
var midfieldSkill = PlayerMidfieldSkill.Create(request.MidfieldSkill); | ||
|
||
if (midfieldSkill.IsFailed) | ||
{ | ||
return midfieldSkill.ToResult<PlayerId>(); | ||
} | ||
|
||
var defenseSkill = PlayerDefenseSkill.Create(request.DefenseSkill); | ||
|
||
if (defenseSkill.IsFailed) | ||
{ | ||
return defenseSkill.ToResult<PlayerId>(); | ||
} | ||
|
||
var player = Player.Create( | ||
firstName.ValueOrDefault, | ||
lastName.ValueOrDefault, | ||
attackSkill.ValueOrDefault, | ||
midfieldSkill.ValueOrDefault, | ||
defenseSkill.ValueOrDefault); | ||
|
||
if (player.IsFailed) | ||
{ | ||
return player.ToResult<PlayerId>(); | ||
} | ||
|
||
await _playerRepository.AddAsync(player.Value, cancellationToken); | ||
|
||
return player.Value.Id; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
Football.Management.Application/Players/Queries/GetPlayerById/GetPlayerByIdQuery.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using Football.Management.Application.Abstractions; | ||
using Football.Management.Domain.Entities; | ||
using Football.Management.Domain.Identities; | ||
|
||
namespace Football.Management.Application.Players.Queries.GetPlayerById; | ||
|
||
public sealed record GetPlayerByIdQuery(PlayerId PlayerId) : IQuery<Player>; |
28 changes: 28 additions & 0 deletions
28
Football.Management.Application/Players/Queries/GetPlayerById/GetPlayerByIdQueryHandler.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using FluentResults; | ||
using Football.Management.Application.Abstractions; | ||
using Football.Management.Domain.Entities; | ||
using Football.Management.Domain.Repositories; | ||
|
||
namespace Football.Management.Application.Players.Queries.GetPlayerById; | ||
|
||
public class GetPlayerByIdQueryHandler : IQueryHandler<GetPlayerByIdQuery, Player> | ||
{ | ||
private readonly IPlayerRepository _playerRepository; | ||
|
||
public GetPlayerByIdQueryHandler(IPlayerRepository playerRepository) | ||
{ | ||
_playerRepository = playerRepository; | ||
} | ||
|
||
public async Task<Result<Player>> Handle(GetPlayerByIdQuery request, CancellationToken cancellationToken) | ||
{ | ||
var player = await _playerRepository.GetAsync(request.PlayerId, cancellationToken); | ||
|
||
if (player is null) | ||
{ | ||
return Result.Fail("Player was not found."); | ||
} | ||
|
||
return player; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Football.Management.Domain/Repositories/IPlayerRepository.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Football.Management.Domain.Entities; | ||
using Football.Management.Domain.Identities; | ||
|
||
namespace Football.Management.Domain.Repositories; | ||
|
||
public interface IPlayerRepository | ||
{ | ||
Task AddAsync(Player player, CancellationToken cancellationToken); | ||
Task<Player?> GetAsync(PlayerId 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Reflection; | ||
|
||
namespace Football.Management.Persistence; | ||
|
||
public class AssemblyReference | ||
{ | ||
public static readonly Assembly Assembly = typeof(AssemblyReference).Assembly; | ||
} |
13 changes: 13 additions & 0 deletions
13
Football.Management.Persistence/Football.Management.Persistence.csproj
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,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Football.Management.Domain\Football.Management.Domain.csproj" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
40 changes: 40 additions & 0 deletions
40
Football.Management.Persistence/Repositories/PlayerRepositoryInMemory.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Football.Management.Domain.Entities; | ||
using Football.Management.Domain.Identities; | ||
using Football.Management.Domain.Repositories; | ||
using Football.Management.Domain.ValueObjects; | ||
|
||
namespace Football.Management.Persistence.Repositories; | ||
|
||
public sealed class PlayerRepositoryInMemory : IPlayerRepository | ||
{ | ||
private List<Player> _players = new(); | ||
|
||
public PlayerRepositoryInMemory() | ||
{ | ||
var player = Player.Create( | ||
PlayerFirstName.Create("Kamil").ValueOrDefault, | ||
PlayerLastName.Create("Grabara").ValueOrDefault, | ||
PlayerAttackSkill.Create(0).ValueOrDefault, | ||
PlayerMidfieldSkill.Create(5).ValueOrDefault, | ||
PlayerDefenseSkill.Create(10).ValueOrDefault); | ||
|
||
_players.Add(player.Value); | ||
} | ||
|
||
public async Task AddAsync(Player player, CancellationToken cancellationToken) | ||
{ | ||
var result = await GetAsync(player.Id, cancellationToken); | ||
|
||
if (result is not null) | ||
{ | ||
return; | ||
} | ||
|
||
_players.Add(player); | ||
} | ||
|
||
public Task<Player?> GetAsync(PlayerId playerId, CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult(_players.FirstOrDefault(i => i.Id.Id == playerId.Id)); | ||
} | ||
} |
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,8 @@ | ||
using System.Reflection; | ||
|
||
namespace Football.Management.Presentation; | ||
|
||
public class AssemblyReference | ||
{ | ||
public static readonly Assembly Assembly = typeof(AssemblyReference).Assembly; | ||
} |
18 changes: 18 additions & 0 deletions
18
Football.Management.Presentation/Football.Management.Presentation.csproj
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Football.Management.Application\Football.Management.Application.csproj" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="MediatR" Version="12.2.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
49 changes: 49 additions & 0 deletions
49
Football.Management.Presentation/Players/Controllers/PlayersController.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using MediatR; | ||
using Football.Management.Application.Players.Commands.CreatePlayer; | ||
using Football.Management.Presentation.Players.Requests; | ||
using Football.Management.Domain.Identities; | ||
using Football.Management.Application.Players.Queries.GetPlayerById; | ||
using Football.Management.Presentation.Players.Responses; | ||
|
||
namespace Football.Management.Presentation.Players.Controllers; | ||
|
||
[ApiController] | ||
[Route("api/players")] | ||
public sealed class PlayersController : ControllerBase | ||
{ | ||
private readonly ISender _sender; | ||
|
||
public PlayersController(ISender sender) | ||
{ | ||
_sender = sender; | ||
} | ||
|
||
[HttpPost] | ||
public async Task<IActionResult> CreatePlayer(CreatePlayerRequest request, CancellationToken cancellationToken) | ||
{ | ||
var command = new CreatePlayerCommand(request.FirstName, request.LastName, request.AttackSkill, request.MidfieldSkill, request.DefenseSkill); | ||
var result = await _sender.Send(command, cancellationToken); | ||
return result.IsSuccess ? Ok(result.Value) : BadRequest(result.Errors); | ||
} | ||
|
||
[HttpGet("{playerId}")] | ||
public async Task<IActionResult> GetPlayerById(Guid playerId, CancellationToken cancellationToken) | ||
{ | ||
var query = new GetPlayerByIdQuery(new PlayerId(playerId)); | ||
var result = await _sender.Send(query, cancellationToken); | ||
if (result.IsSuccess) | ||
{ | ||
var player = result.Value; | ||
var response = new GetPlayerByIdResponse( | ||
player.Id.Id, | ||
player.FirstName.Value, | ||
player.LastName.Value, | ||
player.AttackSkill.Value, | ||
player.MidfieldSkill.Value, | ||
player.DefenseSkill.Value); | ||
return Ok(response); | ||
} | ||
return NotFound(result.Errors); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Football.Management.Presentation/Players/Requests/CreatePlayerRequest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Football.Management.Presentation.Players.Requests; | ||
|
||
public sealed record CreatePlayerRequest(string FirstName, string LastName, int AttackSkill, int MidfieldSkill, int DefenseSkill); |
3 changes: 3 additions & 0 deletions
3
Football.Management.Presentation/Players/Responses/GetPlayerByIdResponse.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Football.Management.Presentation.Players.Responses; | ||
|
||
public sealed record GetPlayerByIdResponse(Guid Id, string FirstName, string LastName, int AttackSkill, int MidfieldSkill, int DefenseSkill); |
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,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2" /> | ||
<PackageReference Include="Scrutor" Version="4.2.2" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Football.Management.Application\Football.Management.Application.csproj" /> | ||
<ProjectReference Include="..\Football.Management.Persistence\Football.Management.Persistence.csproj" /> | ||
<ProjectReference Include="..\Football.Management.Presentation\Football.Management.Presentation.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,6 @@ | ||
@Football.Management.Web_HostAddress = http://localhost:5137 | ||
|
||
GET {{Football.Management.Web_HostAddress}}/weatherforecast/ | ||
Accept: application/json | ||
|
||
### |
Oops, something went wrong.