PredefinedStatusController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2020, Georg Ehrke
  5. *
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Kate Döen <kate.doeen@nextcloud.com>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\UserStatus\Controller;
  26. use OCA\UserStatus\ResponseDefinitions;
  27. use OCA\UserStatus\Service\PredefinedStatusService;
  28. use OCP\AppFramework\Http;
  29. use OCP\AppFramework\Http\Attribute\ApiRoute;
  30. use OCP\AppFramework\Http\DataResponse;
  31. use OCP\AppFramework\OCSController;
  32. use OCP\IRequest;
  33. /**
  34. * @package OCA\UserStatus\Controller
  35. *
  36. * @psalm-import-type UserStatusPredefined from ResponseDefinitions
  37. */
  38. class PredefinedStatusController extends OCSController {
  39. /** @var PredefinedStatusService */
  40. private $predefinedStatusService;
  41. /**
  42. * AStatusController constructor.
  43. *
  44. * @param string $appName
  45. * @param IRequest $request
  46. * @param PredefinedStatusService $predefinedStatusService
  47. */
  48. public function __construct(string $appName,
  49. IRequest $request,
  50. PredefinedStatusService $predefinedStatusService) {
  51. parent::__construct($appName, $request);
  52. $this->predefinedStatusService = $predefinedStatusService;
  53. }
  54. /**
  55. * Get all predefined messages
  56. *
  57. * @NoAdminRequired
  58. *
  59. * @return DataResponse<Http::STATUS_OK, UserStatusPredefined[], array{}>
  60. *
  61. * 200: Predefined statuses returned
  62. */
  63. #[ApiRoute(verb: 'GET', url: '/api/v1/predefined_statuses/')]
  64. public function findAll():DataResponse {
  65. // Filtering out the invisible one, that should only be set by API
  66. return new DataResponse(array_filter($this->predefinedStatusService->getDefaultStatuses(), function (array $status) {
  67. return !array_key_exists('visible', $status) || $status['visible'] === true;
  68. }));
  69. }
  70. }