From 2e693067b807484f475c7d3bd0f649d62d568af5 Mon Sep 17 00:00:00 2001
From: Dane Everitt <dane@daneeveritt.com>
Date: Wed, 7 Feb 2018 21:33:44 -0600
Subject: [PATCH] Add search to API endpoints

---
 CHANGELOG.md                                                   | 3 +++
 .../Api/Application/Locations/LocationController.php           | 2 +-
 app/Http/Controllers/Api/Application/Nodes/NodeController.php  | 2 +-
 app/Http/Controllers/Api/Application/Users/UserController.php  | 2 +-
 4 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3db9e642d..e16dd62b5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,9 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
 * `[rc.2]` — Fixes bad API behavior on `/user` routes.
 * `[rc.2]` — Fixes Admin CP user editing resetting a password on users unintentionally.
 
+### Added
+* Added ability to search the following API endpoints: list users, list servers, and list locations.
+
 ## v0.7.0-rc.2 (Derelict Dermodactylus)
 ### Fixed
 * `[rc.1]` — Fixes exception thrown when revoking user sessions.
diff --git a/app/Http/Controllers/Api/Application/Locations/LocationController.php b/app/Http/Controllers/Api/Application/Locations/LocationController.php
index 42bb2a08c..6520b5918 100644
--- a/app/Http/Controllers/Api/Application/Locations/LocationController.php
+++ b/app/Http/Controllers/Api/Application/Locations/LocationController.php
@@ -67,7 +67,7 @@ class LocationController extends ApplicationApiController
      */
     public function index(GetLocationsRequest $request): array
     {
-        $locations = $this->repository->paginated(100);
+        $locations = $this->repository->setSearchTerm($request->input('search'))->paginated(50);
 
         return $this->fractal->collection($locations)
             ->transformWith($this->getTransformer(LocationTransformer::class))
diff --git a/app/Http/Controllers/Api/Application/Nodes/NodeController.php b/app/Http/Controllers/Api/Application/Nodes/NodeController.php
index 2e1c76a5c..e9f679006 100644
--- a/app/Http/Controllers/Api/Application/Nodes/NodeController.php
+++ b/app/Http/Controllers/Api/Application/Nodes/NodeController.php
@@ -69,7 +69,7 @@ class NodeController extends ApplicationApiController
      */
     public function index(GetNodesRequest $request): array
     {
-        $nodes = $this->repository->paginated(50);
+        $nodes = $this->repository->setSearchTerm($request->input('search'))->paginated(50);
 
         return $this->fractal->collection($nodes)
             ->transformWith($this->getTransformer(NodeTransformer::class))
diff --git a/app/Http/Controllers/Api/Application/Users/UserController.php b/app/Http/Controllers/Api/Application/Users/UserController.php
index 316fc1c68..d845c9441 100644
--- a/app/Http/Controllers/Api/Application/Users/UserController.php
+++ b/app/Http/Controllers/Api/Application/Users/UserController.php
@@ -70,7 +70,7 @@ class UserController extends ApplicationApiController
      */
     public function index(GetUsersRequest $request): array
     {
-        $users = $this->repository->paginated(100);
+        $users = $this->repository->setSearchTerm($request->input('search'))->paginated(50);
 
         return $this->fractal->collection($users)
             ->transformWith($this->getTransformer(UserTransformer::class))