diff --git a/Sources/BowlingApi/BowlingApi.csproj b/Sources/BowlingApi/BowlingApi.csproj index 2605b8f..ffe323b 100644 --- a/Sources/BowlingApi/BowlingApi.csproj +++ b/Sources/BowlingApi/BowlingApi.csproj @@ -11,7 +11,6 @@ - 4 bin\Debug\net6.0\BowlingApi.xml diff --git a/Sources/BowlingApi/Controllers/PartieController.cs b/Sources/BowlingApi/Controllers/PartieController.cs index d50407e..03f6d46 100644 --- a/Sources/BowlingApi/Controllers/PartieController.cs +++ b/Sources/BowlingApi/Controllers/PartieController.cs @@ -121,6 +121,67 @@ namespace BowlingApi.Controllers } + [HttpGet("{page}/{pageSize}")] + [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)] + [ProducesResponseType(typeof(string), StatusCodes.Status404NotFound)] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + public async Task Get(int page = 1, int pageSize = 10) + { + try + { + var result = await _partieService.GetAll(); + if (result == null) + { + return NotFound(); + } + var data = result.Skip((page - 1) * pageSize).Take(pageSize); + Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(new + { + totalCount = result.Count(), + pageSize = pageSize, + currentPage = page, + totalPages = (int)Math.Ceiling(result.Count() / (double)pageSize) + })); + return Ok(data); + } + catch (Exception e) + { + return StatusCode(StatusCodes.Status500InternalServerError, e.Message); + throw; + } + } + /// + /// Supprimer une partie par son id + /// DELETE: api/parti/5 + /// + /// + /// Retourne la partie supprimé + /// Si la partie n'existe pas + /// Si une erreur est survenue + [HttpDelete("{id}")] + [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)] + [ProducesResponseType(typeof(string), StatusCodes.Status404NotFound)] + [ProducesResponseType(typeof(bool), StatusCodes.Status200OK)] + [MapToApiVersion("2")] + public async Task> Delete(long id) + { + try + { + var parti = _partieService.Delete(id); + if (parti.Result == false) + { + return NotFound(); + } + return Ok(parti); + } + catch (Exception e) + { + StatusCode(StatusCodes.Status500InternalServerError, e.Message); + throw; + } + } + + /// /// Modification partie /// PUT: api/parti/5 diff --git a/Sources/BowlingApi/bowling.db-shm b/Sources/BowlingApi/bowling.db-shm new file mode 100644 index 0000000..fe9ac28 Binary files /dev/null and b/Sources/BowlingApi/bowling.db-shm differ diff --git a/Sources/BowlingApi/bowling.db-wal b/Sources/BowlingApi/bowling.db-wal new file mode 100644 index 0000000..e69de29 diff --git a/Sources/BowlingService/Interfaces/IPartieService.cs b/Sources/BowlingService/Interfaces/IPartieService.cs index e1a76eb..077d628 100644 --- a/Sources/BowlingService/Interfaces/IPartieService.cs +++ b/Sources/BowlingService/Interfaces/IPartieService.cs @@ -8,6 +8,7 @@ namespace BowlingService.Interfaces { public Task Add(PartieDTO _partie); public Task Delete(PartieDTO _partie); + public Task Delete(long id); public Task Update(PartieDTO _partie); public Task> GetAll(); public Task> GetAllWithDate(DateTime date); diff --git a/Sources/BowlingService/PartieService.cs b/Sources/BowlingService/PartieService.cs index b805d02..9e92659 100644 --- a/Sources/BowlingService/PartieService.cs +++ b/Sources/BowlingService/PartieService.cs @@ -152,6 +152,27 @@ public async Task Add(PartieDTO _partie) return result; } + + public async Task Delete(long _partiid) + { + var result = false; + try + { + result = await _IpartieRepository.Delete(_partiid); + + if (result) + _logger.LogInformation("A parti was deleted : {player}", _partiid); + else + _logger.LogWarning("A parti not found : {player}", _partiid); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while deleting player : {player}", _partiid); + throw; + } + return result; + } } }