aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/api/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'application/api/controllers')
-rw-r--r--application/api/controllers/Links.php38
-rw-r--r--application/api/controllers/Tags.php8
2 files changed, 23 insertions, 23 deletions
diff --git a/application/api/controllers/Links.php b/application/api/controllers/Links.php
index b83b2260..fe4bdc9f 100644
--- a/application/api/controllers/Links.php
+++ b/application/api/controllers/Links.php
@@ -36,13 +36,6 @@ class Links extends ApiController
36 public function getLinks($request, $response) 36 public function getLinks($request, $response)
37 { 37 {
38 $private = $request->getParam('visibility'); 38 $private = $request->getParam('visibility');
39 $bookmarks = $this->bookmarkService->search(
40 [
41 'searchtags' => $request->getParam('searchtags', ''),
42 'searchterm' => $request->getParam('searchterm', ''),
43 ],
44 $private
45 );
46 39
47 // Return bookmarks from the {offset}th link, starting from 0. 40 // Return bookmarks from the {offset}th link, starting from 0.
48 $offset = $request->getParam('offset'); 41 $offset = $request->getParam('offset');
@@ -50,9 +43,6 @@ class Links extends ApiController
50 throw new ApiBadParametersException('Invalid offset'); 43 throw new ApiBadParametersException('Invalid offset');
51 } 44 }
52 $offset = ! empty($offset) ? intval($offset) : 0; 45 $offset = ! empty($offset) ? intval($offset) : 0;
53 if ($offset > count($bookmarks)) {
54 return $response->withJson([], 200, $this->jsonStyle);
55 }
56 46
57 // limit parameter is either a number of bookmarks or 'all' for everything. 47 // limit parameter is either a number of bookmarks or 'all' for everything.
58 $limit = $request->getParam('limit'); 48 $limit = $request->getParam('limit');
@@ -61,23 +51,33 @@ class Links extends ApiController
61 } elseif (ctype_digit($limit)) { 51 } elseif (ctype_digit($limit)) {
62 $limit = intval($limit); 52 $limit = intval($limit);
63 } elseif ($limit === 'all') { 53 } elseif ($limit === 'all') {
64 $limit = count($bookmarks); 54 $limit = null;
65 } else { 55 } else {
66 throw new ApiBadParametersException('Invalid limit'); 56 throw new ApiBadParametersException('Invalid limit');
67 } 57 }
68 58
59 $searchResult = $this->bookmarkService->search(
60 [
61 'searchtags' => $request->getParam('searchtags', ''),
62 'searchterm' => $request->getParam('searchterm', ''),
63 ],
64 $private,
65 false,
66 false,
67 false,
68 [
69 'limit' => $limit,
70 'offset' => $offset,
71 'allowOutOfBounds' => true,
72 ]
73 );
74
69 // 'environment' is set by Slim and encapsulate $_SERVER. 75 // 'environment' is set by Slim and encapsulate $_SERVER.
70 $indexUrl = index_url($this->ci['environment']); 76 $indexUrl = index_url($this->ci['environment']);
71 77
72 $out = []; 78 $out = [];
73 $index = 0; 79 foreach ($searchResult->getBookmarks() as $bookmark) {
74 foreach ($bookmarks as $bookmark) { 80 $out[] = ApiUtils::formatLink($bookmark, $indexUrl);
75 if (count($out) >= $limit) {
76 break;
77 }
78 if ($index++ >= $offset) {
79 $out[] = ApiUtils::formatLink($bookmark, $indexUrl);
80 }
81 } 81 }
82 82
83 return $response->withJson($out, 200, $this->jsonStyle); 83 return $response->withJson($out, 200, $this->jsonStyle);
diff --git a/application/api/controllers/Tags.php b/application/api/controllers/Tags.php
index e60e00a7..5a23f6db 100644
--- a/application/api/controllers/Tags.php
+++ b/application/api/controllers/Tags.php
@@ -122,12 +122,12 @@ class Tags extends ApiController
122 throw new ApiBadParametersException('New tag name is required in the request body'); 122 throw new ApiBadParametersException('New tag name is required in the request body');
123 } 123 }
124 124
125 $bookmarks = $this->bookmarkService->search( 125 $searchResult = $this->bookmarkService->search(
126 ['searchtags' => $args['tagName']], 126 ['searchtags' => $args['tagName']],
127 BookmarkFilter::$ALL, 127 BookmarkFilter::$ALL,
128 true 128 true
129 ); 129 );
130 foreach ($bookmarks as $bookmark) { 130 foreach ($searchResult->getBookmarks() as $bookmark) {
131 $bookmark->renameTag($args['tagName'], $data['name']); 131 $bookmark->renameTag($args['tagName'], $data['name']);
132 $this->bookmarkService->set($bookmark, false); 132 $this->bookmarkService->set($bookmark, false);
133 $this->history->updateLink($bookmark); 133 $this->history->updateLink($bookmark);
@@ -157,12 +157,12 @@ class Tags extends ApiController
157 throw new ApiTagNotFoundException(); 157 throw new ApiTagNotFoundException();
158 } 158 }
159 159
160 $bookmarks = $this->bookmarkService->search( 160 $searchResult = $this->bookmarkService->search(
161 ['searchtags' => $args['tagName']], 161 ['searchtags' => $args['tagName']],
162 BookmarkFilter::$ALL, 162 BookmarkFilter::$ALL,
163 true 163 true
164 ); 164 );
165 foreach ($bookmarks as $bookmark) { 165 foreach ($searchResult->getBookmarks() as $bookmark) {
166 $bookmark->deleteTag($args['tagName']); 166 $bookmark->deleteTag($args['tagName']);
167 $this->bookmarkService->set($bookmark, false); 167 $this->bookmarkService->set($bookmark, false);
168 $this->history->updateLink($bookmark); 168 $this->history->updateLink($bookmark);