Merge remote-tracking branch 'origine/Branche1'

# Conflicts:
#	Sources/BowlingApi/BowlingApi.csproj
#	Sources/BowlingService/JoueurService.cs
#	Sources/DTOs/FrameDTO.cs
#	Sources/GraphQL Project/bowling.db
#	Sources/GraphQL Project/bowling.db-shm
pull/7/head
Victor Perez NGOUNOU 2 years ago
commit ca2856fa2a

@ -12,6 +12,13 @@
<ItemGroup> <ItemGroup>
<!--<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" />--> <!--<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" />-->
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -20,4 +27,19 @@
</ItemGroup> </ItemGroup>
<<<<<<< HEAD
=======
<ItemGroup>
<None Remove="Microsoft.VisualStudio.Web.CodeGeneration.Design" />
<None Remove="Microsoft.EntityFrameworkCore.SqlServer" />
<None Remove="Microsoft.EntityFrameworkCore.Tools" />
<None Remove="Microsoft.EntityFrameworkCore.Sqlite" />
</ItemGroup>
<ItemGroup>
<None Update="bowling.db">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
>>>>>>> origine/Branche1
</Project> </Project>

@ -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)
{
}
}
}

@ -27,6 +27,8 @@ builder.Services.AddDbContext<BowlingContext>(options =>
}); });
builder.Services.AddScoped<IJoueurRepository, JoueurRepository>(); builder.Services.AddScoped<IJoueurRepository, JoueurRepository>();
builder.Services.AddScoped<IpartieRepository, PartieRepository>();
builder.Services.AddScoped<IpartieService, PartieService>();
//configure Logger //configure Logger
builder.Services.AddLogging(configure => builder.Services.AddLogging(configure =>

@ -1,4 +1,4 @@
using BowlingEF.Entities; using BowlingEF.Entities;
namespace BowlingRepository.Interface; namespace BowlingRepository.Interface;

@ -0,0 +1,17 @@
using System;
using BowlingEF.Entities;
namespace BowlingRepository.Interface
{
public interface IpartieRepository
{
public Task<bool> Add(PartieEntity _partie);
public Task<bool> Delete(PartieEntity _partie);
public Task<bool> Update(PartieEntity _partie);
public Task<List<PartieEntity>> GetAll();
public Task<IEnumerable<PartieEntity>> GetAllWithDate(DateTime date);
public Task<PartieEntity> GetDataWithName(string nom);
}
}

@ -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<bool> Add(PartieEntity partie)
{
_context.Parties.Add( partie);
return await _context.SaveChangesAsync() > 0;
}
public async Task<bool> 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<List<PartieEntity>> GetAll()
{
return await _context.Parties.ToListAsync();
}
public Task<IEnumerable<PartieEntity>> GetAllWithDate(DateTime date)
{
throw new NotImplementedException();
}
public Task<PartieEntity> GetDataWithName(string nom)
{
// return await _context.Parties.FirstOrDefaultAsync(n => n == nom);
throw new NotImplementedException();
}
public async Task<bool> Update(PartieEntity _partie)
{
return await _context.SaveChangesAsync() > 0;
}
}
}

@ -0,0 +1,16 @@
using System;
using BowlingEF.Entities;
namespace BowlingService.Interfaces
{
public interface IpartieService
{
public Task<bool> Add(PartieEntity _partie);
public Task<bool> Delete(PartieEntity _partie);
public Task<bool> Update(PartieEntity _partie);
public Task<IEnumerable<PartieDTO>> GetAll();
public Task<IEnumerable<PartieEntity>> GetAllWithDate(DateTime date);
public Task<PartieEntity> GetDataWithName(string nom);
}
}

@ -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<bool> Add(PartieDTO _partie)
{
bool result = false;
using (var context = new BowlingContext())
{
PartieEntity entity = _mapper.Map<PartieEntity>(_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<bool> Delete(PartieEntity _partie)
{
return await _IpartieRepository.Delete(_partie);
}
public async Task<IEnumerable<PartieDTO>> GetAll()
{
List<PartieDTO> result = new List<PartieDTO>();
using (var context = new BowlingContext())
{
foreach (PartieEntity entity in await _IpartieRepository.GetAll())
{
JoueurDTO joueur = _mapper.Map<JoueurDTO>(entity.Joueur);
List<FrameDTO> frames = new List<FrameDTO>();
foreach (FrameEntity frameEntity in entity.Frames)
{
FrameDTO frame = _mapper.Map<FrameDTO>(frameEntity);
frames.Add(frame);
}
result.Add(_mapper.Map<PartieDTO>(entity));
}
}
return result.OrderBy(item => item.Date).ToList<PartieDTO>();
}
public Task<IEnumerable<PartieEntity>> GetAllWithDate(DateTime date)
{
throw new NotImplementedException();
}
public Task<PartieEntity> GetDataWithName(string nom)
{
throw new NotImplementedException();
}
public Task<bool> Update(PartieEntity _partie)
{
throw new NotImplementedException();
}
public Task<bool> Add(PartieEntity _partie)
{
throw new NotImplementedException();
}
}
}

@ -16,7 +16,6 @@ namespace DTOs
public string Nom { get; set; } public string Nom { get; set; }
public ICollection<JoueurDTO> Joueurs { get; set; } public ICollection<JoueurDTO> Joueurs { get; set; }
#endregion #endregion
#region Constructeurs #region Constructeurs
public EquipeDTO() public EquipeDTO()
{ {

@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
namespace DTOs namespace BowlingEF.Entities
{ {
/// <summary> /// <summary>
/// Classe de gestion des frames /// Classe de gestion des frames
@ -9,9 +9,13 @@ namespace DTOs
public class FrameDTO public class FrameDTO
{ {
#region Properties #region Properties
public long Id { get; set; } public long Id { get; set; }
[Required]
public int Numero { get; set; } public int Numero { get; set; }
[Required]
public int Lancer1 { get; set; } public int Lancer1 { get; set; }
[Required]
public int Lancer2 { get; set; } public int Lancer2 { get; set; }
public int Lancer3 { get; set; } public int Lancer3 { get; set; }

@ -12,8 +12,6 @@ namespace DTOs
[Key] [Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; } public long Id { get; set; }
[Required]
public string Pseudo { get; set; } public string Pseudo { get; set; }
public ICollection<PartieDTO> PartieDTO { get; set; } = new List<PartieDTO>(); public ICollection<PartieDTO> PartieDTO { get; set; } = new List<PartieDTO>();
#endregion #endregion

@ -14,16 +14,14 @@ namespace DTOs
public class PartieDTO public class PartieDTO
{ {
#region Properties #region Properties
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; } public long Id { get; set; }
[ForeignKey("JoueurForeignKey")]
public JoueurDTO Joueur { get; set; } public JoueurDTO Joueur { get; set; }
[Required]
public DateTime Date { get; set; } public DateTime Date { get; set; }
public ICollection<FrameDTO> FramesDTO { get; set; } public ICollection<FrameDTO> FramesDTO { get; set; }
[Required]
public int? Score { get; set; } public int? Score { get; set; }
#endregion #endregion

@ -8,6 +8,6 @@ public class PartieProfile:Profile
{ {
public PartieProfile() public PartieProfile()
{ {
CreateMap<PartieDTO, PartieEntity>(); CreateMap<PartieDTO, PartieEntity>().ReverseMap();
} }
} }

@ -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
Loading…
Cancel
Save