Skip to content

Add V2 player endpoint with clean JSON response structure#113

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/add-playerdata-handler
Draft

Add V2 player endpoint with clean JSON response structure#113
Copilot wants to merge 3 commits intomainfrom
copilot/add-playerdata-handler

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 10, 2025

This PR introduces a new V2 player data endpoint that provides a cleaner, more structured JSON response format compared to the existing Hypixel API-compatible endpoint.

New Endpoint

GET /v2/player/{uuid} - Retrieve player data with modern REST API design

The new endpoint uses path parameters instead of query parameters and returns a response structure that closely mirrors the internal domain models with proper JSON field naming.

Response Format

The V2 endpoint returns a consistent response structure with simplified stats focused on overall gameplay:

{
  "success": true,
  "player": {
    "queriedAt": "2024-01-01T12:00:00Z",
    "uuid": "01234567-89ab-cdef-0123-456789abcdef",
    "displayname": "PlayerName",
    "lastLogin": "2024-01-01T11:00:00Z",
    "lastLogout": "2024-01-01T11:30:00Z", 
    "missingBedwarsStats": false,
    "experience": 1000,
    "overall": {
      "winstreak": 10,
      "gamesPlayed": 100,
      "wins": 80,
      "losses": 20,
      "bedsBroken": 150,
      "bedsLost": 30,
      "finalKills": 200,
      "finalDeaths": 25,
      "kills": 500,
      "deaths": 100
    }
  }
}

Error responses follow the same pattern:

{
  "success": false,
  "player": null,
  "cause": "Invalid UUID"
}

Implementation Details

  • Consistent with existing patterns: Based on the structure of history and sessions handlers
  • Proper error handling: Handles invalid UUIDs, player not found, and service unavailable scenarios
  • Rate limiting: Same rate limits as the existing playerdata endpoint
  • CORS support: Includes OPTIONS endpoint for web client compatibility
  • Comprehensive testing: Full test coverage for both handler and converter functions
  • Uses existing app layer: Leverages the same GetAndPersistPlayerWithCache function as the V1 endpoint
  • Simplified response: Focuses on overall stats only, with the structure designed for easy addition of specific gamemode stats in future updates

Backward Compatibility

This change is fully backward compatible. The existing /v1/playerdata endpoint remains unchanged and continues to return Hypixel API-compatible responses for existing clients like Prism overlay.

Files Added

  • internal/ports/player_v2.go - Main handler implementation
  • internal/ports/player_v2_converters.go - Response structure and conversion logic
  • internal/ports/player_v2_test.go - Handler tests
  • internal/ports/player_v2_converters_test.go - Converter tests

The endpoint is now available for testing:

curl 'localhost:8123/v2/player/01234567-89ab-cdef-0123-456789abcdef'
Original prompt

Create a new handler for playerdata. Call it /v2/player/{uuid} base the structure on the history and session handlers . Write tests for tge handlers based on it receiving a player instance and checking the output. Make a set of new structs with json tags that closely match the domain player structs.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add new handler for playerdata endpoint /v2/player/{uuid} Add V2 player endpoint with clean JSON response structure Oct 10, 2025
Copilot AI requested a review from Amund211 October 10, 2025 15:25
Copilot AI and others added 2 commits October 12, 2025 00:31
Co-authored-by: Amund211 <14028449+Amund211@users.noreply.github.com>
@Amund211 Amund211 force-pushed the copilot/add-playerdata-handler branch from ebd075e to 10c5017 Compare October 11, 2025 22:31
Copy link
Copy Markdown
Owner

@Amund211 Amund211 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot The branch has been rebased. Fix the route definitions in main.go to use the new helper, and fix any code quality check errors.

Prefer v2 as a suffix. E.g rename the file to player_v2.go, Rename to MakeGetPlayerV2Handler, rename to PlayerToPlayerResponseDataV2, rename to PlayerResponseV2

To start with, don't include specific gamemode stats. Only include overall. Keep it as a separate field, so specific gamemodes are easy to add later.

Verify that all code quality checks pass after the changes have been implemented

… stats only, fix route definitions

Co-authored-by: Amund211 <14028449+Amund211@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 11, 2025

@copilot The branch has been rebased. Fix the route definitions in main.go to use the new helper, and fix any code quality check errors.

Prefer v2 as a suffix. E.g rename the file to player_v2.go, Re...

Fixed all requested changes in commit 32d3ae9:

Route definitions: Updated to use handleFunc helper instead of direct http.HandleFunc
v2 suffix naming: Renamed all files and functions:

  • Files: v2_player.goplayer_v2.go, etc.
  • Functions: MakeGetV2PlayerHandlerMakeGetPlayerV2Handler, PlayerToV2PlayerResponseDataPlayerToPlayerResponseDataV2, etc.

Simplified response: Removed specific gamemode stats (solo, doubles, threes, fours), keeping only overall stats as a separate field for easy future expansion

Code quality: All tests passing, build successful, no linting errors

The response now only includes the overall stats field while maintaining clean extensibility for adding specific gamemodes later.

Copilot AI requested a review from Amund211 October 11, 2025 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants