Class LockHandlers
Defined in File lock_handlers.hpp
Class Documentation
-
class LockHandlers
Handlers for SOVD entity locking REST API endpoints.
Provides handlers for:
POST /{entity_type}/{entity_id}/locks - Acquire lock
GET /{entity_type}/{entity_id}/locks - List locks
GET /{entity_type}/{entity_id}/locks/{lock_id} - Get lock
PUT /{entity_type}/{entity_id}/locks/{lock_id} - Extend lock
DELETE /{entity_type}/{entity_id}/locks/{lock_id} - Release lock
Locking is supported for components and apps only (per SOVD spec).
All 5 routes follow the PR-403 typed RouteRegistry convention:
http::Result<dto::TResponse> X(const http::TypedRequest & req [, dto::TBody body]);
The framework owns the cpp-httplib response object - handlers never touch it. Errors are returned as
tl::unexpected(ErrorInfo)and the framework renders them via the SOVD GenericError schema. The acquire handler uses the attachments variant so it can return 201 +Location: <request-path>/<lock-id>without re-introducing ahttplib::Response ¶meter.Public Functions
-
LockHandlers(HandlerContext &ctx, LockManager *lock_manager)
Construct lock handlers with shared context and lock manager.
- Parameters:
ctx – The shared handler context
lock_manager – Pointer to the LockManager (may be nullptr if locking disabled)
-
http::Result<std::pair<dto::Lock, http::ResponseAttachments>> post_lock(const http::TypedRequest &req, dto::AcquireLockRequest body)
POST /{entity_type}/{entity_id}/locks - acquire a lock.
Request body:
AcquireLockRequest(validated at framework level). Requires X-Client-Id header. On success returns the newLockbody with a 201 status override and aLocation: <request-path>/<lock-id>header.
-
http::Result<dto::Collection<dto::Lock>> get_locks(const http::TypedRequest &req)
GET /{entity_type}/{entity_id}/locks - list locks on entity.
X-Client-Id header is optional (used to determine the
ownedfield). Returns 200 withCollection<Lock>(single-item or empty).
-
http::Result<dto::Lock> get_lock(const http::TypedRequest &req)
GET /{entity_type}/{entity_id}/locks/{lock_id} - get lock details.
X-Client-Id header is optional (used to determine the
ownedfield). Returns 200 withLock, or 404 if not found.
-
http::Result<http::NoContent> put_lock(const http::TypedRequest &req, dto::ExtendLockRequest body)
PUT /{entity_type}/{entity_id}/locks/{lock_id} - extend lock.
Request body:
ExtendLockRequest. Requires X-Client-Id header. Returns 204 (NoContent) on success, 403 if not owner, 404 if not found.
-
http::Result<http::NoContent> del_lock(const http::TypedRequest &req)
DELETE /{entity_type}/{entity_id}/locks/{lock_id} - release lock.
Requires X-Client-Id header. Returns 204 (NoContent) on success, 403 if not owner, 404 if not found.
Public Static Functions
-
static std::string format_expiration(std::chrono::steady_clock::time_point expires_at)
Format a time_point as ISO 8601 UTC string.