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

@ -1,7 +1,10 @@
using System;
using DTOs;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BowlingEF.Entities;
using BowlingLib.Model;
using BowlingService;
using BowlingService.Interfaces;
using Microsoft.AspNetCore.Http;
@ -29,35 +32,103 @@ namespace BowlingApi.Controllers
// GET: api/Partie
[HttpGet]
public IActionResult Get()
public async Task<IActionResult> Get()
{
var result = _partieService.GetAll().Result;
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));
// GET: api/Partie/5
[HttpGet("{name}")]
public IActionResult Get(string name)
try
{
return Ok(_partieService.GetDataWithName(name));
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 void Post([FromBody] string value)
public async Task<ActionResult<PartieDTO>> Post([FromBody] PartieDTO parti)
{
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;
}
}
// PUT: api/Partie/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
public async Task<ActionResult<PartieDTO>> Put(string name, [FromBody] PartieDTO partie)
{
try
{
if (partie == null)
return BadRequest("La partie est obligatoire");
var updatepartie = _partieService.Update(partie);
if (updatepartie.Result == null)
{
return NotFound();
}
// DELETE: api/Partie/5
[HttpDelete("{id}")]
public void Delete(int id)
return Ok(updatepartie);
}
catch (Exception e)
{
StatusCode(StatusCodes.Status500InternalServerError, e.Message);
throw;
}
}
}
}

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

Binary file not shown.

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

@ -6,12 +6,12 @@ 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<PartieDTO> Add(PartieDTO _partie);
public Task<bool> Delete(PartieDTO _partie);
public Task<bool> Update(PartieDTO _partie);
public Task<IEnumerable<PartieDTO>> GetAll();
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.Xml.Linq;
using AutoMapper;
using BowlingEF.Context;
using BowlingEF.Entities;
@ -7,51 +8,74 @@ using BowlingRepository;
using BowlingRepository.Interface;
using DTOs;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace BowlingService.Interfaces
{
public class PartieService:IpartieService
public class PartieService : IpartieService
{
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;
_mapper = mapper;
_logger = logger;
}
public PartieService()
{
}
private readonly IMapper _mapper;
public async Task<bool> Add(PartieDTO _partie)
//Add
public async Task<PartieDTO> Add(PartieDTO _partie)
{
bool result = false;
PartieDTO result = null;
using (var context = new BowlingContext())
{
PartieEntity entity = _mapper.Map<PartieEntity>(_partie);
context.Parties.Add(entity);
//context.Parties.Add(entity);
try
{
var data = await context.SaveChangesAsync();
result = data == 1;
//var data = await context.SaveChangesAsync();
result =_mapper.Map<PartieDTO>(await _IpartieRepository.Add(entity));
_logger.LogInformation("A new player was added : {player}", _partie.Id);
}
catch (Exception ex)
{
Console.WriteLine(ex);
_logger.LogError(ex, "Error while adding new player : {player}", _partie.Id);
throw;
}
}
return result;
}
//Delete
public async Task<bool> Delete(PartieDTO _partie)
{
// return await _IpartieRepository.Delete(_partie.Id);
public async Task<bool> Delete(PartieEntity _partie)
var result = false;
try
{
result = await _IpartieRepository.Delete(_partie.Id);
_logger.LogInformation("la partie est supprimer", _partie.Id);
}
catch (Exception ex)
{
return await _IpartieRepository.Delete(_partie);
_logger.LogError(ex, "Error while deleting player : {player}", _partie.Id);
throw;
}
return result;
}
public async Task<IEnumerable<PartieDTO>> GetAll()
@ -80,20 +104,45 @@ namespace BowlingService.Interfaces
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