From 8f1f3f2863deb11c6c5ce4042b9225487ef95600 Mon Sep 17 00:00:00 2001 From: Maxence Lanone Date: Fri, 24 Mar 2023 13:42:10 +0100 Subject: [PATCH] =?UTF-8?q?:construction:=20ajout=20dbadatamaneger=20+=20m?= =?UTF-8?q?anque=20a=20impl=C3=A9menter=20certaines=20methodes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/DbDataManager/CaseManager.cs | 34 ++++++++ Sources/DbDataManager/DbDataManager.cs | 22 ++++++ Sources/DbDataManager/DbDataManager.csproj | 19 +++++ Sources/DbDataManager/ExtensionDataManager.cs | 64 +++++++++++++++ Sources/DbDataManager/GameManager.cs | 76 ++++++++++++++++++ Sources/DbDataManager/GameModeManager.cs | 34 ++++++++ Sources/DbDataManager/GrilleManager.cs | 33 ++++++++ Sources/DbDataManager/Mapper/CaseMapper.cs | 11 +++ Sources/DbDataManager/Mapper/GameMapper.cs | 11 +++ .../DbDataManager/Mapper/GameModeMapper.cs | 11 +++ Sources/DbDataManager/Mapper/GrilleMapper.cs | 11 +++ Sources/DbDataManager/Mapper/PlayerMapper.cs | 14 ++++ Sources/DbDataManager/Mapper/StatsMapper.cs | 11 +++ Sources/DbDataManager/Mapper/TurnMapper.cs | 11 +++ Sources/DbDataManager/PlayerManager.cs | 78 +++++++++++++++++++ Sources/DbDataManager/StatsManager.cs | 33 ++++++++ Sources/DbDataManager/TurnManager.cs | 33 ++++++++ Sources/Tests/DbConsole/DbConsole.csproj | 6 +- Sources/Tests/ModelTest/ModelTest.csproj | 8 +- Sources/Trek12_API.sln | 6 ++ Sources/Trek12_Lib/EntityFrameWorkLib.csproj | 6 +- Sources/Trek12_Lib/PlayerEntity.cs | 1 + 22 files changed, 523 insertions(+), 10 deletions(-) create mode 100644 Sources/DbDataManager/CaseManager.cs create mode 100644 Sources/DbDataManager/DbDataManager.cs create mode 100644 Sources/DbDataManager/DbDataManager.csproj create mode 100644 Sources/DbDataManager/ExtensionDataManager.cs create mode 100644 Sources/DbDataManager/GameManager.cs create mode 100644 Sources/DbDataManager/GameModeManager.cs create mode 100644 Sources/DbDataManager/GrilleManager.cs create mode 100644 Sources/DbDataManager/Mapper/CaseMapper.cs create mode 100644 Sources/DbDataManager/Mapper/GameMapper.cs create mode 100644 Sources/DbDataManager/Mapper/GameModeMapper.cs create mode 100644 Sources/DbDataManager/Mapper/GrilleMapper.cs create mode 100644 Sources/DbDataManager/Mapper/PlayerMapper.cs create mode 100644 Sources/DbDataManager/Mapper/StatsMapper.cs create mode 100644 Sources/DbDataManager/Mapper/TurnMapper.cs create mode 100644 Sources/DbDataManager/PlayerManager.cs create mode 100644 Sources/DbDataManager/StatsManager.cs create mode 100644 Sources/DbDataManager/TurnManager.cs diff --git a/Sources/DbDataManager/CaseManager.cs b/Sources/DbDataManager/CaseManager.cs new file mode 100644 index 0000000..8a524fb --- /dev/null +++ b/Sources/DbDataManager/CaseManager.cs @@ -0,0 +1,34 @@ +using System; +using Model; +namespace DbDataManager +{ + public class CaseManager: ICasesManager + { + + public Task AddItem(Case? item) + { + throw new NotImplementedException(); + } + + public Task DeleteItem(Case? item) + { + throw new NotImplementedException(); + } + + public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task GetNbItems() + { + throw new NotImplementedException(); + } + + public Task UpdateItem(Case? oldItem, Case? newItem) + { + throw new NotImplementedException(); + } + } +} + diff --git a/Sources/DbDataManager/DbDataManager.cs b/Sources/DbDataManager/DbDataManager.cs new file mode 100644 index 0000000..e04e083 --- /dev/null +++ b/Sources/DbDataManager/DbDataManager.cs @@ -0,0 +1,22 @@ +using System; +using Model; + +namespace DbDataManager +{ + public class DbDataManager : IDataManager + { + public IPlayersManager PlayersMgr => new PlayerManager(); + public IGamesManager GamesMgr => new GameManager(); + + public IGamesModeManager GamesModeMgr => new GameModeManager(); + + public ICasesManager CasesMgr => new CaseManager(); + + public IGrillesManager GrillesMgr => new GrilleManager(); + + public IStatsManager StatsMgr => new StatsManager(); + + public ITurnsManager TurnsMgr => new TurnManager(); + } +} + diff --git a/Sources/DbDataManager/DbDataManager.csproj b/Sources/DbDataManager/DbDataManager.csproj new file mode 100644 index 0000000..0676990 --- /dev/null +++ b/Sources/DbDataManager/DbDataManager.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/Sources/DbDataManager/ExtensionDataManager.cs b/Sources/DbDataManager/ExtensionDataManager.cs new file mode 100644 index 0000000..839e9ea --- /dev/null +++ b/Sources/DbDataManager/ExtensionDataManager.cs @@ -0,0 +1,64 @@ +using System; +using Model; +namespace DbDataManager +{ + static class ExtensionDataManager + { + internal static Task> GetItemsWithFilterAndOrdering(this IEnumerable collection, + Func filter, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + IEnumerable temp = collection; + temp = temp.Where(item => filter(item)); + if (orderingPropertyName != null) + { + var prop = typeof(T).GetProperty(orderingPropertyName!); + if (prop != null) + { + temp = descending ? temp.OrderByDescending(item => prop.GetValue(item)) + : temp.OrderBy(item => prop.GetValue(item)); + } + } + return Task.FromResult>(temp.Skip(index * count).Take(count)); + } + + internal static Task GetNbItemsWithFilter(this IEnumerable collection, Func filter) + { + return Task.FromResult(collection.Count(item => filter(item))); + } + + internal static Task AddItem(this IList collection, T? item) + { + if (item == null || collection.Contains(item)) + { + return Task.FromResult(default(T)); + } + collection.Add(item); + return Task.FromResult(item); + } + + internal static Task DeleteItem(this IList collection, T? item) + { + if (item == null) + { + return Task.FromResult(false); + } + bool result = collection.Remove(item!); + return Task.FromResult(result); + } + + internal static Task UpdateItem(this IList collection, T? oldItem, T? newItem) + { + if (oldItem == null || newItem == null) return Task.FromResult(default(T)); + + if (!collection.Contains(oldItem)) + { + return Task.FromResult(default(T)); + } + + collection.Remove(oldItem!); + collection.Add(newItem!); + return Task.FromResult(newItem); + } + } +} + diff --git a/Sources/DbDataManager/GameManager.cs b/Sources/DbDataManager/GameManager.cs new file mode 100644 index 0000000..65eb471 --- /dev/null +++ b/Sources/DbDataManager/GameManager.cs @@ -0,0 +1,76 @@ +using System; +using EntityFrameWorkLib; +using Model; +using System.Linq; +using Shared; +namespace DbDataManager +{ + public class GameManager: IGamesManager + { + private TrekContext trekcontext; + + public Task AddCaseValueToPlayer(int idGame, int idPlayer, int value, int index) + { + throw new NotImplementedException(); + } + + public async Task AddItem(Game? item) + { + if (item == null) + { + return null; + + } + var addItem = await trekcontext.AddAsync(item); + await trekcontext.SaveChangesAsync(); + return addItem.Entity; + } + + public Task AddPlayer(Player player) + { + throw new NotImplementedException(); + } + + public Task AddScoreToPlayer(int idGame, int idPlayer, int score) + { + throw new NotImplementedException(); + } + + public Task AddTime(TimeSpan time) + { + var game = trekcontext.Game.FirstOrDefault(); + if (game == null) + { + return Task.FromResult(false); + } + game.AddTime(time); + return Task.FromResult(true); + } + + public Task AddTurn(Turn turn) + { + throw new NotImplementedException(); + } + + public Task DeleteItem(Game? item) + { + throw new NotImplementedException(); + } + + public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task GetNbItems() + { + throw new NotImplementedException(); + } + + public Task UpdateItem(Game? oldItem, Game? newItem) + { + throw new NotImplementedException(); + } + } +} + diff --git a/Sources/DbDataManager/GameModeManager.cs b/Sources/DbDataManager/GameModeManager.cs new file mode 100644 index 0000000..347a4f7 --- /dev/null +++ b/Sources/DbDataManager/GameModeManager.cs @@ -0,0 +1,34 @@ +using System; +using Model; +namespace DbDataManager +{ + public class GameModeManager: IGamesModeManager + { + + public Task AddItem(GameMode? item) + { + throw new NotImplementedException(); + } + + public Task DeleteItem(GameMode? item) + { + throw new NotImplementedException(); + } + + public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task GetNbItems() + { + throw new NotImplementedException(); + } + + public Task UpdateItem(GameMode? oldItem, GameMode? newItem) + { + throw new NotImplementedException(); + } + } +} + diff --git a/Sources/DbDataManager/GrilleManager.cs b/Sources/DbDataManager/GrilleManager.cs new file mode 100644 index 0000000..14504f2 --- /dev/null +++ b/Sources/DbDataManager/GrilleManager.cs @@ -0,0 +1,33 @@ +using System; +using Model; +namespace DbDataManager +{ + public class GrilleManager: IGrillesManager + { + public Task AddItem(Grille? item) + { + throw new NotImplementedException(); + } + + public Task DeleteItem(Grille? item) + { + throw new NotImplementedException(); + } + + public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task GetNbItems() + { + throw new NotImplementedException(); + } + + public Task UpdateItem(Grille? oldItem, Grille? newItem) + { + throw new NotImplementedException(); + } + } +} + diff --git a/Sources/DbDataManager/Mapper/CaseMapper.cs b/Sources/DbDataManager/Mapper/CaseMapper.cs new file mode 100644 index 0000000..ad9aed4 --- /dev/null +++ b/Sources/DbDataManager/Mapper/CaseMapper.cs @@ -0,0 +1,11 @@ +using System; +namespace DbDataManager.Mapper +{ + public class CaseMapper + { + public CaseMapper() + { + } + } +} + diff --git a/Sources/DbDataManager/Mapper/GameMapper.cs b/Sources/DbDataManager/Mapper/GameMapper.cs new file mode 100644 index 0000000..7a3cb73 --- /dev/null +++ b/Sources/DbDataManager/Mapper/GameMapper.cs @@ -0,0 +1,11 @@ +using System; +namespace DbDataManager.Mapper +{ + public class GameMapper + { + public GameMapper() + { + } + } +} + diff --git a/Sources/DbDataManager/Mapper/GameModeMapper.cs b/Sources/DbDataManager/Mapper/GameModeMapper.cs new file mode 100644 index 0000000..8780d5d --- /dev/null +++ b/Sources/DbDataManager/Mapper/GameModeMapper.cs @@ -0,0 +1,11 @@ +using System; +namespace DbDataManager.Mapper +{ + public class GameModeMapper + { + public GameModeMapper() + { + } + } +} + diff --git a/Sources/DbDataManager/Mapper/GrilleMapper.cs b/Sources/DbDataManager/Mapper/GrilleMapper.cs new file mode 100644 index 0000000..1c080db --- /dev/null +++ b/Sources/DbDataManager/Mapper/GrilleMapper.cs @@ -0,0 +1,11 @@ +using System; +namespace DbDataManager.Mapper +{ + public class GrilleMapper + { + public GrilleMapper() + { + } + } +} + diff --git a/Sources/DbDataManager/Mapper/PlayerMapper.cs b/Sources/DbDataManager/Mapper/PlayerMapper.cs new file mode 100644 index 0000000..0a7fb90 --- /dev/null +++ b/Sources/DbDataManager/Mapper/PlayerMapper.cs @@ -0,0 +1,14 @@ +using System; +using EntityFrameWorkLib; +using Model; +namespace DbDataManager.Mapper +{ + public static class PlayerMapper + { + public static Player ToPoco(this PlayerEntity player) + { + return new Player(player.Pseudo, new Stats { player.NbWin, player.NbPlayed, player.MaxChain, player.MaxZone, player.MaxPoints }, player.PlayerId); + } + } +} + diff --git a/Sources/DbDataManager/Mapper/StatsMapper.cs b/Sources/DbDataManager/Mapper/StatsMapper.cs new file mode 100644 index 0000000..09ecd7c --- /dev/null +++ b/Sources/DbDataManager/Mapper/StatsMapper.cs @@ -0,0 +1,11 @@ +using System; +namespace DbDataManager.Mapper +{ + public class StatsMapper + { + public StatsMapper() + { + } + } +} + diff --git a/Sources/DbDataManager/Mapper/TurnMapper.cs b/Sources/DbDataManager/Mapper/TurnMapper.cs new file mode 100644 index 0000000..917c5a4 --- /dev/null +++ b/Sources/DbDataManager/Mapper/TurnMapper.cs @@ -0,0 +1,11 @@ +using System; +namespace DbDataManager.Mapper +{ + public class TurnMapper + { + public TurnMapper() + { + } + } +} + diff --git a/Sources/DbDataManager/PlayerManager.cs b/Sources/DbDataManager/PlayerManager.cs new file mode 100644 index 0000000..0349231 --- /dev/null +++ b/Sources/DbDataManager/PlayerManager.cs @@ -0,0 +1,78 @@ +using System; +using EntityFrameWorkLib; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Model; + +namespace DbDataManager +{ + public class PlayerManager: IPlayersManager + { + private TrekContext trekContext; + + public async Task AddItem(Player? item) + { + if (item == null) + { + return null; + + } + var addItem = await trekContext.AddAsync(item); + await trekContext.SaveChangesAsync(); + return addItem.Entity; + } + + public async Task DeleteItem(Player? item) + { + if (item == null) + { + return false; + } + var deleteItem = trekContext.Remove(item); + trekContext.SaveChanges(); + return true; + } + + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + + //IEnumerable players = trekContext.Players.Skip(index * count) + // .Take(count) + // .OrderBy(champions => orderingPropertyName) + // .Select(champions => champions.ToPoco()); + //return players; + throw new NotImplementedException(); + } + + private Func filterByPseudo = (player, substring) => player.Pseudo.Contains(substring, StringComparison.InvariantCultureIgnoreCase); + private Func filterById = (player, id) => player.Id.Equals(id); + + public async Task> GetItemsById(int id) + { + //return trekContext.Players.GetItemsWithFilterAndOrdering(player => filterById(player, id), 0, 1); + throw new NotImplementedException(); + } + + public Task> GetItemsByPseudo(string charPseudo) + { + //return trekContext.Players.GetItemsWithFilterAndOrdering(player => filterByPseudo(player, charPseudo), 0, trekContext.Players.Count()); + throw new NotImplementedException(); + } + + public Task GetNbItems() + { + return Task.FromResult(trekContext.Players.Count()); + } + + public Task GetNbItemsByPseudo(string charPseudo) + { + throw new NotImplementedException(); + } + + public Task UpdateItem(Player? oldItem, Player? newItem) + { + //return trekContext.Players.UpdateItem(oldItem, newItem); + throw new NotImplementedException(); + } + } +} + diff --git a/Sources/DbDataManager/StatsManager.cs b/Sources/DbDataManager/StatsManager.cs new file mode 100644 index 0000000..8d6c0a4 --- /dev/null +++ b/Sources/DbDataManager/StatsManager.cs @@ -0,0 +1,33 @@ +using System; +using Model; +namespace DbDataManager +{ + public class StatsManager : IStatsManager + { + public Task AddItem(Stats? item) + { + throw new NotImplementedException(); + } + + public Task DeleteItem(Stats? item) + { + throw new NotImplementedException(); + } + + public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task GetNbItems() + { + throw new NotImplementedException(); + } + + public Task UpdateItem(Stats? oldItem, Stats? newItem) + { + throw new NotImplementedException(); + } + } +} + diff --git a/Sources/DbDataManager/TurnManager.cs b/Sources/DbDataManager/TurnManager.cs new file mode 100644 index 0000000..25046e8 --- /dev/null +++ b/Sources/DbDataManager/TurnManager.cs @@ -0,0 +1,33 @@ +using System; +using Model; +namespace DbDataManager +{ + public class TurnManager : ITurnsManager + { + public Task AddItem(Turn? item) + { + throw new NotImplementedException(); + } + + public Task DeleteItem(Turn? item) + { + throw new NotImplementedException(); + } + + public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task GetNbItems() + { + throw new NotImplementedException(); + } + + public Task UpdateItem(Turn? oldItem, Turn? newItem) + { + throw new NotImplementedException(); + } + } +} + diff --git a/Sources/Tests/DbConsole/DbConsole.csproj b/Sources/Tests/DbConsole/DbConsole.csproj index ed572bd..edbe25d 100644 --- a/Sources/Tests/DbConsole/DbConsole.csproj +++ b/Sources/Tests/DbConsole/DbConsole.csproj @@ -20,11 +20,11 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/Sources/Tests/ModelTest/ModelTest.csproj b/Sources/Tests/ModelTest/ModelTest.csproj index c5d1063..18ed80f 100644 --- a/Sources/Tests/ModelTest/ModelTest.csproj +++ b/Sources/Tests/ModelTest/ModelTest.csproj @@ -9,13 +9,13 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/Sources/Trek12_API.sln b/Sources/Trek12_API.sln index c682d4f..801b4c4 100644 --- a/Sources/Trek12_API.sln +++ b/Sources/Trek12_API.sln @@ -23,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csp EndProject Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{7DF17583-2166-4ABE-82EE-F63CEE2132C2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbDataManager", "..\DbDataManager\DbDataManager.csproj", "{BECCFECE-4BFE-49E6-BD8F-5A791180922C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -61,6 +63,10 @@ Global {7DF17583-2166-4ABE-82EE-F63CEE2132C2}.Debug|Any CPU.Build.0 = Debug|Any CPU {7DF17583-2166-4ABE-82EE-F63CEE2132C2}.Release|Any CPU.ActiveCfg = Release|Any CPU {7DF17583-2166-4ABE-82EE-F63CEE2132C2}.Release|Any CPU.Build.0 = Release|Any CPU + {BECCFECE-4BFE-49E6-BD8F-5A791180922C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BECCFECE-4BFE-49E6-BD8F-5A791180922C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BECCFECE-4BFE-49E6-BD8F-5A791180922C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BECCFECE-4BFE-49E6-BD8F-5A791180922C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Sources/Trek12_Lib/EntityFrameWorkLib.csproj b/Sources/Trek12_Lib/EntityFrameWorkLib.csproj index b8e4722..473649d 100644 --- a/Sources/Trek12_Lib/EntityFrameWorkLib.csproj +++ b/Sources/Trek12_Lib/EntityFrameWorkLib.csproj @@ -13,9 +13,9 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/Sources/Trek12_Lib/PlayerEntity.cs b/Sources/Trek12_Lib/PlayerEntity.cs index 516ca91..a493479 100644 --- a/Sources/Trek12_Lib/PlayerEntity.cs +++ b/Sources/Trek12_Lib/PlayerEntity.cs @@ -13,6 +13,7 @@ namespace EntityFrameWorkLib public int NbWin { get; set; } public int NbPlayed { get; set; } public int MaxZone { get; set; } + public int MaxChain { get; set; } public int MaxPoints { get; set; } public int NbPoints { get; set; } }