1
0

PredefinedStatusController.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\Attribute\NoAdminRequired;
  13. use OCP\AppFramework\Http\DataResponse;
  14. use OCP\AppFramework\OCSController;
  15. use OCP\IRequest;
  16. /**
  17. * @package OCA\UserStatus\Controller
  18. *
  19. * @psalm-import-type UserStatusPredefined from ResponseDefinitions
  20. */
  21. class PredefinedStatusController extends OCSController {
  22. /**
  23. * AStatusController constructor.
  24. *
  25. * @param string $appName
  26. * @param IRequest $request
  27. * @param PredefinedStatusService $predefinedStatusService
  28. */
  29. public function __construct(
  30. string $appName,
  31. IRequest $request,
  32. private PredefinedStatusService $predefinedStatusService,
  33. ) {
  34. parent::__construct($appName, $request);
  35. }
  36. /**
  37. * Get all predefined messages
  38. *
  39. * @return DataResponse<Http::STATUS_OK, list<UserStatusPredefined>, array{}>
  40. *
  41. * 200: Predefined statuses returned
  42. */
  43. #[NoAdminRequired]
  44. #[ApiRoute(verb: 'GET', url: '/api/v1/predefined_statuses/')]
  45. public function findAll():DataResponse {
  46. // Filtering out the invisible one, that should only be set by API
  47. return new DataResponse(array_values(array_filter($this->predefinedStatusService->getDefaultStatuses(), function (array $status) {
  48. return !array_key_exists('visible', $status) || $status['visible'] === true;
  49. })));
  50. }
  51. }