Merge remote-tracking branch 'origin/Branche1'
continuous-integration/drone/push Build is failing Details

pull/11/head
Victor Perez NGOUNOU 2 years ago
commit 0fa297f75f

@ -9,8 +9,9 @@
<PropertyGroup Condition=" '$(RunConfiguration)' == 'https' " /> <PropertyGroup Condition=" '$(RunConfiguration)' == 'https' " />
<PropertyGroup Condition=" '$(RunConfiguration)' == 'http' " /> <PropertyGroup Condition=" '$(RunConfiguration)' == 'http' " />
<PropertyGroup Condition=" '$(RunConfiguration)' == 'RestFull' " />
<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="6.0.11" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.13" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.13" />
@ -25,6 +26,9 @@
<ProjectReference Include="..\BowlingService\BowlingService.csproj" /> <ProjectReference Include="..\BowlingService\BowlingService.csproj" />
<ProjectReference Include="..\Mapper\Mapper.csproj" /> <ProjectReference Include="..\Mapper\Mapper.csproj" />
<ProjectReference Include="..\DTOs\DTOs.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
</ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -33,5 +37,4 @@
<None Remove="Microsoft.EntityFrameworkCore.Tools" /> <None Remove="Microsoft.EntityFrameworkCore.Tools" />
<None Remove="Microsoft.EntityFrameworkCore.Sqlite" /> <None Remove="Microsoft.EntityFrameworkCore.Sqlite" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -1,19 +1,22 @@
using System; using System;
using System.Collections.Generic; using DTOs;
using System.Linq; using System.Collections.Generic;
using System.Threading.Tasks; using System.Linq;
using System.Threading.Tasks;
using BowlingEF.Entities;
using BowlingLib.Model;
using BowlingService; using BowlingService;
using BowlingService.Interfaces; using BowlingService.Interfaces;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace BowlingApi.Controllers namespace BowlingApi.Controllers
{ {
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
public class PartieController : ControllerBase public class PartieController : ControllerBase
{ {
@ -29,35 +32,103 @@ namespace BowlingApi.Controllers
// GET: api/Partie // GET: api/Partie
[HttpGet] [HttpGet]
public IActionResult Get() public async Task<IActionResult> Get()
{
try
{
var result = await _partieService.GetAll();
if (result == null)
{
return NotFound();
}
return Ok(result);
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
throw;
}
//var result = _partieService.GetAll().Result;
//return Ok(result);
}
// GET: api/Partie/djon
[HttpGet("{id}")]
public async Task<IActionResult> Get(int id)
{
// return Ok(_partieService.GetDataWithName(name));
try
{
if (id == null)
return BadRequest("Le nom de la partie est obligatoire");
var result = _partieService.GetDataWithId(id).Result;
if (result == null)
{
return NotFound();
}
return Ok(result);
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
throw;
}
}
// POST: api/Partie
[HttpPost]
public async Task<ActionResult<PartieDTO>> Post([FromBody] PartieDTO parti)
{ {
var result = _partieService.GetAll().Result;
return Ok(result);
try
{
if (parti == null)
{
return BadRequest("partie est obligatoire");
}
var createdpartie = _partieService.Add(parti).Result;
return CreatedAtAction(nameof(Get), new { id = parti.Id }, createdpartie);
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
throw;
}
} }
// GET: api/Partie/5 // PUT: api/Partie/5
[HttpGet("{name}")] [HttpPut("{id}")]
public IActionResult Get(string name) public async Task<ActionResult<PartieDTO>> Put(string name, [FromBody] PartieDTO partie)
{ {
return Ok(_partieService.GetDataWithName(name)); try
} {
if (partie == null)
// POST: api/Partie return BadRequest("La partie est obligatoire");
[HttpPost]
public void Post([FromBody] string value) var updatepartie = _partieService.Update(partie);
{ if (updatepartie.Result == null)
} {
return NotFound();
// PUT: api/Partie/5 }
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value) return Ok(updatepartie);
{ }
} catch (Exception e)
{
// DELETE: api/Partie/5 StatusCode(StatusCodes.Status500InternalServerError, e.Message);
[HttpDelete("{id}")] throw;
public void Delete(int id) }
{
} }
}
}
}
}

