feat(notifications): mark alert read via PATCH /v1/account/alerts/:alertId/read

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jake Barnby
2026-05-06 14:35:53 +12:00
co-authored by Claude Opus 4.7
parent 0a9b54543d
commit e54fbf3b3f
2 changed files with 77 additions and 0 deletions
@@ -0,0 +1,75 @@
<?php
namespace Appwrite\Platform\Modules\Account\Http\Alerts\Read;
use Appwrite\Extend\Exception;
use Appwrite\SDK\AuthType;
use Appwrite\SDK\Method;
use Appwrite\SDK\Response as SDKResponse;
use Appwrite\Utopia\Response;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Validator\UID;
use Utopia\Platform\Action;
use Utopia\Platform\Scope\HTTP;
class Update extends Action
{
use HTTP;
public static function getName(): string
{
return 'updateAlertRead';
}
public function __construct()
{
$this
->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);
}
}
@@ -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());
}
}