From 38e84e3a838b1ff9ae155121af5cc4e01561efa3 Mon Sep 17 00:00:00 2001 From: etudiant Date: Tue, 17 Jan 2023 17:22:13 +0100 Subject: [PATCH] Parti end poin --- Sources/BowlingApi/BowlingApi.csproj | 15 +++ .../Controllers/PartieController.cs | 63 +++++++++++ Sources/BowlingApi/Program.cs | 2 + .../BowlingApi/Properties/launchSettings.json | 6 +- Sources/BowlingApi/bowling.db | Bin 45056 -> 45056 bytes Sources/BowlingApi/bowling.db-shm | Bin 32768 -> 0 bytes Sources/BowlingApi/bowling.db-wal | Bin 16512 -> 0 bytes .../Interface/IEquipeRepository.cs | 2 +- .../Interface/IpartieRepository.cs | 17 +++ .../Interface/PartieRepository.cs | 58 +++++++++++ .../Interfaces/IPartieService.cs | 16 +++ .../Interfaces/PartieService.cs | 98 ++++++++++++++++++ Sources/BowlingService/JoueurService.cs | 2 +- Sources/DTOs/EquipeDTO.cs | 1 - Sources/DTOs/FrameDTO.cs | 7 +- Sources/DTOs/JoueurDTO.cs | 2 - Sources/DTOs/PartieDTO.cs | 8 +- Sources/Mapper/PartieProfile.cs | 2 +- .../BowlingAppUnitTest/BowlingAppUnitTest.sln | 25 +++++ 19 files changed, 303 insertions(+), 21 deletions(-) create mode 100644 Sources/BowlingApi/Controllers/PartieController.cs delete mode 100644 Sources/BowlingApi/bowling.db-shm delete mode 100644 Sources/BowlingApi/bowling.db-wal create mode 100644 Sources/BowlingRepository/Interface/IpartieRepository.cs create mode 100644 Sources/BowlingRepository/Interface/PartieRepository.cs create mode 100644 Sources/BowlingService/Interfaces/IPartieService.cs create mode 100644 Sources/BowlingService/Interfaces/PartieService.cs create mode 100644 Sources/Tests/BowlingAppUnitTest/BowlingAppUnitTest.sln diff --git a/Sources/BowlingApi/BowlingApi.csproj b/Sources/BowlingApi/BowlingApi.csproj index 64f00fb..7996562 100644 --- a/Sources/BowlingApi/BowlingApi.csproj +++ b/Sources/BowlingApi/BowlingApi.csproj @@ -7,9 +7,18 @@ 11 + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + @@ -18,6 +27,12 @@ + + + + + + PreserveNewest diff --git a/Sources/BowlingApi/Controllers/PartieController.cs b/Sources/BowlingApi/Controllers/PartieController.cs new file mode 100644 index 0000000..848d695 --- /dev/null +++ b/Sources/BowlingApi/Controllers/PartieController.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using BowlingService; +using BowlingService.Interfaces; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace BowlingApi.Controllers +{ + + + [Route("api/[controller]")] + [ApiController] + public class PartieController : ControllerBase + { + + + private IpartieService _partieService; + + public PartieController(IpartieService partieService) + { + _partieService = partieService; + } + + + + + // GET: api/Partie + [HttpGet] + public IActionResult Get() + { + var result = _partieService.GetAll().Result; + return Ok(result); + } + + // GET: api/Partie/5 + [HttpGet("{name}")] + public IActionResult Get(string name) + { + return Ok(_partieService.GetDataWithName(name)); + } + + // POST: api/Partie + [HttpPost] + public void Post([FromBody] string value) + { + } + + // PUT: api/Partie/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE: api/Partie/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git a/Sources/BowlingApi/Program.cs b/Sources/BowlingApi/Program.cs index 2a009e5..fd44c1e 100644 --- a/Sources/BowlingApi/Program.cs +++ b/Sources/BowlingApi/Program.cs @@ -18,6 +18,8 @@ builder.Services.AddSwaggerGen(); builder.Services.AddAutoMapper(typeof(JoueurProfile)); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); var app = builder.Build(); diff --git a/Sources/BowlingApi/Properties/launchSettings.json b/Sources/BowlingApi/Properties/launchSettings.json index ea7e601..018693f 100644 --- a/Sources/BowlingApi/Properties/launchSettings.json +++ b/Sources/BowlingApi/Properties/launchSettings.json @@ -1,4 +1,4 @@ -{ +{ "$schema": "https://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, @@ -11,7 +11,6 @@ "profiles": { "http": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", "applicationUrl": "http://localhost:5229", @@ -21,7 +20,6 @@ }, "https": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", "applicationUrl": "https://localhost:7097;http://localhost:5229", @@ -38,4 +36,4 @@ } } } -} +} \ No newline at end of file diff --git a/Sources/BowlingApi/bowling.db b/Sources/BowlingApi/bowling.db index b257dc97c3c1a54a3fd0845c3301fcc914f52b80..ebb188c75a2401b94e1f6f696182f03dfbb7955e 100644 GIT binary patch delta 125 zcmZp8z|`=7X~S)QM)t{f{8dHyk20|H&u8HO%Kwu8F8@XTHT*mI=WiAi=;YVpW@llL zW(dnnF3B%4=4J(P%D@~WE;behNro_I&k+A01_lP6%_rln4TRYF?=kTI;s4J6iT^GC Z3;xIa_kiY{;AdrFW?*FB{CK{s005h`CF=kH delta 89 zcmV-f0H*(d-~xc)0Yr_15$Fe|^jAD?<9z5Dpc zdt9|vJT+sb-maz&1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAn@A)Y1^F; z$Wx#Q^*lfB*8~UY5C-76?0s-|#!)OZ9M}qiB3jtk1;j)|5fexw1W6G@0+&S4Mi472MQm&Y z>tLTIomfV#M2&?a#KJ}qEhM-bP1GOY7rX;E?9T1N?o%Ff!z<=0^<8xlwULUOv+h#w zws*8;RGvLMdMHb#eB4I;e0;6HW53uMWzJT;XFba8d0?KmY;|fB*y_009U< z00Izz00bcLI|8nulShl`xm?B{bWEK>6c0ycCa2|bT0-wH9KBwTgk{|kpT>cYv90OU zNr_k@HYT?k>Nbt<0(5fPvl(A11-VLs%fw}V;0v_^0Rad=00Izz00bZa0SG_<0uX?} z9~W>n;c3xKK9%>gmLo(+8}*Y5sqBb6w`)%&{aiZb2IQKzVOI4DsHgc|ptf%B=(Bq@ z)h}T2?w5W6IYmGK0uX=z1Rwwb2tWV=5P$##AnOIJaO8EG{}D_q z&li^3HwIME;!ENee&Tz+<0@avDFOlzfB*y_009U<00Izz00bZafqx^Q3(_o=OqC3k Mbd`ik0U^kK1r2U;_W%F@ diff --git a/Sources/BowlingRepository/Interface/IEquipeRepository.cs b/Sources/BowlingRepository/Interface/IEquipeRepository.cs index c782472..c0d3ef9 100644 --- a/Sources/BowlingRepository/Interface/IEquipeRepository.cs +++ b/Sources/BowlingRepository/Interface/IEquipeRepository.cs @@ -1,4 +1,4 @@ -using BowlingEF.Entities; + using BowlingEF.Entities; namespace BowlingRepository.Interface; diff --git a/Sources/BowlingRepository/Interface/IpartieRepository.cs b/Sources/BowlingRepository/Interface/IpartieRepository.cs new file mode 100644 index 0000000..9381a82 --- /dev/null +++ b/Sources/BowlingRepository/Interface/IpartieRepository.cs @@ -0,0 +1,17 @@ +using System; +using BowlingEF.Entities; + +namespace BowlingRepository.Interface +{ + public interface IpartieRepository + { + public Task Add(PartieEntity _partie); + public Task Delete(PartieEntity _partie); + public Task Update(PartieEntity _partie); + public Task> GetAll(); + public Task> GetAllWithDate(DateTime date); + public Task GetDataWithName(string nom); + + } +} + diff --git a/Sources/BowlingRepository/Interface/PartieRepository.cs b/Sources/BowlingRepository/Interface/PartieRepository.cs new file mode 100644 index 0000000..43f8020 --- /dev/null +++ b/Sources/BowlingRepository/Interface/PartieRepository.cs @@ -0,0 +1,58 @@ +using System; +using BowlingEF.Context; +using BowlingEF.Entities; +using Microsoft.EntityFrameworkCore; + +namespace BowlingRepository.Interface +{ + public class PartieRepository:IpartieRepository + { + private readonly BowlingContext _context; + public PartieRepository() + { + _context = new BowlingContext(); + } + + public async Task Add(PartieEntity partie) + { + _context.Parties.Add( partie); + return await _context.SaveChangesAsync() > 0; + + + } + + public async Task Delete(PartieEntity _partie) + { + using (var context = new BowlingContext()) + { + PartieEntity entity = context.Parties.Find(_partie.Id); + context.Parties.Remove(entity); + return await context.SaveChangesAsync() > 0; + } + } + + + + public async Task> GetAll() + { + return await _context.Parties.ToListAsync(); + } + + public Task> GetAllWithDate(DateTime date) + { + throw new NotImplementedException(); + } + + public Task GetDataWithName(string nom) + { + // return await _context.Parties.FirstOrDefaultAsync(n => n == nom); + throw new NotImplementedException(); + } + + public async Task Update(PartieEntity _partie) + { + return await _context.SaveChangesAsync() > 0; + } + } +} + diff --git a/Sources/BowlingService/Interfaces/IPartieService.cs b/Sources/BowlingService/Interfaces/IPartieService.cs new file mode 100644 index 0000000..4ce4816 --- /dev/null +++ b/Sources/BowlingService/Interfaces/IPartieService.cs @@ -0,0 +1,16 @@ +using System; +using BowlingEF.Entities; + +namespace BowlingService.Interfaces +{ + public interface IpartieService + { + public Task Add(PartieEntity _partie); + public Task Delete(PartieEntity _partie); + public Task Update(PartieEntity _partie); + public Task> GetAll(); + public Task> GetAllWithDate(DateTime date); + public Task GetDataWithName(string nom); + } +} + diff --git a/Sources/BowlingService/Interfaces/PartieService.cs b/Sources/BowlingService/Interfaces/PartieService.cs new file mode 100644 index 0000000..32ab1bb --- /dev/null +++ b/Sources/BowlingService/Interfaces/PartieService.cs @@ -0,0 +1,98 @@ +using System; +using AutoMapper; +using BowlingEF.Context; +using BowlingEF.Entities; +using BowlingLib.Model; +using BowlingRepository; +using BowlingRepository.Interface; +using Microsoft.EntityFrameworkCore; + +namespace BowlingService.Interfaces +{ + public class PartieService:IpartieService + { + private readonly IpartieRepository _IpartieRepository; + + public PartieService(IpartieRepository ipartieRepository, IMapper mapper) + { + _IpartieRepository = ipartieRepository; + _mapper = mapper; + } + + public PartieService() + { + + } + private readonly IMapper _mapper; + + public async Task Add(PartieDTO _partie) + { + bool result = false; + using (var context = new BowlingContext()) + { + PartieEntity entity = _mapper.Map(_partie); + context.Parties.Add(entity); + try + { + var data = await context.SaveChangesAsync(); + result = data == 1; + } + catch (Exception ex) + { + Console.WriteLine(ex); + throw; + } + } + + return result; + } + + + public async Task Delete(PartieEntity _partie) + { + return await _IpartieRepository.Delete(_partie); + } + + public async Task> GetAll() + { + List result = new List(); + using (var context = new BowlingContext()) + { + foreach (PartieEntity entity in await _IpartieRepository.GetAll()) + { + JoueurDTO joueur = _mapper.Map(entity.Joueur); + List frames = new List(); + foreach (FrameEntity frameEntity in entity.Frames) + { + FrameDTO frame = _mapper.Map(frameEntity); + frames.Add(frame); + } + result.Add(_mapper.Map(entity)); + } + } + return result.OrderBy(item => item.Date).ToList(); + + } + + public Task> GetAllWithDate(DateTime date) + { + throw new NotImplementedException(); + } + + public Task GetDataWithName(string nom) + { + throw new NotImplementedException(); + } + + public Task Update(PartieEntity _partie) + { + throw new NotImplementedException(); + } + + public Task Add(PartieEntity _partie) + { + throw new NotImplementedException(); + } + } +} + diff --git a/Sources/BowlingService/JoueurService.cs b/Sources/BowlingService/JoueurService.cs index 20b57d6..72f4b1b 100644 --- a/Sources/BowlingService/JoueurService.cs +++ b/Sources/BowlingService/JoueurService.cs @@ -43,7 +43,7 @@ namespace BowlingService Pseudo = _joueur.Pseudo, }; - //Parcourt de la liste des parties d'un joueur + //Parcourt de la liste des parties d'un joueur DTA for (int i = 0; i < _joueur.PartieDTO.Count; i++) { //Mapping entre les parties d'un joueur et les partieEntity d'une partieEntity diff --git a/Sources/DTOs/EquipeDTO.cs b/Sources/DTOs/EquipeDTO.cs index 18d129e..55d8567 100644 --- a/Sources/DTOs/EquipeDTO.cs +++ b/Sources/DTOs/EquipeDTO.cs @@ -16,7 +16,6 @@ namespace BowlingEF.Entities public string Nom { get; set; } public ICollection Joueurs { get; set; } #endregion - #region Constructeurs public EquipeDTO() { diff --git a/Sources/DTOs/FrameDTO.cs b/Sources/DTOs/FrameDTO.cs index 377953a..c0ec75c 100644 --- a/Sources/DTOs/FrameDTO.cs +++ b/Sources/DTOs/FrameDTO.cs @@ -9,17 +9,12 @@ namespace BowlingEF.Entities public class FrameDTO { #region Properties - [Key] - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public long Id { get; set; } - [Required] public int Numero { get; set; } - [Required] public int Lancer1 { get; set; } - [Required] public int Lancer2 { get; set; } public int Lancer3 { get; set; } - public PartieDTO Partie { get; set; } #endregion } diff --git a/Sources/DTOs/JoueurDTO.cs b/Sources/DTOs/JoueurDTO.cs index 8cf54ff..3df2f98 100644 --- a/Sources/DTOs/JoueurDTO.cs +++ b/Sources/DTOs/JoueurDTO.cs @@ -12,8 +12,6 @@ namespace BowlingEF.Entities [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public long Id { get; set; } - - [Required] public string Pseudo { get; set; } public ICollection PartieDTO { get; set; } = new List(); #endregion diff --git a/Sources/DTOs/PartieDTO.cs b/Sources/DTOs/PartieDTO.cs index 0386481..ba8b942 100644 --- a/Sources/DTOs/PartieDTO.cs +++ b/Sources/DTOs/PartieDTO.cs @@ -14,16 +14,14 @@ namespace BowlingEF.Entities public class PartieDTO { #region Properties - [Key] - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public long Id { get; set; } - [ForeignKey("JoueurForeignKey")] public JoueurDTO Joueur { get; set; } - [Required] + public DateTime Date { get; set; } public ICollection FramesDTO { get; set; } - [Required] + public int? Score { get; set; } #endregion diff --git a/Sources/Mapper/PartieProfile.cs b/Sources/Mapper/PartieProfile.cs index 8b4ffab..ab78a99 100644 --- a/Sources/Mapper/PartieProfile.cs +++ b/Sources/Mapper/PartieProfile.cs @@ -7,6 +7,6 @@ public class PartieProfile:Profile { public PartieProfile() { - CreateMap(); + CreateMap().ReverseMap(); } } \ No newline at end of file diff --git a/Sources/Tests/BowlingAppUnitTest/BowlingAppUnitTest.sln b/Sources/Tests/BowlingAppUnitTest/BowlingAppUnitTest.sln new file mode 100644 index 0000000..48ab595 --- /dev/null +++ b/Sources/Tests/BowlingAppUnitTest/BowlingAppUnitTest.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 25.0.1704.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BowlingAppUnitTest", "BowlingAppUnitTest.csproj", "{6CE80C57-58B9-4481-B4EE-1DD615117D93}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6CE80C57-58B9-4481-B4EE-1DD615117D93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6CE80C57-58B9-4481-B4EE-1DD615117D93}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6CE80C57-58B9-4481-B4EE-1DD615117D93}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6CE80C57-58B9-4481-B4EE-1DD615117D93}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {977E7E9D-643B-4F31-B0F3-229032EB3B68} + EndGlobalSection +EndGlobal