Feature implement update result endpoint #133 #169
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes-#133
Pull Request Description
Overview
This PR introduces enhancements to the game results tracking functionality by implementing an update endpoint to manage user performance metrics and a delete endpoint for removing game results. The changes ensure that metrics like times played, current streak, maximum streak, wins, and win percentage are accurately tracked and updated after each game play. Additionally, dependency injection issues in the Result module have been resolved.
Key Changes
1. Update Result Endpoint
New DTO:
A dedicated
UpdateResultDto
has been created to accept only the necessary fields:userId
(UUID): Ensures the result update targets the correct user.won
(boolean): Indicates whether the game was won.Controller Update:
The PATCH endpoint now uses the route
PATCH /results/:userId
and leverages the new DTO for validating incoming data.Service Logic:
The
updateResult
method inResultService
now:timesPlayed
for every game played.currentStreak
(increments if won, resets if lost).maxStreak
when the current streak exceeds the previous maximum.winPercentage
using(wins / timesPlayed) * 100
.2. Entity Enhancements
New Metrics Fields:
The
Result
entity has been updated with the following new columns:timesPlayed
(integer, default: 0)currentStreak
(integer, default: 0)maxStreak
(integer, default: 0)wins
(integer, default: 0)winPercentage
(float, default: 0)Feedback Field Update:
The
feedback
column now uses asimple-array
type to clearly store an array of strings.3. Delete Endpoint Implementation
Updated the delete endpoint in the
ResultController
to useParseIntPipe
for type conversion