Skip to content

Commit

Permalink
Merge pull request #55 from sfneal/dev
Browse files Browse the repository at this point in the history
Refactor `UserListQuery` to accept a name query string parameter
  • Loading branch information
sfneal committed Sep 7, 2021
2 parents 8cacb7f + 0983c96 commit 9da7636
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,7 @@ All notable changes to `users` will be documented in this file
# 1.3.1 - 2021-09-07
- bump min sfneal/models packages version to v2.8.1
- add assertions to `UserListQueryTest` now that issues with Sqlite concat & if statements has been resolved


# 1.4.0 - 2021-09-07
- refactor `UserListQuery` to accept a name query string as a parameter instead of a Request #43
15 changes: 6 additions & 9 deletions src/Queries/UserListQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@

namespace Sfneal\Users\Queries;

use Illuminate\Http\Request;
use Sfneal\Queries\Query;
use Sfneal\Users\Builders\UserBuilder;
use Sfneal\Users\Models\User;

class UserListQuery extends Query
{
// todo: refactor to use param instead of $request?
/**
* @var Request
* @var string Query string containing portions of a User's name
*/
private $request;
private $nameQuery;

/**
* TeamListQuery constructor.
*
* @param Request $request
* @param string $nameQuery
*/
public function __construct(Request $request)
public function __construct(string $nameQuery)
{
$this->request = $request;
$this->nameQuery = $nameQuery;
}

/**
Expand All @@ -44,7 +41,7 @@ protected function builder(): UserBuilder
public function execute(): array
{
return $this->builder()
->whereNameLike($this->request->input('q'))
->whereNameLike($this->nameQuery)
->whereActive()
->selectRawJson()
->countAndPaginate();
Expand Down
9 changes: 1 addition & 8 deletions tests/Feature/Queries/UserListQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
namespace Sfneal\Users\Tests\Feature\Queries;

use Sfneal\Queries\RandomModelAttributeQuery;
use Sfneal\Testing\Utils\Traits\CreateRequest;
use Sfneal\Users\Models\User;
use Sfneal\Users\Queries\UserListQuery;
use Sfneal\Users\Tests\TestCase;

class UserListQueryTest extends TestCase
{
use CreateRequest;

/**
* @var string
*/
Expand All @@ -33,11 +30,7 @@ public function setUp(): void
/** @test */
public function query_returns_results()
{
$request = $this->createRequest([], [
'q' => $this->userName,
]);

$result = (new UserListQuery($request))->execute();
$result = (new UserListQuery($this->userName))->execute();
$items = $result['items'];
$count = $result['total_count'];

Expand Down

0 comments on commit 9da7636

Please sign in to comment.