Skip to content

Commit

Permalink
Add delete score function
Browse files Browse the repository at this point in the history
  • Loading branch information
hueckidom committed Aug 28, 2024
1 parent f45d3aa commit a8e8899
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/src/views/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions service/src/PingPong/Controllers/ScoreController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <IActionResult> GetScores()
Expand Down
13 changes: 13 additions & 0 deletions service/src/PingPong/Repositories/Score/ScoreSQLiteRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
}
}
5 changes: 5 additions & 0 deletions service/src/PingPong/Services/ScoreService/ScoreService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ public void AddScores(PlayerDTO newScore)
{
_pingPongRepository.AddScores(newScore);
}

public void DeleteScores()
{
_pingPongRepository.DeleteScores();
}
}
}

0 comments on commit a8e8899

Please sign in to comment.