AmmunitionController - xEdziu/RPG-Handy-Helper GitHub Wiki

CpRedAmmunitionController

This page contains documentation for the CpRedAmmunitionController class, which handles ammunition management for Cyberpunk Red.

Basic Information

Base Path: /api/v1/authorized
Package: dev.goral.rpghandyhelper.rpgSystems.cpRed.manual.ammunition

Authentication

All requests to this controller require an XSRF token to be included in the headers.
Example:

headers: {
  "X-XSRF-TOKEN": "<csrfToken>"
}

Endpoint Summary

HTTP Method Path Description
GET /rpgSystems/cpRed/ammunition/all Returns basic info about all available ammunition
GET /rpgSystems/cpRed/ammunition/{ammunitionId} Returns detailed information about a specific ammunition by ID
GET /admin/rpgSystems/cpRed/ammunition/all Returns a full list of all ammunition types with administrative data
POST /admin/rpgSystems/cpRed/ammunition/add Adds a new ammunition type to the system
PUT /admin/rpgSystems/cpRed/ammunition/update/{ammunitionId} Update ammunition data

Field Descriptions

Request Body Fields (AmmunitionDto)

  • name (String): Name of the ammunition. Required.
  • description (String): Description of the ammunition. Required.
  • pricePerBullet (Integer): Price per bullet. Required.
  • availability (String): Availability status. Required. Possible values: CHEAP, EVERYDAY, COSTLY, PREMIUM, EXPENSIVE, VERY_EXPENSIVE, LUXURY, SUPER_LUXURY.

Response Fields

  • message (String): Describes the result of the operation.
  • error (Integer): HTTP status code.
  • timestamp (String): Time the response was generated.
  • ammunition (Object): A single ammunition object (if applicable).
  • ammunitionList (Array): List of ammunition (if applicable).

Endpoint Details

Get All Ammunition

Method: GET
Path: /rpgSystems/cpRed/ammunition/all

Response

{
  "ammunition": [
    {
      "name": "Explosive Ammo",
      "description": "For heavy weapons",
      "pricePerBullet": 50,
      "availability": "PREMIUM"
    }
  ],
  "message": "Amunicja została pobrana.",
  "error": 200,
  "timestamp": "..."
}

Possible Errors

  • 401 Unauthorized: User is not logged in.

Get Ammunition by ID

Method: GET
Path: /rpgSystems/cpRed/ammunition/{ammunitionId}

Response

{
  "ammunition": {
    "name": "Explosive Ammo",
    "description": "For heavy weapons",
    "pricePerBullet": 50,
    "availability": "PREMIUM"
  },
  "message": "Amunicja została pobrana.",
  "error": 200,
  "timestamp": "..."
}

Possible Errors

  • 400 Bad Request: Invalid ammunition ID.
  • 401 Unauthorized: User is not logged in.
  • 404 Not Found: Ammunition with the specified ID does not exist.

Get All Ammunition with Admin Data

Method: GET
Path: admin/rpgSystems/cpRed/ammunition/all

Response

{
  "ammunition": [
    {
      "id": 1,
      "name": "Explosive Ammo",
      "description": "For heavy weapons",
      "pricePerBullet": 50,
      "availability": "PREMIUM"
    }
  ],
  "message": "Amunicja została pobrana dla administratora.",
  "error": 200,
  "timestamp": "..."
}

Possible Errors

  • 401 Unauthorized: User is not logged in.
  • 403 Forbidden: User is not an admin.

Add New Ammunition

Method: POST
Path: /admin/rpgSystems/cpRed/ammunition/add

Request

{
  "name": "Incendiary Ammo",
  "description": "12 gauge shotgun, 20mm penetration",
  "pricePerBullet": 10,
  "availability": "PREMIUM"
}

Response

{
  "message": "Amunicja została dodana.",
  "error": 200,
  "timestamp": "..."
}

Possible Errors

  • 400 Bad Request: User not authenticated.
  • 401 Unauthorized: User not logged in.
  • 403 Forbidden: User is not an admin.
  • 404 Not Found: Invalid ammunition data.

Update Ammunition

Method: PUT
Path: /admin/rpgSystems/cpRed/ammunition/update/{ammunitionId}

Request

{
  "name": "Explosive Ammo 2.0",
  "description": "Updated description",
  "pricePerBullet": 60,
  "availability": "LUXURY"
}

Response

{
  "message": "Amunicja została zmodyfikowana.",
  "error": 200,
  "timestamp": "..."
}

Possible Errors

  • 400 Bad Request: Invalid ammunition ID or data.
  • 401 Unauthorized: User not logged in.
  • 403 Forbidden: User is not an admin.
  • 404 Not Found: Ammunition with the specified ID does not exist.

Common Troubleshooting Tips

  • Missing XSRF Token: Ensure the X-XSRF-TOKEN header is included in every request.
  • Invalid Fields: Double-check the request body for missing or invalid fields.
  • Permission Issues: Verify that the user has the necessary permissions for the requested operation.
⚠️ **GitHub.com Fallback** ⚠️