Class FavoritePostHandler
POST /api/v2/documents/{docId}/favorite.
Marks a document as a favorite for the calling user and bumps the
document's favorite counter. Mirrors v1's
SearchApiManager#processFavoriteRequest but with the v2 envelope and
a JSON body (the query_id that v1 read from a query parameter now
lives in the request body).
Order of checks:
- HTTP method must be
POST. docIdmust be non-blank and match[A-Za-z0-9_-]+.- Caller must be authenticated (saved
FessUserBeanpresent) — the login lookup is wrapped in try/catch so unit harnesses without DBFlute behaviors are treated as anonymous (consistent withMeHandler). user.favoritefeature flag must be enabled.- Body must parse and contain
query_id. - The
docIdmust appear in the user's last result set. - The document must exist in the index.
The ifPresent / orElse(Runnable) shape and the exception-as-
control-flow inside the lambda are kept verbatim from v1 so reviewers can
diff the two paths side-by-side. The outer try/catch converts any
lambda-thrown RuntimeException into a structured v2 error envelope
rather than letting it bubble up as a 500 HTML page.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
FavoritePostHandler
public FavoritePostHandler()Default constructor used by the DI container. The handler holds no per-request state and is safe to share across concurrent requests.
-
-
Method Details
-
handle
public void handle(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, String docId) throws IOException Processes onePOST /api/v2/documents/{docId}/favoriterequest.Validates the HTTP method, document id format, authenticated session, favorite feature flag and request body. On success a favorite is recorded for the user and a success envelope is returned. Failures map to v2 error codes (
V2ErrorCode.AUTH_REQUIRED,V2ErrorCode.INVALID_REQUEST,V2ErrorCode.NOT_FOUND,V2ErrorCode.INTERNAL_ERROR).- Parameters:
req- the incoming HTTP requestres- the HTTP response to write todocId- the document id extracted from the URL path- Throws:
IOException- if writing the envelope or reading the body fails
-