1
0

PredefinedStatusController.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\UserStatus\Controller;
  8. use OCA\UserStatus\ResponseDefinitions;
  9. use OCA\UserStatus\Service\PredefinedStatusService;
  10. use OCP\AppFramework\Http;
  11. use OCP\AppFramework\Http\Attribute\ApiRoute;
  12. use OCP\AppFramework\Http\DataResponse;
  13. use OCP\AppFramework\OCSController;
  14. use OCP\IRequest;
  15. /**
  16. * @package OCA\UserStatus\Controller
  17. *
  18. * @psalm-import-type UserStatusPredefined from ResponseDefinitions
  19. */
  20. class PredefinedStatusController extends OCSController {
  21. /** @var PredefinedStatusService */
  22. private $predefinedStatusService;
  23. /**
  24. * AStatusController constructor.
  25. *
  26. * @param string $appName
  27. * @param IRequest $request
  28. * @param PredefinedStatusService $predefinedStatusService
  29. */
  30. public function __construct(string $appName,
  31. IRequest $request,
  32. PredefinedStatusService $predefinedStatusService) {
  33. parent::__construct($appName, $request);
  34. $this->predefinedStatusService = $predefinedStatusService;
  35. }
  36. /**
  37. * Get all predefined messages
  38. *
  39. * @NoAdminRequired
  40. *
  41. * @return DataResponse<Http::STATUS_OK, UserStatusPredefined[], array{}>
  42. *
  43. * 200: Predefined statuses returned
  44. */
  45. #[ApiRoute(verb: 'GET', url: '/api/v1/predefined_statuses/')]
  46. public function findAll():DataResponse {
  47. // Filtering out the invisible one, that should only be set by API
  48. return new DataResponse(array_filter($this->predefinedStatusService->getDefaultStatuses(), function (array $status) {
  49. return !array_key_exists('visible', $status) || $status['visible'] === true;
  50. }));
  51. }
  52. }