From 3807b837962809d718173ff4ae4637292512cbe9 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Sat, 19 Sep 2020 11:56:54 -0300 Subject: [PATCH 1/9] Rename some api parameters. --- lib/Controller/NoteApiController.php | 9 +++++---- lib/Controller/NoteController.php | 10 +++++----- lib/Db/Note.php | 26 +++++++++++--------------- lib/Service/NoteService.php | 4 ---- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/lib/Controller/NoteApiController.php b/lib/Controller/NoteApiController.php index c4bcd4f..e4badb3 100644 --- a/lib/Controller/NoteApiController.php +++ b/lib/Controller/NoteApiController.php @@ -116,13 +116,14 @@ class NoteApiController extends ApiController { * @param int $id * @param string $title * @param string $content - * @param array $attachts - * @param bool $pinned + * @param array $attachments + * @param bool $isPinned * @param array $tags + * @param array $sharedWith * @param string $color */ - public function update(int $id, string $title, string $content, array $attachts, bool $pinned, array $tags, string $color = "#F7EB96"): JSONResponse { - $note = $this->noteService->update($this->userId, $id, $title, $content, $attachts, $pinned, $tags, $color); + 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); if (is_null($note)) { return new JSONResponse([], Http::STATUS_NOT_FOUND); } diff --git a/lib/Controller/NoteController.php b/lib/Controller/NoteController.php index 3581ecf..00dc8ab 100644 --- a/lib/Controller/NoteController.php +++ b/lib/Controller/NoteController.php @@ -108,14 +108,14 @@ class NoteController extends Controller { * @param int $id * @param string $title * @param string $content - * @param array $attachts - * @param bool $pinned + * @param array $attachments + * @param bool $isPinned * @param array $tags - * @param array $shared_with + * @param array $sharedWith * @param string $color */ - public function update(int $id, string $title, string $content, array $attachts, bool $pinned, array $tags, array $shared_with, string $color = "#F7EB96"): JSONResponse { - $note = $this->noteService->update($this->userId, $id, $title, $content, $attachts, $pinned, $tags, $shared_with, $color); + 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); if (is_null($note)) { return new JSONResponse([], Http::STATUS_NOT_FOUND); } diff --git a/lib/Db/Note.php b/lib/Db/Note.php index 15007da..c7e03a4 100644 --- a/lib/Db/Note.php +++ b/lib/Db/Note.php @@ -15,7 +15,6 @@ class Note extends Entity implements JsonSerializable { protected $userId; protected $sharedWith = []; protected $sharedBy = []; - protected $isShared; protected $tags; protected $attachts; @@ -32,20 +31,17 @@ class Note extends Entity implements JsonSerializable { public function jsonSerialize() { return [ - 'id' => $this->id, - 'title' => $this->title, - 'content' => $this->content, - 'pinned' => $this->pinned, - 'ispinned' => $this->isPinned, - 'timestamp' => $this->timestamp, - 'colorid' => $this->colorId, - 'color' => $this->color, - 'userid' => $this->userId, - 'shared_with' => $this->sharedWith, - 'shared_by' => $this->sharedBy, - 'is_shared' => $this->isShared, - 'tags' => $this->tags, - 'attachts' => $this->attachts + 'id' => $this->id, + 'title' => $this->title, + 'content' => $this->content, + 'pinned' => $this->pinned, + 'isPinned' => $this->isPinned, + 'timestamp' => $this->timestamp, + 'color' => $this->color, + 'sharedWith' => $this->sharedWith, + 'sharedBy' => $this->sharedBy, + 'tags' => $this->tags, + 'attachments' => $this->attachts ]; } } diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php index bd8c08c..ed13bbe 100644 --- a/lib/Service/NoteService.php +++ b/lib/Service/NoteService.php @@ -81,7 +81,6 @@ class NoteService { // Set shares with others. foreach($notes as $note) { - $note->setIsShared(false); $note->setSharedWith($this->noteShareMapper->getSharesForNote($note->getId())); } @@ -90,8 +89,6 @@ class NoteService { $sharedEntries = $this->noteShareMapper->findForUser($userId); foreach($sharedEntries as $sharedEntry) { $sharedNote = $this->notemapper->findShared($sharedEntry->getNoteId()); - $sharedNote->setIsShared(true); - $sharedEntry->setUserId($sharedNote->getUserId()); $sharedNote->setSharedBy([$sharedEntry]); $shares[] = $sharedNote; @@ -343,7 +340,6 @@ class NoteService { $newnote->setAttachts($attachts); // Fill shared with with others - $newnote->setIsShared(false); $newnote->setSharedWith($this->noteShareMapper->getSharesForNote($newnote->getId())); // Remove old color if necessary From 959aa90f1aa31dd1af024b3e4a07de80ace2aea7 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Fri, 18 Sep 2020 09:27:23 -0300 Subject: [PATCH 2/9] Register nextcloud capabilities to check api versions.. ... ... 0.6.0 1.0 ... --- lib/AppInfo/Application.php | 13 +++++++-- lib/AppInfo/Capabilities.php | 47 +++++++++++++++++++++++++++++++++ lib/Service/SettingsService.php | 4 +-- 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 lib/AppInfo/Capabilities.php diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index f67f6d1..719d758 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -32,14 +32,18 @@ use OCP\IServerContainer; class Application extends App { /** @var string */ - public const APP_NAME = 'quicknotes'; + public const APP_ID = 'quicknotes'; + + /** @var string */ + public const API_VERSION = '1.0'; public function __construct(array $urlParams = []) { - parent::__construct(self::APP_NAME, $urlParams); + parent::__construct(self::APP_ID, $urlParams); } public function register(): void { $this->registerNavigationEntry(); + $this->registerCapabilities(); } private function registerNavigationEntry(): void { @@ -59,4 +63,9 @@ class Application extends App { }); } + private function registerCapabilities(): void { + $container = $this->getContainer(); + $container->registerCapability(Capabilities::class); + } + } \ No newline at end of file diff --git a/lib/AppInfo/Capabilities.php b/lib/AppInfo/Capabilities.php new file mode 100644 index 0000000..a24939a --- /dev/null +++ b/lib/AppInfo/Capabilities.php @@ -0,0 +1,47 @@ + + * + * @author 2016 Matias De lellis + * + * @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\QuickNotes\AppInfo; + +use OCP\Capabilities\ICapability; +use OCP\App\IAppManager; + +class Capabilities implements ICapability { + + /** @var IAppManager */ + private $appManager; + + public function __construct(IAppManager $appManager) { + $this->appManager = $appManager; + } + + public function getCapabilities() { + return [ + Application::APP_ID => [ + 'version' => $this->appManager->getAppVersion(Application::APP_ID), + 'api_version' => Application::API_VERSION, + ], + ]; + } + +} \ No newline at end of file diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index 97ff5bc..0df0daf 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -55,11 +55,11 @@ class SettingsService { public function getColorForNewNotes(): string { - return $this->config->getUserValue($this->userId, Application::APP_NAME, self::COLOR_FOR_NEW_NOTES_KEY, self::DEFAULT_COLOR_FOR_NEW_NOTES); + return $this->config->getUserValue($this->userId, Application::APP_ID, self::COLOR_FOR_NEW_NOTES_KEY, self::DEFAULT_COLOR_FOR_NEW_NOTES); } public function setColorForNewNotes(string $color) { - $this->config->setUserValue($this->userId, Application::APP_NAME, self::COLOR_FOR_NEW_NOTES_KEY, $color); + $this->config->setUserValue($this->userId, Application::APP_ID, self::COLOR_FOR_NEW_NOTES_KEY, $color); } } From 587fc10c7684a54ce39473270fd87079ed63c1f4 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Sat, 19 Sep 2020 12:15:03 -0300 Subject: [PATCH 3/9] Adapt the fronted to the new parameters. --- js/script.js | 18 +++++++++--------- js/templates/attachts.handlebars | 2 +- js/templates/note-item.handlebars | 8 ++++---- js/templates/notes.handlebars | 14 +++++++------- js/templates/shares.handlebars | 2 +- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/js/script.js b/js/script.js index 2b1f9ed..f6ecf21 100644 --- a/js/script.js +++ b/js/script.js @@ -204,14 +204,14 @@ View.prototype = { this._editableId(note.id); this._editableTitle(note.title); this._editableContent(note.content); - this._editablePinned(note.ispinned); + this._editablePinned(note.isPinned); this._editableColor(note.color); - this._editableShares(note.shared_with); + this._editableShares(note.sharedWith); this._editableTags(note.tags); - this._editableAttachts(note.attachts, !note.is_shared); + this._editableAttachts(note.attachments, !note.sharedBy.length); // Create medium div editor. - this._isEditable(!note.is_shared); + this._isEditable(!note.sharedBy.length); // Show modal editor this._showEditor(id); @@ -222,11 +222,11 @@ View.prototype = { id: this._editableId(), title: this._editableTitle(), content: this._editableContent(), - attachts: this._editableAttachts(), + attachments: this._editableAttachts(), color: this._editableColor(), - pinned: this._editablePinned(), + isPinned: this._editablePinned(), tags: this._editableTags(), - shared_with: this._editableShares() + sharedWith: this._editableShares() }; var self = this; this._notes.update(fakeNote).done(function (note) { @@ -851,7 +851,7 @@ View.prototype = { }; }); } else { - var html = Handlebars.templates['shares']({shared_with: shared_with}); + var html = Handlebars.templates['shares']({sharedWith: shared_with}); $("#modal-note-div .note-shares").replaceWith(html); } }, @@ -878,7 +878,7 @@ View.prototype = { }; }); } else { - var html = Handlebars.templates['attachts']({ attachts: attachts, can_delete: can_delete}); + var html = Handlebars.templates['attachts']({ attachments: attachts, can_delete: can_delete}); $("#modal-note-div .note-attachts").replaceWith(html); lozad('.attach-preview').observe(); diff --git a/js/templates/attachts.handlebars b/js/templates/attachts.handlebars index 63d04d3..9763cde 100644 --- a/js/templates/attachts.handlebars +++ b/js/templates/attachts.handlebars @@ -1,5 +1,5 @@
- {{#each attachts}} + {{#each attachments}}
diff --git a/js/templates/note-item.handlebars b/js/templates/note-item.handlebars index 5c36109..3773662 100644 --- a/js/templates/note-item.handlebars +++ b/js/templates/note-item.handlebars @@ -1,8 +1,8 @@
-
+
- {{#each attachts}} + {{#each attachments}}
@@ -11,7 +11,7 @@
- {{#if ispinned}} + {{#if isPinned}}
{{else}}
@@ -25,7 +25,7 @@ {{{ content }}}
- {{#each shared_with}} + {{#each sharedWith}} {{/each}}
diff --git a/js/templates/notes.handlebars b/js/templates/notes.handlebars index 683987b..db84aa2 100644 --- a/js/templates/notes.handlebars +++ b/js/templates/notes.handlebars @@ -2,10 +2,10 @@
{{#each notes}}
-
+
- {{#each attachts}} + {{#each attachments}}
@@ -14,11 +14,11 @@
- {{#if is_shared}} -
-
+ {{#if sharedBy}} +
+
{{else}} - {{#if ispinned}} + {{#if isPinned}}
{{else}}
@@ -33,7 +33,7 @@ {{{ content }}}
- {{#each shared_with}} + {{#each sharedWith}} {{/each}}
diff --git a/js/templates/shares.handlebars b/js/templates/shares.handlebars index 77c5a7d..542c009 100644 --- a/js/templates/shares.handlebars +++ b/js/templates/shares.handlebars @@ -1,5 +1,5 @@
- {{#each shared_with}} + {{#each sharedWith}} {{/each}}
\ No newline at end of file From 4f260c9af0c9f7c333b44a07820e3c3bb0276fcd Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Sat, 19 Sep 2020 13:25:07 -0300 Subject: [PATCH 4/9] Smal misc fixes... --- lib/Controller/NoteApiController.php | 6 +++--- lib/Controller/NoteController.php | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/Controller/NoteApiController.php b/lib/Controller/NoteApiController.php index e4badb3..2d6dd02 100644 --- a/lib/Controller/NoteApiController.php +++ b/lib/Controller/NoteApiController.php @@ -37,7 +37,7 @@ class NoteApiController extends ApiController { private $userId; public function __construct($AppName, - IRequest $request, + IRequest $request, NoteService $noteService, $userId) { @@ -74,7 +74,7 @@ class NoteApiController extends ApiController { * * @param int $id */ - public function show($id): JSONResponse { + public function show(int $id): JSONResponse { $note = $this->noteService->get($this->userId, $id); if (is_null($note)) { return new JSONResponse([], Http::STATUS_NOT_FOUND); @@ -97,7 +97,7 @@ class NoteApiController extends ApiController { * @param string $content * @param string $color */ - public function create($title, $content, $color = "#F7EB96") { + public function create(string $title, string $content, string $color = null) { $note = $this->noteService->create($this->userId, $title, $content, $color); $etag = md5(json_encode($note)); diff --git a/lib/Controller/NoteController.php b/lib/Controller/NoteController.php index 00dc8ab..9aa5883 100644 --- a/lib/Controller/NoteController.php +++ b/lib/Controller/NoteController.php @@ -37,7 +37,7 @@ class NoteController extends Controller { private $userId; public function __construct($AppName, - IRequest $request, + IRequest $request, NoteService $noteService, $userId) { @@ -70,7 +70,7 @@ class NoteController extends Controller { * * @param int $id */ - public function show($id): JSONResponse { + public function show(int $id): JSONResponse { $note = $this->noteService->get($this->userId, $id); if (is_null($note)) { return new JSONResponse([], Http::STATUS_NOT_FOUND); @@ -91,7 +91,7 @@ class NoteController extends Controller { * @param string $content * @param string $color */ - public function create($title, $content, $color = NULL) { + public function create(string $title, string $content, string $color = null) { $note = $this->noteService->create($this->userId, $title, $content, $color); $etag = md5(json_encode($note)); @@ -137,4 +137,5 @@ class NoteController extends Controller { $this->noteService->destroy($this->userId, $id); return new JSONResponse([]); } + } From 5e076da22a4e13aade11fc35e246e054fac111c6 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Sat, 19 Sep 2020 13:54:39 -0300 Subject: [PATCH 5/9] Can create the notes with more optional parameters --- lib/Controller/NoteApiController.php | 22 ++++++++++++++++++++-- lib/Controller/NoteController.php | 22 ++++++++++++++++++++-- lib/Service/NoteService.php | 20 ++++++++++++++++++-- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/lib/Controller/NoteApiController.php b/lib/Controller/NoteApiController.php index 2d6dd02..6563114 100644 --- a/lib/Controller/NoteApiController.php +++ b/lib/Controller/NoteApiController.php @@ -96,9 +96,27 @@ class NoteApiController extends ApiController { * @param string $title * @param string $content * @param string $color + * @param bool $isPinned + * @param array $sharedWith + * @param array $tags + * @param array $attachments */ - public function create(string $title, string $content, string $color = null) { - $note = $this->noteService->create($this->userId, $title, $content, $color); + public function create(string $title, + string $content, + string $color = null, + bool $isPinned = false, + array $sharedWith = [], + array $tags = [], + array $attachments = []) + { + $note = $this->noteService->create($this->userId, + $title, + $content, + $color, + $isPinned, + $sharedWith, + $tags, + $attachments); $etag = md5(json_encode($note)); diff --git a/lib/Controller/NoteController.php b/lib/Controller/NoteController.php index 9aa5883..d1358e6 100644 --- a/lib/Controller/NoteController.php +++ b/lib/Controller/NoteController.php @@ -90,9 +90,27 @@ class NoteController extends Controller { * @param string $title * @param string $content * @param string $color + * @param bool $isPinned + * @param array $sharedWith + * @param array $tags + * @param array $attachments */ - public function create(string $title, string $content, string $color = null) { - $note = $this->noteService->create($this->userId, $title, $content, $color); + public function create(string $title, + string $content, + string $color = null, + bool $isPinned = false, + array $sharedWith = [], + array $tags = [], + array $attachments = []) + { + $note = $this->noteService->create($this->userId, + $title, + $content, + $color, + $isPinned, + $sharedWith, + $tags, + $attachments); $etag = md5(json_encode($note)); diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php index ed13bbe..11df0fb 100644 --- a/lib/Service/NoteService.php +++ b/lib/Service/NoteService.php @@ -152,9 +152,21 @@ class NoteService { * @param string $userId * @param string $title * @param string $content - * @param string $color + * @param string $color optional color. + * @param bool $isPinned optional if note must be pinned + * @param array $sharedWith optional list of shares + * @param array $tags optional list of tags + * @param array $attachments optional list of attachments */ - public function create(string $userId, string $title, string $content, string $color = NULL): Note { + public function create(string $userId, + string $title, + string $content, + string $color = null, + bool $isPinned = false, + array $sharedWith = [], + array $tags = [], + array $attachments = []): ?Note + { if (is_null($color)) { $color = $this->settingsService->getColorForNewNotes(); } @@ -168,17 +180,21 @@ class NoteService { $hcolor = $this->colormapper->insert($hcolor); } + // Create note and insert it $note = new Note(); $note->setTitle($title); $note->setContent($content); + $note->setPinned($isPinned ? 1 : 0); $note->setTimestamp(time()); $note->setColorId($hcolor->id); $note->setUserId($userId); $newNote = $this->notemapper->insert($note); + // TODO: Insert optional shares, tags and attachments. + // Insert true color pin and tags to response $newNote->setColor($hcolor->getColor()); $newNote->setIsPinned(false); From d002d7cf1e1fc5e85f1d19e5496af6914ac61d12 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Sat, 19 Sep 2020 14:23:33 -0300 Subject: [PATCH 6/9] Just some reorder of arguments.. --- lib/Controller/NoteApiController.php | 29 ++++++++++++++++++++++------ lib/Controller/NoteController.php | 29 ++++++++++++++++++++++------ lib/Service/NoteService.php | 28 +++++++++++++-------------- 3 files changed, 60 insertions(+), 26 deletions(-) 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())); From 10442c5117c1e2fde9aec785a2baf83c236d23fc Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Sat, 19 Sep 2020 14:27:50 -0300 Subject: [PATCH 7/9] Just add type to destroy arguments. --- lib/Service/NoteService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php index 43f1af6..f47eba4 100644 --- a/lib/Service/NoteService.php +++ b/lib/Service/NoteService.php @@ -375,7 +375,7 @@ class NoteService { * @param string $userId * @param int $id */ - public function destroy($userId, $id) { + public function destroy (string $userId, int $id) { // Get Note and Color try { $note = $this->notemapper->find($id, $userId); From 80ed5f59ad917817974012f54beb1fae32bf3df8 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Sat, 19 Sep 2020 17:56:15 -0300 Subject: [PATCH 8/9] Move Shared argument at the end.. --- lib/Controller/NoteApiController.php | 10 +++++----- lib/Controller/NoteController.php | 10 +++++----- lib/Service/NoteService.php | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/Controller/NoteApiController.php b/lib/Controller/NoteApiController.php index acf0120..dbc1bc2 100644 --- a/lib/Controller/NoteApiController.php +++ b/lib/Controller/NoteApiController.php @@ -137,8 +137,8 @@ class NoteApiController extends ApiController { * @param string $color * @param bool $isPinned * @param array $tags - * @param array $sharedWith * @param array $attachments + * @param array $sharedWith */ public function update(int $id, string $title, @@ -146,8 +146,8 @@ class NoteApiController extends ApiController { string $color, bool $isPinned, array $tags, - array $sharedWith, - array $attachments): JSONResponse + array $attachments, + array $sharedWith): JSONResponse { $note = $this->noteService->update($this->userId, $id, @@ -156,8 +156,8 @@ class NoteApiController extends ApiController { $color, $isPinned, $tags, - $sharedWith, - $attachments); + $attachments, + $sharedWith); if (is_null($note)) { return new JSONResponse([], Http::STATUS_NOT_FOUND); diff --git a/lib/Controller/NoteController.php b/lib/Controller/NoteController.php index ce40300..476ab97 100644 --- a/lib/Controller/NoteController.php +++ b/lib/Controller/NoteController.php @@ -129,8 +129,8 @@ class NoteController extends Controller { * @param string $color * @param bool $isPinned * @param array $tags - * @param array $sharedWith * @param array $attachments + * @param array $sharedWith */ public function update(int $id, string $title, @@ -138,8 +138,8 @@ class NoteController extends Controller { string $color, bool $isPinned, array $tags, - array $sharedWith, - array $attachments): JSONResponse + array $attachments, + array $sharedWith): JSONResponse { $note = $this->noteService->update($this->userId, $id, @@ -148,8 +148,8 @@ class NoteController extends Controller { $color, $isPinned, $tags, - $sharedWith, - $attachments); + $attachments, + $sharedWith); if (is_null($note)) { return new JSONResponse([], Http::STATUS_NOT_FOUND); diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php index f47eba4..9e0a96c 100644 --- a/lib/Service/NoteService.php +++ b/lib/Service/NoteService.php @@ -211,9 +211,9 @@ class NoteService { * @param string $content * @param string $color * @param bool $isPinned - * @param array $sharedWith * @param array $tags * @param array $attachments + * @param array $sharedWith */ public function update(string $userId, int $id, @@ -221,9 +221,9 @@ class NoteService { string $content, string $color, bool $isPinned, - array $sharedWith, array $tags, - array $attachments): ?Note + array $attachments, + array $sharedWith): ?Note { // Get current Note and Color. $note = $this->get($userId, $id); @@ -272,7 +272,7 @@ class NoteService { $dbShares = $this->noteShareMapper->getSharesForNote($id); foreach ($dbShares as $dbShare) { $delete = true; - foreach ($shares as $share) { + foreach ($sharedWith as $share) { if ($dbShare->getSharedUser() === $share['shared_user']) { $delete = false; break; From d316392dfd7d6c03168b9480468952d134fe62dc Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Sat, 19 Sep 2020 18:04:02 -0300 Subject: [PATCH 9/9] Fix pin note.. --- js/script.js | 4 ++-- lib/Db/Note.php | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/js/script.js b/js/script.js index f6ecf21..8bd6cb6 100644 --- a/js/script.js +++ b/js/script.js @@ -390,7 +390,7 @@ View.prototype = { var id = parseInt(gridNote.data('id'), 10); var note = self._notes.read(id); - note.pinned = true; + note.isPinned = true; self._notes.update(note).done(function () { icon.removeClass("hide-header-icon"); @@ -413,7 +413,7 @@ View.prototype = { var id = parseInt(gridNote.data('id'), 10); var note = self._notes.read(id); - note.pinned = false; + note.isPinned = false; self._notes.update(note).done(function () { icon.removeClass("fixed-header-icon"); diff --git a/lib/Db/Note.php b/lib/Db/Note.php index c7e03a4..7bd54d4 100644 --- a/lib/Db/Note.php +++ b/lib/Db/Note.php @@ -34,7 +34,6 @@ class Note extends Entity implements JsonSerializable { 'id' => $this->id, 'title' => $this->title, 'content' => $this->content, - 'pinned' => $this->pinned, 'isPinned' => $this->isPinned, 'timestamp' => $this->timestamp, 'color' => $this->color,