From a8e88996a21bf3f110933a96d29d4fb87a935305 Mon Sep 17 00:00:00 2001 From: hueckidom Date: Wed, 28 Aug 2024 08:09:54 +0200 Subject: [PATCH] Add delete score function --- client/src/views/Game.tsx | 2 +- .../src/PingPong/Controllers/ScoreController.cs | 14 ++++++++++++++ .../Repositories/Score/ScoreSQLiteRepository.cs | 13 +++++++++++++ .../PingPong/Services/ScoreService/ScoreService.cs | 5 +++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/client/src/views/Game.tsx b/client/src/views/Game.tsx index b0a3be7..bbfcba9 100644 --- a/client/src/views/Game.tsx +++ b/client/src/views/Game.tsx @@ -39,7 +39,7 @@ const INITIAL_GAME_DEFAULTS: BaseSettings = { maxBoardWidth: 700, maxLife: 2, maxVelocityX: 5, - moveSpeed: 9, + moveSpeed: 10, playerHeight: 60, playerWidth: 10, player1KeyDown: "ArrowDown", diff --git a/service/src/PingPong/Controllers/ScoreController.cs b/service/src/PingPong/Controllers/ScoreController.cs index e903106..8ddc539 100644 --- a/service/src/PingPong/Controllers/ScoreController.cs +++ b/service/src/PingPong/Controllers/ScoreController.cs @@ -14,6 +14,20 @@ public ScoreController(ScoreService scoreService) { _scoreService = scoreService; } + + [HttpDelete(nameof(DeleteScores))] + public IActionResult DeleteScores([FromQuery] string password) + { + try + { + _scoreService.DeleteScores(); + return NoContent(); + } + catch (Exception ex) + { + return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); + } + } [HttpGet(nameof(GetScores))] public async Task GetScores() diff --git a/service/src/PingPong/Repositories/Score/ScoreSQLiteRepository.cs b/service/src/PingPong/Repositories/Score/ScoreSQLiteRepository.cs index 550a59f..0f63f1e 100644 --- a/service/src/PingPong/Repositories/Score/ScoreSQLiteRepository.cs +++ b/service/src/PingPong/Repositories/Score/ScoreSQLiteRepository.cs @@ -75,5 +75,18 @@ public void AddScores(PlayerDTO item) } } } + + public void DeleteScores() + { + using (SQLiteConnection connection = new SQLiteConnection(_sqlitePath)) + { + connection.Open(); + string deleteQuery = "DELETE FROM PlayerItems"; + using (SQLiteCommand command = new SQLiteCommand(deleteQuery, connection)) + { + command.ExecuteNonQuery(); + } + } + } } } \ No newline at end of file diff --git a/service/src/PingPong/Services/ScoreService/ScoreService.cs b/service/src/PingPong/Services/ScoreService/ScoreService.cs index c6246f5..e5ff845 100644 --- a/service/src/PingPong/Services/ScoreService/ScoreService.cs +++ b/service/src/PingPong/Services/ScoreService/ScoreService.cs @@ -21,5 +21,10 @@ public void AddScores(PlayerDTO newScore) { _pingPongRepository.AddScores(newScore); } + + public void DeleteScores() + { + _pingPongRepository.DeleteScores(); + } } } \ No newline at end of file