ContactsMenuController.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OC\Core\Controller;
  7. use Exception;
  8. use OC\Contacts\ContactsMenu\Manager;
  9. use OCP\AppFramework\Controller;
  10. use OCP\AppFramework\Http;
  11. use OCP\AppFramework\Http\Attribute\FrontpageRoute;
  12. use OCP\AppFramework\Http\Attribute\NoAdminRequired;
  13. use OCP\AppFramework\Http\JSONResponse;
  14. use OCP\IRequest;
  15. use OCP\IUserSession;
  16. class ContactsMenuController extends Controller {
  17. public function __construct(
  18. IRequest $request,
  19. private IUserSession $userSession,
  20. private Manager $manager,
  21. ) {
  22. parent::__construct('core', $request);
  23. }
  24. /**
  25. * @return \JsonSerializable[]
  26. * @throws Exception
  27. */
  28. #[NoAdminRequired]
  29. #[FrontpageRoute(verb: 'POST', url: '/contactsmenu/contacts')]
  30. public function index(?string $filter = null): array {
  31. return $this->manager->getEntries($this->userSession->getUser(), $filter);
  32. }
  33. /**
  34. * @return JSONResponse|\JsonSerializable
  35. * @throws Exception
  36. */
  37. #[NoAdminRequired]
  38. #[FrontpageRoute(verb: 'POST', url: '/contactsmenu/findOne')]
  39. public function findOne(int $shareType, string $shareWith) {
  40. $contact = $this->manager->findOne($this->userSession->getUser(), $shareType, $shareWith);
  41. if ($contact) {
  42. return $contact;
  43. }
  44. return new JSONResponse([], Http::STATUS_NOT_FOUND);
  45. }
  46. }