forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request laravel#49 from eurides-eu/feature/user-endpoints
Feature/user overview endpoint
- Loading branch information
Showing
13 changed files
with
265 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Organizations\Repositories\ReadRepository; | ||
use App\Organizations\Roles\Transformers\UserTransformer; | ||
use App\Users\Queries\FindUsersForOrganizationQuery; | ||
use App\Users\Repositories\UsersReadRepository; | ||
use Illuminate\Http\Request; | ||
|
||
class OrganizationUsersController extends ApiController | ||
{ | ||
/** | ||
* @var ReadRepository | ||
*/ | ||
private $organizationsReadRepository; | ||
|
||
/** | ||
* @var UsersReadRepository | ||
*/ | ||
private $usersReadRepository; | ||
|
||
/** | ||
* @param UserTransformer $userTransformer | ||
* @param ReadRepository $organizationsReadRepository | ||
* @param UsersReadRepository $usersReadRepository | ||
*/ | ||
public function __construct( | ||
UserTransformer $userTransformer, | ||
ReadRepository $organizationsReadRepository, | ||
UsersReadRepository $usersReadRepository | ||
) { | ||
$this->setTransformer($userTransformer); | ||
$this->organizationsReadRepository = $organizationsReadRepository; | ||
$this->usersReadRepository = $usersReadRepository; | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* @param string $organizationId | ||
* @param FindUsersForOrganizationQuery $query | ||
* | ||
* @return \Psr\Http\Message\ResponseInterface | ||
*/ | ||
public function all(Request $request, $organizationId, FindUsersForOrganizationQuery $query) | ||
{ | ||
$organization = $this->organizationsReadRepository->find($organizationId); | ||
|
||
if ($roleId = $request->get('roleId')) { | ||
$query->filterByRoleId($roleId); | ||
} | ||
|
||
$users = $query->find($organization); | ||
|
||
return $this->responsePaginator($users); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Users\Queries; | ||
|
||
use App\Models\Organization; | ||
use App\User; | ||
|
||
class FindUsersForOrganizationQuery | ||
{ | ||
/** | ||
* @var User | ||
*/ | ||
private $items; | ||
|
||
public function __construct() | ||
{ | ||
$this->items = User::query(); | ||
} | ||
|
||
/** | ||
* @param string $roleId | ||
*/ | ||
public function filterByRoleId(string $roleId) | ||
{ | ||
$this->items = $this->items->where('role_id', $roleId); | ||
} | ||
|
||
/** | ||
* @param Organization $organization | ||
* | ||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator | ||
*/ | ||
public function find(Organization $organization) | ||
{ | ||
return $this->items->where('organization_id', $organization->id)->paginate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Users\Repositories; | ||
|
||
use App\Entities\Repositories\EloquentRepository; | ||
use App\User; | ||
|
||
class UsersReadRepository extends EloquentRepository | ||
{ | ||
/** | ||
* @param User $items | ||
*/ | ||
public function __construct(User $items) | ||
{ | ||
parent::__construct($items); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace App\Organizations\Roles\Transformers; | ||
|
||
use App\User; | ||
use League\Fractal\TransformerAbstract; | ||
|
||
class UserTransformer extends TransformerAbstract | ||
{ | ||
/** | ||
* List of resources possible to include. | ||
* | ||
* @var array | ||
*/ | ||
protected $defaultIncludes = [ | ||
'role', | ||
]; | ||
|
||
/** | ||
* @param User $user | ||
* | ||
* @return array | ||
*/ | ||
public function transform(User $user) | ||
{ | ||
return [ | ||
'id' => $user->id, | ||
'first_name' => $user->first_name, | ||
'last_name' => $user->last_name, | ||
'email' => $user->email, | ||
'language' => $user->language, | ||
'gender' => $user->gender, | ||
'birthDate' => $user->birthdate, | ||
'addressStreet' => $user->address_street, | ||
'addressNumber' => $user->address_number, | ||
'addressBox' => $user->address_box, | ||
'addressPostalCode' => $user->address_postal_code, | ||
'addressCity' => $user->address_city, | ||
'addressCountryCode' => $user->address_country_code, | ||
]; | ||
} | ||
|
||
/** | ||
* @param User $user | ||
* | ||
* @return \League\Fractal\Resource\Item | ||
*/ | ||
public function includeRole(User $user) | ||
{ | ||
return $this->item($user->role, new OrganizationRoleTransformer()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.