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).

Example Game Note Object

{
  "id": 1,
  "gameId": 1,
  "userId": 1,
  "title": "title",
  "content": "content",
  "createdAt": "...",
  "lastModifiedAt": "..."
}

Endpoint Details

Add Game Note

Method: POST
Path: /add

Response

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

Possible Errors

  • 400 Bad Request: Missing fields, empty title/content, or duplicate title.
  • 403 Forbidden: User not authorized to add notes for another user or game is inactive.
  • 404 Not Found: Game or user does not exist.

Get All Notes for Current User

Method: GET
Path: /

Response

{
  "gameNotes": [ { ... } ],
  "message": "Notatki zostały pobrane",
  "error": 200,
  "timestamp": "..."
}

Possible Errors

  • 401 Unauthorized: User is not authenticated.

Get Note by ID

Method: GET
Path: /{gameNoteId}

Response

{
  "message": "Notatka została pobrana",
  "error": 200,
  "gameNote": { ... },
  "timestamp": "..."
}

Possible Errors

  • 403 Forbidden: User not authorized to access this note.
  • 404 Not Found: Note or associated game does not exist.

Get Notes for a Specific Game

Method: GET
Path: /game/{gameId}

Response

{
  "message": "Notatki zostały pobrane",
  "error": 200,
  "gameNotes": [ { ... } ],
  "timestamp": "..."
}

Possible Errors

  • 403 Forbidden: User does not have access to the game.
  • 404 Not Found: Game does not exist.

Update Game Note

Method: PUT
Path: /update/{gameNoteId}

Response

{
  "message": "Notatka została zaktualizowana",
  "error": 200,
  "timestamp": "..."
}

Possible Errors

  • 400 Bad Request: Missing or invalid fields.
  • 403 Forbidden: User not authorized to update the note.
  • 404 Not Found: Note, game, or user does not exist.

Delete Game Note

Method: DELETE
Path: /delete/{gameNoteId}

Response

{
  "message": "Notatka została usunięta",
  "error": 200,
  "timestamp": "..."
}

Possible Errors

  • 403 Forbidden: User not authorized to delete the note.
  • 404 Not Found: Note 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 is the owner of the note and the game is accessible.
⚠️ **GitHub.com Fallback** ⚠️