Class FavoriteGetHandler
GET /api/v2/documents/{docId}/favorite.
Returns whether the calling user has favorited the document plus the
document's current favorite count. The docId is extracted from the
path by the manager; this handler validates it against a conservative
[A-Za-z0-9_-]+ regex so a malformed value (path traversal attempt,
empty segment, …) surfaces as a structured V2ErrorCode.INVALID_REQUEST
envelope rather than reaching the search backend.
The response payload is:
{ "doc_id": "<id>", "favorite": <bool>, "count": <long> }
The count field is always present (defaults to 0) so
client SDKs can rely on a stable shape rather than branching on its presence.
POST/DELETE handling lives in Plan 3 — this handler only services GET.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
FavoriteGetHandler
public FavoriteGetHandler()Default constructor. The handler is stateless and intended to be instantiated once by the API manager and shared across concurrent requests.
-
-
Method Details
-
handle
public void handle(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, String docId) throws IOException Processes one/api/v2/documents/{docId}/favoriteGET request.Order of checks:
- HTTP method must be
GET. docIdmust be non-blank and match the safety regex.user.favoritefeature flag must be enabled.- Document must exist (or 404).
When the user code is blank (anonymous caller) the
favoriteflag is reported asfalsebut thecountstill reflects the stored value, matching v1's read-only semantics for unauthenticated favorite queries.- Parameters:
req- the incoming HTTP requestres- the HTTP response to write todocId- the document id extracted from the URL path (already trimmed of surrounding path segments)- Throws:
IOException- if writing the envelope fails
- HTTP method must be
-