From e54fbf3b3f94792fcec1b2046a3a5ce6547d1e41 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 6 May 2026 14:35:53 +1200 Subject: [PATCH] feat(notifications): mark alert read via PATCH /v1/account/alerts/:alertId/read Co-Authored-By: Claude Opus 4.7 (1M context) --- .../Account/Http/Alerts/Read/Update.php | 75 +++++++++++++++++++ .../Modules/Account/Services/Http.php | 2 + 2 files changed, 77 insertions(+) create mode 100644 src/Appwrite/Platform/Modules/Account/Http/Alerts/Read/Update.php diff --git a/src/Appwrite/Platform/Modules/Account/Http/Alerts/Read/Update.php b/src/Appwrite/Platform/Modules/Account/Http/Alerts/Read/Update.php new file mode 100644 index 0000000000..1aa71013fd --- /dev/null +++ b/src/Appwrite/Platform/Modules/Account/Http/Alerts/Read/Update.php @@ -0,0 +1,75 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) + ->setHttpPath('/v1/account/alerts/:alertId/read') + ->desc('Mark alert read') + ->groups(['api', 'account']) + ->label('scope', 'account') + ->label('sdk', new Method( + namespace: 'account', + group: 'alerts', + name: 'updateAlertRead', + description: '/docs/references/account/update-alert-read.md', + auth: [AuthType::SESSION, AuthType::JWT], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_ALERT, + ) + ] + )) + ->param('alertId', '', new UID(), 'Alert ID.') + ->inject('response') + ->inject('dbForPlatform') + ->inject('user') + ->callback($this->action(...)); + } + + public function action( + string $alertId, + Response $response, + Database $dbForPlatform, + Document $user, + ): void { + $alert = $dbForPlatform->getDocument('alerts', $alertId); + + if ($alert->isEmpty()) { + throw new Exception(Exception::DOCUMENT_NOT_FOUND); + } + + if ($alert->getAttribute('userId') !== $user->getId()) { + throw new Exception(Exception::USER_UNAUTHORIZED); + } + + $updated = $dbForPlatform->updateDocument('alerts', $alertId, new Document([ + 'read' => true, + ])); + + $response->dynamic($updated, Response::MODEL_ALERT); + } +} diff --git a/src/Appwrite/Platform/Modules/Account/Services/Http.php b/src/Appwrite/Platform/Modules/Account/Services/Http.php index fbdf2aecdf..1547412dee 100644 --- a/src/Appwrite/Platform/Modules/Account/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Account/Services/Http.php @@ -12,6 +12,7 @@ use Appwrite\Platform\Modules\Account\Http\Account\MFA\RecoveryCodes\Create as C use Appwrite\Platform\Modules\Account\Http\Account\MFA\RecoveryCodes\Get as GetRecoveryCodes; use Appwrite\Platform\Modules\Account\Http\Account\MFA\RecoveryCodes\Update as UpdateRecoveryCodes; use Appwrite\Platform\Modules\Account\Http\Account\MFA\Update as UpdateMfa; +use Appwrite\Platform\Modules\Account\Http\Alerts\Read\Update as UpdateAlertRead; use Appwrite\Platform\Modules\Account\Http\Alerts\Track\Get as TrackAlert; use Appwrite\Platform\Modules\Account\Http\Alerts\XList as ListAlerts; use Utopia\Platform\Service; @@ -33,6 +34,7 @@ class Http extends Service ->addAction(CreateChallenge::getName(), new CreateChallenge()) ->addAction(UpdateChallenge::getName(), new UpdateChallenge()) ->addAction(ListAlerts::getName(), new ListAlerts()) + ->addAction(UpdateAlertRead::getName(), new UpdateAlertRead()) ->addAction(TrackAlert::getName(), new TrackAlert()); } }