Player_Game REST API Overview This is a Spring Boot REST API project for managing Players and their associated Games. The API supports typical CRUD operations for Players and allows retrieving the games played by a specific player.
Features Get all players
Get player by ID
Get all games for a player
Create a new player
Update an existing player
Delete a player
Technologies Java 17+
Spring Boot (Web, Data JPA)
H2 in-memory database (or any configured DB)
JUnit 5 & Mockito for testing
Maven for build and dependency management
Jackson for JSON serialization/deserialization
Getting Started Prerequisites Java 17 or higher installed
Maven installed
Running the Application Clone the repository: git clone https://github.com/PeterImrich13/Player_Game.git cd Player_Game
Build and run the project using Maven: mvn spring-boot:run
The API will be available at http://localhost:8080/api/players
API Endpoints Method Endpoint Description GET /api/players Get all players GET /api/players/{id} Get player by ID GET /api/players/{id}/games Get all games by player ID POST /api/players Create a new player PUT /api/players/{id} Update a player by ID DELETE /api/players/{id} Delete a player by ID
Testing To run all unit and integration tests, use: mvn test Tests cover:
Controller layer (PlayerControllerTest) with mock MVC
Service layer (PlayerServiceTest) with mocked repository
Project Structure src/ └─ main/ ├─ java/com/example/Player_Game/ │ ├─ Controller/ # REST controllers (PlayerController, GameController) │ ├─ Service/ # Business logic services (PlayerService, GameService) │ ├─ model/ # Entity classes (Player, Game) │ ├─ repository/ # JPA repositories │ └─ Exception/ # Custom exceptions └─ test/ └─ java/com/example/Player_Game/ ├─ PlayerControllerTest.java ├─ PlayerServiceTest.java ├─ GameControllerTest.java └─ GameServiceTest.java
Notes The project uses Mockito to mock dependencies for unit testing.
PlayerNotFoundException is thrown when an operation targets a non-existent player.
Validation and error handling can be extended as needed.