-
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
f4a9d18
commit d8a8296
Showing
13 changed files
with
124 additions
and
79 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
10 changes: 0 additions & 10 deletions
10
Football.Management.Domain/Repositories/IPlayerRepository.cs
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
Football.Management.Domain/Repositories/Players/Errors/PlayerExists.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,9 @@ | ||
using FluentResults; | ||
using Football.Management.Domain.Entities; | ||
|
||
namespace Football.Management.Domain.Repositories.Players.Errors; | ||
|
||
public class PlayerExists(Player player) : Error | ||
{ | ||
public Player Player { get; } = player; | ||
} |
9 changes: 9 additions & 0 deletions
9
Football.Management.Domain/Repositories/Players/Errors/PlayerNotFound.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,9 @@ | ||
using FluentResults; | ||
using Football.Management.Domain.Identities; | ||
|
||
namespace Football.Management.Domain.Repositories.Players.Errors; | ||
|
||
public class PlayerNotFound(PlayerId PlayerId) : Error | ||
{ | ||
public PlayerId PlayerId { get; } = PlayerId; | ||
} |
11 changes: 11 additions & 0 deletions
11
Football.Management.Domain/Repositories/Players/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,11 @@ | ||
using FluentResults; | ||
using Football.Management.Domain.Entities; | ||
using Football.Management.Domain.Identities; | ||
|
||
namespace Football.Management.Domain.Repositories.Players; | ||
|
||
public interface IPlayerRepository | ||
{ | ||
Task<Result> AddAsync(Player player, CancellationToken cancellationToken); | ||
Task<Result<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
40 changes: 0 additions & 40 deletions
40
Football.Management.Persistence/Repositories/PlayerRepositoryInMemory.cs
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
Football.Management.Persistence/Repositories/Players/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,51 @@ | ||
using FluentResults; | ||
using Football.Management.Domain.Entities; | ||
using Football.Management.Domain.Identities; | ||
using Football.Management.Domain.Repositories.Players; | ||
using Football.Management.Domain.Repositories.Players.Errors; | ||
using Football.Management.Domain.ValueObjects; | ||
|
||
namespace Football.Management.Persistence.Repositories.Players; | ||
|
||
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<Result> AddAsync(Player player, CancellationToken cancellationToken) | ||
{ | ||
var playerResult = await GetAsync(player.Id, cancellationToken); | ||
|
||
if (playerResult.IsSuccess) | ||
{ | ||
return Result.Fail(new PlayerExists(player)); | ||
} | ||
|
||
_players.Add(player); | ||
|
||
return Result.Ok(); | ||
} | ||
|
||
public Task<Result<Player>> GetAsync(PlayerId playerId, CancellationToken cancellationToken) | ||
{ | ||
var player = _players.FirstOrDefault(i => i.Id.Id == playerId.Id); | ||
|
||
if (player is null) | ||
{ | ||
return Task.FromResult(Result.Fail<Player>(new PlayerNotFound(playerId))); | ||
} | ||
|
||
return Task.FromResult(Result.Ok(player)); | ||
} | ||
} |
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
3 changes: 0 additions & 3 deletions
3
Football.Management.Presentation/Players/Requests/CreatePlayerRequest.cs
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
Football.Management.Presentation/Players/Requests/PlayerPostRequest.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 PlayerPostRequest(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