Given four files PlayerController.java
, PlayerRepository.java
, PlayerService.java
and Player.java
.
The PlayerService
class has a variable named team
, which is a HashMap that holds Integer
s as keys and Player
objects as values. Initially, it contains data of 11 players.
-
Player.java
:Player
class should contain the following attributes.Attribute Type playerId int playerName String jerseyNumber int role String -
PlayerRepository.java
: Create aninterface
containing required methods. -
PlayerService.java
: Update the service class with logic for managing player data. -
PlayerController.java
: Create the controller class to handle HTTP requests.
Implement the following APIs.
Returns a list of all players in the team.
[
{
"playerId": 1,
"playerName": "Alexander",
"jerseyNumber": 5,
"role": "All-rounder"
},
...
]
Creates a new player in the team
. The playerId
is auto-incremented.
{
"playerName": "Prince",
"jerseyNumber": 24,
"role": "Bowler"
}
{
"playerId": 12,
"playerName": "Prince",
"jerseyNumber": 24,
"role": "Bowler"
}
Returns a player based on the playerId
. If the given playerId
is not found in the team
, raise ResponseStatusException
with HttpStatus.NOT_FOUND
.
{
"playerId": 1,
"playerName": "Alexander",
"jerseyNumber": 5,
"role": "All-rounder"
}
Updates the details of a player in the team based on the playerId
. If the given playerId
is not found in the team
, raise ResponseStatusException
with HttpStatus.NOT_FOUND
.
{
"playerName": "Yuvi"
"jerseyNumber": 12,
"role": "All-rounder"
}
{
"playerId": 3,
"playerName": "Yuvi",
"jerseyNumber": 12,
"role": "All-rounder"
}
Deletes a player from the team based on the playerId
. If the given playerId
is not found in the team
, raise ResponseStatusException
with HttpStatus.NOT_FOUND
.
Do not modify the code in PlayerApplication.java