This commit is contained in:
Dennis Eichhorn 2024-03-10 02:24:56 +00:00
parent 35ef0b13bc
commit 155b1ca196
2 changed files with 46 additions and 0 deletions

View File

@ -29,4 +29,15 @@ return [
],
],
],
'^.*/notification(\?.*|$)' => [
[
'dest' => '\Modules\Notification\Controller\ApiController:apiNotificationsGet',
'verb' => RouteVerb::GET,
'permission' => [
'module' => ApiController::NAME,
'type' => PermissionType::READ,
'state' => PermissionCategory::NOTIFICATION,
],
],
],
];

View File

@ -16,8 +16,10 @@ namespace Modules\Notification\Controller;
use Modules\Notification\Models\NotificationMapper;
use phpOMS\DataStorage\Database\Query\OrderType;
use phpOMS\Message\NotificationLevel;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\System\MimeType;
/**
* Api controller for the tasks module.
@ -61,4 +63,37 @@ final class ApiController extends Controller
$this->createStandardUpdateResponse($request, $response, []);
}
/**
* Api method to create a task
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param array $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiNotificationsGet(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void
{
$now = new \DateTimeImmutable('now');
$notifications = NotificationMapper::getAll()
->where('createdFor', $request->header->account)
->where('seenAt', null)
->where('createdAt', $now, '<') // Don't show pre-created notifications
->where('createdAt', $request->getDataDateTime('start') ?? $now->modify('-1 hour'), '>')
->sort('createdAt', OrderType::ASC)
->execute();
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->data[$request->uri->__toString()] = [
'status' => NotificationLevel::OK,
'title' => 'New Notification',
'message' => 'You have new notifications',
'response' => $notifications,
];
}
}