Skip to content

Cricket Team is build By Using RestController, GetMapping, PostMapping, PutMapping, DeleteMapping, Override, PathVariable and RequestBody

Notifications You must be signed in to change notification settings

ashokravina/Cricket-Team

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 Integers as keys and Player objects as values. Initially, it contains data of 11 players.

Completion Instructions

  • Player.java: Player class should contain the following attributes.

    Attribute Type
    playerId int
    playerName String
    jerseyNumber int
    role String
  • PlayerRepository.java: Create an interface 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.

API 1

Path: /players

Method: GET

Description:

Returns a list of all players in the team.

Response

[
    {
        "playerId": 1,
        "playerName": "Alexander",
        "jerseyNumber": 5,
        "role": "All-rounder"
    },
   ...
]

API 2

Path: /players

Method: POST

Description:

Creates a new player in the team. The playerId is auto-incremented.

Request

{
  "playerName": "Prince",
  "jerseyNumber": 24,
  "role": "Bowler"
}

Response

{
    "playerId": 12,
    "playerName": "Prince",
    "jerseyNumber": 24,
    "role": "Bowler"
}

API 3

Path: /players/{playerId}

Method: GET

Description:

Returns a player based on the playerId. If the given playerId is not found in the team, raise ResponseStatusException with HttpStatus.NOT_FOUND.

Success Response

{
    "playerId": 1,
    "playerName": "Alexander",
    "jerseyNumber": 5,
    "role": "All-rounder"
}

API 4

Path: /players/{playerId}

Method: PUT

Description:

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.

Request

{
    "playerName": "Yuvi"
    "jerseyNumber": 12,
    "role": "All-rounder"
}

Success Response

{
    "playerId": 3,
    "playerName": "Yuvi",
    "jerseyNumber": 12,
    "role": "All-rounder"
}

API 5

Path: /players/{playerId}

Method: DELETE

Description:

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

About

Cricket Team is build By Using RestController, GetMapping, PostMapping, PutMapping, DeleteMapping, Override, PathVariable and RequestBody

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages