Skip to content

Commit

Permalink
Update Game History microservice README and integrate GameStat model …
Browse files Browse the repository at this point in the history
…and endpoints
  • Loading branch information
abbastoof committed Jul 8, 2024
1 parent 910b84d commit 7cc581f
Showing 1 changed file with 59 additions and 23 deletions.
82 changes: 59 additions & 23 deletions Backend/game_history/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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/<int:pk>/
PUT /game-history/<int:pk>/
DELETE /game-history/<int:pk>/
```
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/<int:pk>/
PUT /game-history/<int:pk>/
DELETE /game-history/<int:pk>/
```
- **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/<int:pk>/
PUT /game-stat/<int:pk>/
DELETE /game-stat/<int:pk>/
```
### 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
Expand All @@ -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:
Expand All @@ -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.

0 comments on commit 7cc581f

Please sign in to comment.