@ -29,8 +29,6 @@
}, },
"RestFull": { "RestFull": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:5001", "applicationUrl": "https://localhost:5001",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"

Binary file not shown.

@ -5,12 +5,12 @@ namespace BowlingRepository.Interface
{ {
public interface IpartieRepository public interface IpartieRepository
{ {
public Task<bool> Add(PartieEntity _partie); public Task<PartieEntity> Add(PartieEntity _partie);
public Task<bool> Delete(PartieEntity _partie); public Task<bool> Delete(long id);
public Task<bool> Update(PartieEntity _partie); public Task<bool> Update(PartieEntity _partie);
public Task<List<PartieEntity>> GetAll(); public Task<List<PartieEntity>> GetAll();
public Task<IEnumerable<PartieEntity>> GetAllWithDate(DateTime date); public Task<IEnumerable<PartieEntity>> GetAllWithDate(DateTime date);
public Task<PartieEntity> GetDataWithName(string nom); public Task<PartieEntity> GetDataWithId(int id);
} }
} }

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
namespace BowlingRepository.Interface namespace BowlingRepository.Interface
{ {
public class PartieRepository:IpartieRepository public class PartieRepository : IpartieRepository
{ {
private readonly BowlingContext _context; private readonly BowlingContext _context;
public PartieRepository() public PartieRepository()
@ -13,25 +13,30 @@ namespace BowlingRepository.Interface
_context = new BowlingContext(); _context = new BowlingContext();
} }
public async Task<bool> Add(PartieEntity partie) public async Task<PartieEntity> Add(PartieEntity partie)
{ {
_context.Parties.Add( partie);
return await _context.SaveChangesAsync() > 0; var result = await _context.Parties.AddAsync(partie);
await _context.SaveChangesAsync();
return result.Entity;
//_context.Parties.Add( partie);
//return await _context.SaveChangesAsync() > 0;
} }
public async Task<bool> Delete(PartieEntity _partie) public async Task<bool> Delete(long id)
{ {
using (var context = new BowlingContext()) using (var context = new BowlingContext())
{ {
PartieEntity entity = context.Parties.Find(_partie.Id); PartieEntity entity = context.Parties.Find(id);
context.Parties.Remove(entity); context.Parties.Remove(entity);
return await context.SaveChangesAsync() > 0; return await context.SaveChangesAsync() > 0;
} }
} }
public async Task<List<PartieEntity>> GetAll() public async Task<List<PartieEntity>> GetAll()
{ {
@ -43,12 +48,13 @@ namespace BowlingRepository.Interface
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<PartieEntity> GetDataWithName(string nom) public async Task<PartieEntity> GetDataWithId(int id)
{ {
// return await _context.Parties.FirstOrDefaultAsync(n => n == nom); var data = await _context.Parties.FirstOrDefaultAsync(n => n.Id == id);
throw new NotImplementedException(); return data;
} }
public async Task<bool> Update(PartieEntity _partie) public async Task<bool> Update(PartieEntity _partie)
{ {
return await _context.SaveChangesAsync() > 0; return await _context.SaveChangesAsync() > 0;
@ -56,3 +62,4 @@ namespace BowlingRepository.Interface
} }
} }

@ -30,7 +30,7 @@ public class JoueurRepository:IJoueurRepository
public async Task<bool> Update(JoueurEntity joueur) public async Task<bool> Update(JoueurEntity joueur)
{ {
return await _context.SaveChangesAsync() > 0; return await _context.SaveChangesAsync() > 0;
} }
public async Task<JoueurEntity> GetJoueur(long id) public async Task<JoueurEntity> GetJoueur(long id)

@ -4,14 +4,14 @@ using DTOs;
namespace BowlingService.Interfaces namespace BowlingService.Interfaces
{ {
public interface IpartieService public interface IpartieService
{ {
public Task<bool> Add(PartieEntity _partie); public Task<PartieDTO> Add(PartieDTO _partie);
public Task<bool> Delete(PartieEntity _partie); public Task<bool> Delete(PartieDTO _partie);
public Task<bool> Update(PartieEntity _partie); public Task<bool> Update(PartieDTO _partie);
public Task<IEnumerable<PartieDTO>> GetAll(); public Task<IEnumerable<PartieDTO>> GetAll();
public Task<IEnumerable<PartieEntity>> GetAllWithDate(DateTime date); public Task<IEnumerable<PartieEntity>> GetAllWithDate(DateTime date);
public Task<PartieEntity> GetDataWithName(string nom); public Task<PartieDTO> GetDataWithId(int id);
} }
} }

@ -1,4 +1,5 @@
using System; using System;
using System.Xml.Linq;
using AutoMapper; using AutoMapper;
using BowlingEF.Context; using BowlingEF.Context;
using BowlingEF.Entities; using BowlingEF.Entities;
@ -7,51 +8,74 @@ using BowlingRepository;
using BowlingRepository.Interface; using BowlingRepository.Interface;
using DTOs; using DTOs;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace BowlingService.Interfaces namespace BowlingService.Interfaces
{ {
public class PartieService:IpartieService public class PartieService : IpartieService
{ {
private readonly IpartieRepository _IpartieRepository; private readonly IpartieRepository _IpartieRepository;
private readonly ILogger<JoueurService> _logger;
private readonly IMapper _mapper;
public PartieService(IpartieRepository ipartieRepository, IMapper mapper) public PartieService(IpartieRepository ipartieRepository, IMapper mapper, ILogger<JoueurService> logger)
{ {
_IpartieRepository = ipartieRepository; _IpartieRepository = ipartieRepository;
_mapper = mapper; _mapper = mapper;
_logger = logger;
} }
public PartieService() public PartieService()
{ {
} }
private readonly IMapper _mapper;
//Add
public async Task<bool> Add(PartieDTO _partie)
public async Task<PartieDTO> Add(PartieDTO _partie)
{ {
bool result = false;
PartieDTO result = null;
using (var context = new BowlingContext()) using (var context = new BowlingContext())
{ {
PartieEntity entity = _mapper.Map<PartieEntity>(_partie); PartieEntity entity = _mapper.Map<PartieEntity>(_partie);
context.Parties.Add(entity); //context.Parties.Add(entity);
try try
{ {
var data = await context.SaveChangesAsync(); //var data = await context.SaveChangesAsync();
result = data == 1; result =_mapper.Map<PartieDTO>(await _IpartieRepository.Add(entity));
_logger.LogInformation("A new player was added : {player}", _partie.Id);
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine(ex); _logger.LogError(ex, "Error while adding new player : {player}", _partie.Id);
throw; throw;
} }
} }
return result; return result;
} }
//Delete
public async Task<bool> Delete(PartieDTO _partie)
public async Task<bool> Delete(PartieEntity _partie)
{ {
return await _IpartieRepository.Delete(_partie); // return await _IpartieRepository.Delete(_partie.Id);
var result = false;
try
{
result = await _IpartieRepository.Delete(_partie.Id);
_logger.LogInformation("la partie est supprimer", _partie.Id);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error while deleting player : {player}", _partie.Id);
throw;
}
return result;
} }
public async Task<IEnumerable<PartieDTO>> GetAll() public async Task<IEnumerable<PartieDTO>> GetAll()
@ -80,20 +104,45 @@ namespace BowlingService.Interfaces
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<PartieEntity> GetDataWithName(string nom) public async Task<PartieDTO> GetDataWithId(int id)
{ {
throw new NotImplementedException(); PartieDTO _partie = null;
}
public Task<bool> Update(PartieEntity _partie) try
{ {
throw new NotImplementedException(); var partientity = await _IpartieRepository.GetDataWithId(id);
_partie = _mapper.Map<PartieDTO>(partientity);
_logger.LogInformation("partie was retrieved : {partie}", id);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error while retrieving partie : {partie}", id);
throw;
}
return _partie;
} }
public Task<bool> Add(PartieEntity _partie)
//Update
public async Task<bool> Update(PartieDTO _partie)
{ {
throw new NotImplementedException();
bool result = false;
using (var context = new BowlingContext())
{
PartieEntity entity = _mapper.Map<PartieEntity>(_partie);
entity.Date = _partie.Date;
entity.Score = _partie.Score;
result = _IpartieRepository.Update(entity).Result;
}
return result;
} }
} }
} }

Loading…
Cancel
Save