ajout de la commande de creation de match
This commit was merged in pull request #7.
This commit is contained in:
11
Src/Giants.Core/Src/Commands/BaseCommandResult.cs
Normal file
11
Src/Giants.Core/Src/Commands/BaseCommandResult.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Giants.Core.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// Class de base des resultats de commande. Chaque commande doit retourner un resultat quand elle
|
||||
/// s'execute et les données de ce resultat est propre a la commande
|
||||
/// </summary>
|
||||
public abstract class BaseCommandResult
|
||||
{
|
||||
/// <summary> indique si le resultat est un success (true) ou un echec(false) </summary>
|
||||
public bool Success { get; init; } = false;
|
||||
}
|
||||
17
Src/Giants.Core/Src/Commands/CommandBase.cs
Normal file
17
Src/Giants.Core/Src/Commands/CommandBase.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace Giants.Core.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// Base des commande permettant d'agir sur le modele
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Le type de resultat que retourne cette commande </typeparam>
|
||||
public abstract class BaseCommand<T> where T : BaseCommandResult
|
||||
{
|
||||
protected abstract T LocalExecute();
|
||||
|
||||
/// <summary> Executer la commande, si nécessaire il faut avoir rempli les parametres en amont </summary>
|
||||
public T Execute()
|
||||
{
|
||||
// C'est ici que sera validé l'exécution
|
||||
return LocalExecute();
|
||||
}
|
||||
}
|
||||
38
Src/Giants.Core/Src/Commands/NewMatchCommand.cs
Normal file
38
Src/Giants.Core/Src/Commands/NewMatchCommand.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Giants.Core.Interfaces;
|
||||
|
||||
namespace Giants.Core.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// Commande permettant de créer un nouveau match
|
||||
/// </summary>
|
||||
public class NewMatchCommand : BaseCommand<NewMatchResult>
|
||||
{
|
||||
private readonly IMatchRepository _repo;
|
||||
|
||||
/// <summary>
|
||||
/// constructeur
|
||||
/// </summary>
|
||||
/// <param name="repo">le repository de match</param>
|
||||
public NewMatchCommand(IMatchRepository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override sealed NewMatchResult LocalExecute()
|
||||
{
|
||||
var match = _repo.CreateMatch();
|
||||
|
||||
return new NewMatchResult()
|
||||
{
|
||||
Match = match,
|
||||
Success = match != null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class NewMatchResult : BaseCommandResult
|
||||
{
|
||||
/// <summary> Le match créé si success </summary>
|
||||
public Match? Match { get; init; }
|
||||
}
|
||||
@@ -11,6 +11,7 @@ namespace Giants.Core;
|
||||
public class Match
|
||||
{
|
||||
#region données statiques
|
||||
public int Id { get; init; }
|
||||
IHexagonalGrid _grid;
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -11,4 +11,10 @@ public interface IMatchRepository
|
||||
/// <param name="matchId">L'id unique du match a récupérer</param>
|
||||
/// <returns>le match s'il existe ou null dans le cas contraire</returns>
|
||||
Match? GetMatch(int matchId);
|
||||
|
||||
/// <summary>
|
||||
/// Créer un match avec un ID unique
|
||||
/// </summary>
|
||||
/// <returns>le nouveau match a son état initial</returns>
|
||||
Match? CreateMatch();
|
||||
}
|
||||
Reference in New Issue
Block a user