From 7cc581fa73938ea9b75aa8f68c9aa7ba3436a5a5 Mon Sep 17 00:00:00 2001 From: Abbas Toof Date: Mon, 8 Jul 2024 20:20:34 +0300 Subject: [PATCH] Update Game History microservice README and integrate GameStat model and endpoints --- Backend/game_history/README.md | 82 ++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 23 deletions(-) diff --git a/Backend/game_history/README.md b/Backend/game_history/README.md index b4f2799..7402e06 100644 --- a/Backend/game_history/README.md +++ b/Backend/game_history/README.md @@ -2,7 +2,7 @@ ### Overview -The Game History microservice is a key component of the Transcendence project at 42 School. This service is responsible for recording and managing the history of ping pong games played by users. It supports creating, retrieving, updating, and deleting game history records. +The Game History microservice is a key component of the Transcendence project at 42 School. This service is responsible for recording and managing the history of ping pong games played by users. It supports creating, retrieving, updating, and deleting game history and game statistics records. ### Directory Structure @@ -57,37 +57,61 @@ The `GameHistory` model represents a record of a game played between two users. - `player2_id`: Integer, ID of the second player. - `winner_id`: Integer, ID of the winning player. - `start_time`: DateTime, the start time of the game. -- `end_time`: DateTime, the end time of the game (auto-populated). +- `end_time`: DateTime, the end time of the game (optional). + +The `GameStat` model represents the statistics of a game, linked to a `GameHistory` record. It includes the following fields: + +- `game_id`: OneToOneField, primary key linked to `GameHistory`. +- `player1_score`: Integer, score of the first player. +- `player2_score`: Integer, score of the second player. +- `total_hits`: Integer, total number of hits in the game. +- `longest_rally`: Integer, the longest rally in the game. ### Serializers -The `GameHistorySerializer` converts model instances to JSON format and validates incoming data. +- The `GameHistorySerializer` converts `GameHistory` model instances to JSON format and validates incoming data. +- The `GameStatSerializer` converts `GameStat` model instances to JSON format and validates incoming data. ### Views -The `GameHistoryViewSet` handles the CRUD operations for game history records. +- The `GameHistoryViewSet` handles the CRUD operations for game history records. +- The `GameStatViewSet` handles the CRUD operations for game statistics records. ### URLs -The microservice defines several endpoints to interact with the game history data. These endpoints are defined in the `game_data/urls.py` file. Here is an overview of how to access them: - -- **List and Create Game History Records:** - ``` - GET /game-history/ - POST /game-history/ - ``` -- **Retrieve, Update, and Delete a Specific Game History Record:** - ``` - GET /game-history// - PUT /game-history// - DELETE /game-history// - ``` +The microservice defines several endpoints to interact with the game history and game statistics data. These endpoints are defined in the `game_data/urls.py` file. Here is an overview of how to access them: + +- **Game History Endpoints:** + - **List and Create Game History Records:** + ``` + GET /game-history/ + POST /game-history/ + ``` + - **Retrieve, Update, and Delete a Specific Game History Record:** + ``` + GET /game-history// + PUT /game-history// + DELETE /game-history// + ``` + +- **Game Stat Endpoints:** + - **List and Create Game Stat Records:** + ``` + GET /game-stat/ + POST /game-stat/ + ``` + - **Retrieve, Update, and Delete a Specific Game Stat Record:** + ``` + GET /game-stat// + PUT /game-stat// + DELETE /game-stat// + ``` ### Tests #### Directory Structure -The tests for the Game History microservice are located in the `game_history/game_history/tests/` directory. The tests ensure that the CRUD operations for game history records are working correctly. +The tests for the Game History microservice are located in the `game_history/game_history/tests/` directory. The tests ensure that the CRUD operations for game history and game statistics records are working correctly. #### Test Cases @@ -103,12 +127,24 @@ The tests for the Game History microservice are located in the `game_history/gam 4. **Test Update Game History** - Verifies that a specific game history record can be updated successfully. -5. **Test Partial Update Game History** - - Verifies that a specific game history record can be partially updated successfully. - -6. **Test Delete Game History** +5. **Test Delete Game History** - Verifies that a specific game history record can be deleted successfully. +6. **Test Create Game Stat** + - Verifies that a game statistics record can be created successfully. + +7. **Test List Game Stats** + - Verifies that a list of game statistics records can be retrieved successfully. + +8. **Test Retrieve Game Stat** + - Verifies that a specific game statistics record can be retrieved successfully. + +9. **Test Update Game Stat** + - Verifies that a specific game statistics record can be updated successfully. + +10. **Test Delete Game Stat** + - Verifies that a specific game statistics record can be deleted successfully. + ### Running Tests To run the tests, use the following commands: @@ -127,4 +163,4 @@ To run the tests, use the following commands: ### Conclusion -The Game History microservice is an essential part of the Transcendence project, providing a robust solution for managing game history records. This documentation provides an overview of the setup, implementation, and testing of the service. For further details, refer to the respective source code files in the project directory. +The Game History microservice is an essential part of the Transcendence project, providing a robust solution for managing game history and game statistics records. This documentation provides an overview of the setup, implementation, and testing of the service. For further details, refer to the respective source code files in the project directory.