ContactsMenuController.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\JSONResponse;
  13. use OCP\IRequest;
  14. use OCP\IUserSession;
  15. class ContactsMenuController extends Controller {
  16. public function __construct(
  17. IRequest $request,
  18. private IUserSession $userSession,
  19. private Manager $manager,
  20. ) {
  21. parent::__construct('core', $request);
  22. }
  23. /**
  24. * @NoAdminRequired
  25. *
  26. * @return \JsonSerializable[]
  27. * @throws Exception
  28. */
  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. * @NoAdminRequired
  35. *
  36. * @return JSONResponse|\JsonSerializable
  37. * @throws Exception
  38. */
  39. #[FrontpageRoute(verb: 'POST', url: '/contactsmenu/findOne')]
  40. public function findOne(int $shareType, string $shareWith) {
  41. $contact = $this->manager->findOne($this->userSession->getUser(), $shareType, $shareWith);
  42. if ($contact) {
  43. return $contact;
  44. }
  45. return new JSONResponse([], Http::STATUS_NOT_FOUND);
  46. }
  47. }