|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * @copyright Copyright (c) 2023 Richard Steinmetz <richard@steinmetz.cloud> |
| 7 | + * |
| 8 | + * @author Richard Steinmetz <richard@steinmetz.cloud> |
| 9 | + * |
| 10 | + * @license AGPL-3.0-or-later |
| 11 | + * |
| 12 | + * This program is free software: you can redistribute it and/or modify |
| 13 | + * it under the terms of the GNU General Public License as published by |
| 14 | + * the Free Software Foundation, either version 3 of the License, or |
| 15 | + * (at your option) any later version. |
| 16 | + * |
| 17 | + * This program is distributed in the hope that it will be useful, |
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | + * GNU General Public License for more details. |
| 21 | + * |
| 22 | + * You should have received a copy of the GNU General Public License |
| 23 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 24 | + * |
| 25 | + */ |
| 26 | + |
| 27 | +namespace OCA\DAV\Controller; |
| 28 | + |
| 29 | +use OCA\DAV\Db\AbsenceMapper; |
| 30 | +use OCA\DAV\ResponseDefinitions; |
| 31 | +use OCP\AppFramework\Db\DoesNotExistException; |
| 32 | +use OCP\AppFramework\Http; |
| 33 | +use OCP\AppFramework\Http\DataResponse; |
| 34 | +use OCP\AppFramework\OCSController; |
| 35 | +use OCP\IRequest; |
| 36 | + |
| 37 | +/** |
| 38 | + * @psalm-import-type DAVOutOfOfficeData from ResponseDefinitions |
| 39 | + */ |
| 40 | +class OutOfOfficeController extends OCSController { |
| 41 | + |
| 42 | + public function __construct( |
| 43 | + string $appName, |
| 44 | + IRequest $request, |
| 45 | + private AbsenceMapper $absenceMapper, |
| 46 | + ) { |
| 47 | + parent::__construct($appName, $request); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Get the currently configured out-of-office data of a user. |
| 52 | + * |
| 53 | + * @NoAdminRequired |
| 54 | + * @NoCSRFRequired |
| 55 | + * |
| 56 | + * @param string $userId The user id to get out-of-office data for. |
| 57 | + * @return DataResponse<Http::STATUS_OK|Http::STATUS_NOT_FOUND, ?DAVOutOfOfficeData, array{}> |
| 58 | + * |
| 59 | + * 200: Out-of-office data |
| 60 | + * 404: No out-of-office data was found |
| 61 | + */ |
| 62 | + public function getCurrentOutOfOfficeData(string $userId): DataResponse { |
| 63 | + try { |
| 64 | + $data = $this->absenceMapper->findByUserId($userId); |
| 65 | + } catch (DoesNotExistException) { |
| 66 | + return new DataResponse(null, Http::STATUS_NOT_FOUND); |
| 67 | + } |
| 68 | + |
| 69 | + return new DataResponse([ |
| 70 | + 'id' => $data->getId(), |
| 71 | + 'userId' => $data->getUserId(), |
| 72 | + 'firstDay' => $data->getFirstDay(), |
| 73 | + 'lastDay' => $data->getLastDay(), |
| 74 | + 'status' => $data->getStatus(), |
| 75 | + 'message' => $data->getMessage(), |
| 76 | + ]); |
| 77 | + } |
| 78 | +} |
0 commit comments