diff --git a/lib/Controller/NoteApiController.php b/lib/Controller/NoteApiController.php index 6563114..acf0120 100644 --- a/lib/Controller/NoteApiController.php +++ b/lib/Controller/NoteApiController.php @@ -134,14 +134,31 @@ class NoteApiController extends ApiController { * @param int $id * @param string $title * @param string $content - * @param array $attachments - * @param bool $isPinned - * @param array $tags - * @param array $sharedWith * @param string $color + * @param bool $isPinned + * @param array $tags + * @param array $sharedWith + * @param array $attachments */ - public function update(int $id, string $title, string $content, array $attachments, bool $isPinned, array $tags, array $sharedWith, string $color): JSONResponse { - $note = $this->noteService->update($this->userId, $id, $title, $content, $attachments, $isPinned, $tags, $sharedWith, $color); + public function update(int $id, + string $title, + string $content, + string $color, + bool $isPinned, + array $tags, + array $sharedWith, + array $attachments): JSONResponse + { + $note = $this->noteService->update($this->userId, + $id, + $title, + $content, + $color, + $isPinned, + $tags, + $sharedWith, + $attachments); + if (is_null($note)) { return new JSONResponse([], Http::STATUS_NOT_FOUND); } diff --git a/lib/Controller/NoteController.php b/lib/Controller/NoteController.php index d1358e6..ce40300 100644 --- a/lib/Controller/NoteController.php +++ b/lib/Controller/NoteController.php @@ -126,14 +126,31 @@ class NoteController extends Controller { * @param int $id * @param string $title * @param string $content - * @param array $attachments - * @param bool $isPinned - * @param array $tags - * @param array $sharedWith * @param string $color + * @param bool $isPinned + * @param array $tags + * @param array $sharedWith + * @param array $attachments */ - public function update(int $id, string $title, string $content, array $attachments = [], bool $isPinned, array $tags = [], array $sharedWith = [], string $color): JSONResponse { - $note = $this->noteService->update($this->userId, $id, $title, $content, $attachments, $isPinned, $tags, $sharedWith, $color); + public function update(int $id, + string $title, + string $content, + string $color, + bool $isPinned, + array $tags, + array $sharedWith, + array $attachments): JSONResponse + { + $note = $this->noteService->update($this->userId, + $id, + $title, + $content, + $color, + $isPinned, + $tags, + $sharedWith, + $attachments); + if (is_null($note)) { return new JSONResponse([], Http::STATUS_NOT_FOUND); } diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php index 11df0fb..43f1af6 100644 --- a/lib/Service/NoteService.php +++ b/lib/Service/NoteService.php @@ -197,7 +197,7 @@ class NoteService { // Insert true color pin and tags to response $newNote->setColor($hcolor->getColor()); - $newNote->setIsPinned(false); + $newNote->setIsPinned($isPinned); $newNote->setTags([]); $newNote->setAttachts([]); @@ -206,24 +206,24 @@ class NoteService { /** * @param string userId - * @param int $id + * @param int $id * @param string $title * @param string $content - * @param array $attachts - * @param bool $pinned - * @param array $tags - * @param array $shares * @param string $color + * @param bool $isPinned + * @param array $sharedWith + * @param array $tags + * @param array $attachments */ public function update(string $userId, int $id, string $title, string $content, - array $attachts, - bool $pinned, + string $color, + bool $isPinned, + array $sharedWith, array $tags, - array $shares, - string $color): ?Note + array $attachments): ?Note { // Get current Note and Color. $note = $this->get($userId, $id); @@ -257,7 +257,7 @@ class NoteService { } // Add new attachts - foreach ($attachts as $attach) { + foreach ($attachments as $attach) { if (!$this->attachMapper->fileAttachExists($userId, $id, $attach['file_id'])) { $hAttach = new Attach(); $hAttach->setUserId($userId); @@ -284,7 +284,7 @@ class NoteService { } // Add new shares - foreach ($shares as $share) { + foreach ($sharedWith as $share) { if (!$this->noteShareMapper->existsByNoteAndUser($id, $share['shared_user'])) { $hShare = new NoteShare(); $hShare->setNoteId($id); @@ -333,7 +333,7 @@ class NoteService { // Set new info on Note $note->setTitle($title); $note->setContent($content); - $note->setPinned($pinned ? 1 : 0); + $note->setPinned($isPinned ? 1 : 0); $note->setTimestamp(time()); $note->setColorId($hcolor->id); @@ -342,7 +342,7 @@ class NoteService { // Insert true color and pin to response $newnote->setColor($hcolor->getColor()); - $newnote->setIsPinned($note->getPinned() ? true : false); + $newnote->setIsPinned($isPinned); // Fill new tags $newnote->setTags($this->tagmapper->getTagsForNote($userId, $newnote->getId()));