GameNoteController - xEdziu/RPG-Handy-Helper GitHub Wiki

GameNoteController

This page contains documentation for the GameNoteController class, which handles note management for games.

Basic Information

Base Path: /api/v1/authorized/gameNotes
Package: dev.goral.rpghandyhelper.notes

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
POST /add Adds a new note for the current user
GET / Retrieves all notes for the current user
GET /{gameNoteId} Retrieves a specific note by ID
GET /game/{gameId} Retrieves notes for a specific game
PUT /update/{gameNoteId} Updates an existing note
DELETE /delete/{gameNoteId} Deletes a note by ID

Field Descriptions

Request Body Fields (GameNoteDto)

  • gameId (Long): ID of the game the note is associated with. Required.
  • userId (Long): ID of the note author (must match logged-in user). Required.
  • title (String): Note title. Must be unique per user-game pair. Required.
  • content (String): Main body of the note. Required.

Response Fields

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

GameNote Sample Object (View DTO)

{
  "title": "Moja notatka",
  "content": "Zawartość notatki",
  "createdAt": "2025-05-22T12:00:00.000+00:00",
  "updatedAt": "2025-05-22T12:00:00.000+00:00"
}

Detailed Endpoints

Add Game Note

Method: POST
Path: /add

Request

{
  "gameId": 1,
  "userId": 2,
  "title": "Moja pierwsza notatka",
  "content": "Treść notatki do kampanii."
}

Response

{
  "message": "Notatka została dodana",
  "error": 200,
  "timestamp": "2025-05-22T12:00:00.000+00:00"
}

Possible Errors

  • 400 Bad Request: Missing or invalid fields in the request body.
  • 403 Forbidden: User does not have permission to add notes for another user.
  • 404 Not Found: Game or user with the specified ID does not exist.

Get All Notes for Current User

Method: GET
Path: /

Response

{
  "message": "Notatki zostały pobrane",
  "error": 200,
  "timestamp": "2025-05-22T12:00:00.000+00:00",
  "gameNotes": [
    {
      "title": "Moja notatka",
      "content": "Zawartość notatki",
      "createdAt": "...",
      "updatedAt": "..."
    }
  ]
}

Possible Errors

  • 400 Bad Request: User is not authenticated.

Get Note by ID

Method: GET
Path: /{gameNoteId}

Response

{
  "message": "Notatka została pobrana",
  "error": 200,
  "timestamp": "2025-05-22T12:00:00.000+00:00",
  "gameNote": {
    "title": "Moja notatka",
    "content": "Zawartość notatki",
    "createdAt": "...",
    "updatedAt": "..."
  }
}

Possible Errors

  • 400 Bad Request: User is not authenticated.
  • 403 Forbidden: User does not have permission to access the note.
  • 404 Not Found: Note with the specified ID does not exist.

Get Notes for a Specific Game

Method: GET
Path: /game/{gameId}

Response

{
  "message": "Notatki zostały pobrane",
  "error": 200,
  "timestamp": "2025-05-22T12:00:00.000+00:00",
  "gameNotes": [
    {
      "title": "Moja notatka",
      "content": "Zawartość notatki",
      "createdAt": "...",
      "updatedAt": "..."
    }
  ]
}

Possible Errors

  • 400 Bad Request: User is not authenticated.
  • 403 Forbidden: User does not have permission to access notes for the game.
  • 404 Not Found: Game with the specified ID does not exist.

Update Game Note

Method: PUT
Path: /update/{gameNoteId}

Request

{
  "gameId": 1,
  "userId": 2,
  "title": "Zaktualizowany tytuł",
  "content": "Zmieniona treść notatki."
}

Response

{
  "message": "Notatka została zaktualizowana",
  "error": 200,
  "timestamp": "2025-05-22T12:00:00.000+00:00"
}

Possible Errors

  • 400 Bad Request: Missing or invalid fields in the request body.
  • 403 Forbidden: User does not have permission to update the note.
  • 404 Not Found: Note, game, or user with the specified ID does not exist.

Delete Game Note

Method: DELETE
Path: /delete/{gameNoteId}

Response

{
  "message": "Notatka została usunięta",
  "error": 200,
  "timestamp": "2025-05-22T12:00:00.000+00:00"
}

Possible Errors

  • 400 Bad Request: User is not authenticated.
  • 403 Forbidden: User does not have permission to delete the note.
  • 404 Not Found: Note 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** ⚠️