1<?php 2 3declare(strict_types=1); 4 5/** 6 * @author Kristian Lebold <kristian@lebold.info> 7 * 8 * Mail 9 * 10 * This code is free software: you can redistribute it and/or modify 11 * it under the terms of the GNU Affero General Public License, version 3, 12 * as published by the Free Software Foundation. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Affero General Public License for more details. 18 * 19 * You should have received a copy of the GNU Affero General Public License, version 3, 20 * along with this program. If not, see <http://www.gnu.org/licenses/> 21 * 22 */ 23 24namespace OCA\Mail\Controller; 25 26use OCA\Mail\Service\ContactIntegration\ContactIntegrationService; 27use OCP\AppFramework\Controller; 28use OCP\AppFramework\Http; 29use OCP\AppFramework\Http\JSONResponse; 30use OCP\IRequest; 31 32class ContactIntegrationController extends Controller { 33 34 /** @var ContactIntegrationService */ 35 private $service; 36 37 public function __construct(string $appName, 38 IRequest $request, 39 ContactIntegrationService $service) { 40 parent::__construct($appName, $request); 41 42 $this->service = $service; 43 } 44 45 /** 46 * @NoAdminRequired 47 * @TrapError 48 * 49 * @param string $mail 50 * @return JSONResponse 51 */ 52 public function match(string $mail): JSONResponse { 53 return new JSONResponse($this->service->findMatches($mail)); 54 } 55 56 /** 57 * @NoAdminRequired 58 * @TrapError 59 * 60 * @param string $uid 61 * @param string $mail 62 * @return JSONResponse 63 */ 64 public function addMail(string $uid = null, string $mail = null): JSONResponse { 65 $res = $this->service->addEMailToContact($uid, $mail); 66 if ($res === null) { 67 return new JSONResponse([], Http::STATUS_NOT_FOUND); 68 } 69 return new JSONResponse($res); 70 } 71 72 /** 73 * @NoAdminRequired 74 * @TrapError 75 * 76 * @param string $name 77 * @param string $mail 78 * @return JSONResponse 79 */ 80 public function newContact(string $contactName = null, string $mail = null): JSONResponse { 81 $res = $this->service->newContact($contactName, $mail); 82 if ($res === null) { 83 return new JSONResponse([], Http::STATUS_NOT_ACCEPTABLE); 84 } 85 return new JSONResponse($res); 86 } 87 88 /** 89 * @NoAdminRequired 90 * @TrapError 91 * 92 * @param string $term 93 * @return JSONResponse 94 */ 95 public function autoComplete(string $term): JSONResponse { 96 $res = $this->service->autoComplete($term); 97 return new JSONResponse($res); 98 } 99} 100