diff --git a/lib/Controller/CardApiController.php b/lib/Controller/CardApiController.php index d6ee8210c..95eea6f54 100644 --- a/lib/Controller/CardApiController.php +++ b/lib/Controller/CardApiController.php @@ -25,6 +25,7 @@ namespace OCA\Deck\Controller; +use OCA\Deck\Model\OptionalNullableValue; use OCA\Deck\Service\AssignmentService; use OCA\Deck\Service\CardService; use OCP\AppFramework\ApiController; @@ -104,7 +105,8 @@ class CardApiController extends ApiController { * * Update a card */ - public function update($title, $type, $owner, $description = '', $order = 0, $duedate = null, $archived = null, ?bool $done = null) { + public function update($title, $type, $owner, $description = '', $order = 0, $duedate = null, $archived = null) { + $done = array_key_exists('done', $this->request->getParams()) ? new OptionalNullableValue($this->request->getParam('done', null)) : null; $card = $this->cardService->update($this->request->getParam('cardId'), $title, $this->request->getParam('stackId'), $type, $owner, $description, $order, $duedate, 0, $archived, $done); return new DataResponse($card, HTTP::STATUS_OK); } diff --git a/lib/Model/OptionalNullableValue.php b/lib/Model/OptionalNullableValue.php new file mode 100644 index 000000000..0d3240621 --- /dev/null +++ b/lib/Model/OptionalNullableValue.php @@ -0,0 +1,51 @@ + + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCA\Deck\Model; + +/** + * This is a helper abstraction to allow usage of optional parameters + * which hold a nullable value. The actual null value of the parameter + * is used to indicate if it has been set or not. The containing value + * will then still allow having null as a value + * + * Example use case: Have a nullable database column, + * but only update it if it is passed + * + * @template T + */ +class OptionalNullableValue { + + /** @var ?T */ + private mixed $value; + + /** @param ?T $value */ + public function __construct(mixed $value) { + $this->value = $value; + } + + /** @return ?T */ + public function getValue(): mixed { + return $this->value; + } + +} diff --git a/lib/Service/CardService.php b/lib/Service/CardService.php index 33db81406..abf8ee378 100644 --- a/lib/Service/CardService.php +++ b/lib/Service/CardService.php @@ -43,6 +43,7 @@ use OCA\Deck\Event\CardCreatedEvent; use OCA\Deck\Event\CardDeletedEvent; use OCA\Deck\Event\CardUpdatedEvent; use OCA\Deck\Model\CardDetails; +use OCA\Deck\Model\OptionalNullableValue; use OCA\Deck\NoPermissionException; use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\StatusException; @@ -294,7 +295,7 @@ class CardService { * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws BadRequestException */ - public function update($id, $title, $stackId, $type, $owner, $description = '', $order = 0, $duedate = null, $deletedAt = null, $archived = null, $done = null) { + public function update($id, $title, $stackId, $type, $owner, $description = '', $order = 0, $duedate = null, $deletedAt = null, $archived = null, ?OptionalNullableValue $done = null) { $this->cardServiceValidator->check(compact('id', 'title', 'stackId', 'type', 'owner', 'order')); $this->permissionService->checkPermission($this->cardMapper, $id, Acl::PERMISSION_EDIT); @@ -345,7 +346,7 @@ class CardService { $card->setArchived($archived); } if ($done !== null) { - $card->setDone($done); + $card->setDone($done->getValue()); }