Ajout des Converter pour les DTO
continuous-integration/drone/push Build is failing Details

EF
Théo DUPIN 2 years ago
parent 91e6fb5e48
commit 915942b9b2

@ -27,6 +27,8 @@ namespace Model
public GameMode GameMode { get; set; }
public Player Player { get; set; }
//public Game(TimeSpan duration, DateOnly date, Dictionary<Player,Grille> grilles, Dictionary<Player, int> scores, List<Turn> turns, GameMode gameMode,int id=0)
//{
@ -50,7 +52,7 @@ namespace Model
scores.Add(owner, 0);
GameMode = gameMode;
Id = id;
Player = owner;
}
public bool AddPlayerToGame(Player player)

@ -1,9 +1,32 @@
using Model;
using System.Collections.Generic;
using Trek12_API.DTO;
namespace Trek12_API.Converter
{
public class GameConverter
public static class GameConverter
{
public static GameDTO toDTO(this Game game)
{
var gameDTO = new GameDTO(game.Id, game.Date, game.Player.toDTO(), game.GameMode.toDTO());
gameDTO.Duration = game.Duration;
gameDTO.Date = game.Date;
gameDTO.Turns = new List<TurnDTO>();
foreach (var turn in game.Turns)
{
gameDTO.Turns.Add(turn.toDTO());
}
gameDTO.Grilles = new Dictionary<PlayerDTO, GrilleDTO>();
foreach ( var grille in game.Grilles)
{
gameDTO.Grilles.Add(grille.Key.toDTO(), grille.Value.toDTO());
}
gameDTO.Scores = new Dictionary<PlayerDTO, int>();
foreach ( var score in game.Scores)
{
gameDTO.Scores.Add(score.Key.toDTO(), score.Value);
}
return gameDTO;
}
}
}

@ -0,0 +1,17 @@
using Model;
using Trek12_API.DTO;
namespace Trek12_API.Converter
{
public static class GameModeConverter
{
public static GamemodeDTO toDTO(this GameMode gameMode)
{
return new GamemodeDTO()
{
Id = gameMode.Id,
Name = gameMode.Name,
};
}
}
}

@ -0,0 +1,20 @@
using Model;
using Trek12_API.DTO;
namespace Trek12_API.Converter
{
public static class GrilleConverter
{
public static GrilleDTO toDTO(this Grille grille)
{
return new GrilleDTO()
{
Id = grille.Id,
NbChaines = grille.NbChaine,
NbZones = grille.NbZone,
MaxChaines = grille.MaxChaine,
MaxZones = grille.MaxZone
};
}
}
}

@ -0,0 +1,18 @@
using Model;
using Trek12_API.DTO;
namespace Trek12_API.Converter
{
public static class TurnConverter
{
public static TurnDTO toDTO(this Turn turn)
{
return new TurnDTO()
{
Id = turn.Id,
diceValue1 = turn.DiceValue1,
diceValue2 = turn.DiceValue2,
};
}
}
}

@ -9,12 +9,10 @@ namespace Trek12_API.DTO
public TimeSpan Duration { get; set; }
public DateOnly Date { get; set; }
public List<TurnDTO> Turns { get; set; }
public Dictionary<PlayerDTO, GrilleDTO> Grilles { get; set; }
public Dictionary<PlayerDTO, int> Scores { get; set; }
public GamemodeDTO GameMode { get; set; }
public PlayerDTO Player { get; set; }
public GameDTO(int id, DateOnly date, PlayerDTO owner, GamemodeDTO gameMode)
{
@ -26,6 +24,7 @@ namespace Trek12_API.DTO
Scores.Add(owner, 0);
GameMode = gameMode;
Id = id;
Player = owner;
}
}
}

@ -4,7 +4,6 @@
{
public int Id { get; set; }
public int diceValue1 { get; set; }
public string diceValue2 { get; set; }
public int diceValue2 { get; set; }
}
}

Loading…
Cancel
Save