Skip to content

Commit

Permalink
move method call from action to task
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Oct 1, 2021
1 parent e5caab6 commit d27b4ea
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

namespace App\Containers\AppSection\Authorization\Actions;

use Apiato\Core\Exceptions\CoreInternalErrorException;
use App\Containers\AppSection\Authorization\Tasks\GetAllPermissionsTask;
use App\Containers\AppSection\Authorization\UI\API\Requests\GetAllPermissionsRequest;
use App\Ship\Parents\Actions\Action;
use Prettus\Repository\Exceptions\RepositoryException;

class GetAllPermissionsAction extends Action
{
/**
* @throws CoreInternalErrorException
* @throws RepositoryException
*/
public function run(GetAllPermissionsRequest $request)
{
return app(GetAllPermissionsTask::class)->addRequestCriteria()->run();
return app(GetAllPermissionsTask::class)->run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

namespace App\Containers\AppSection\Authorization\Actions;

use Apiato\Core\Exceptions\CoreInternalErrorException;
use App\Containers\AppSection\Authorization\Tasks\GetAllRolesTask;
use App\Containers\AppSection\Authorization\UI\API\Requests\GetAllRolesRequest;
use App\Ship\Parents\Actions\Action;
use Prettus\Repository\Exceptions\RepositoryException;

class GetAllRolesAction extends Action
{
/**
* @throws CoreInternalErrorException
* @throws RepositoryException
*/
public function run(GetAllRolesRequest $request)
{
return app(GetAllRolesTask::class)->addRequestCriteria()->run();
return app(GetAllRolesTask::class)->run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace App\Containers\AppSection\Authorization\Tasks;

use Apiato\Core\Exceptions\CoreInternalErrorException;
use App\Containers\AppSection\Authorization\Data\Repositories\PermissionRepository;
use App\Ship\Parents\Tasks\Task;
use Prettus\Repository\Exceptions\RepositoryException;

class GetAllPermissionsTask extends Task
{
Expand All @@ -12,8 +14,14 @@ public function __construct(
) {
}

/**
* @throws CoreInternalErrorException
* @throws RepositoryException
*/
public function run(bool $skipPagination = false): mixed
{
return $skipPagination ? $this->repository->all() : $this->repository->paginate();
$repository = $this->addRequestCriteria()->repository;

return $skipPagination ? $repository->all() : $repository->paginate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace App\Containers\AppSection\Authorization\Tasks;

use Apiato\Core\Exceptions\CoreInternalErrorException;
use App\Containers\AppSection\Authorization\Data\Repositories\RoleRepository;
use App\Ship\Parents\Tasks\Task;
use Prettus\Repository\Exceptions\RepositoryException;

class GetAllRolesTask extends Task
{
Expand All @@ -12,8 +14,12 @@ public function __construct(
) {
}

/**
* @throws CoreInternalErrorException
* @throws RepositoryException
*/
public function run()
{
return $this->repository->paginate();
return $this->addRequestCriteria()->repository->paginate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ class GetAllUsersAction extends Action
*/
public function run()
{
return app(GetAllUsersTask::class)->addRequestCriteria()->run();
return app(GetAllUsersTask::class)->run();
}
}
8 changes: 7 additions & 1 deletion app/Containers/AppSection/User/Tasks/GetAllUsersTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace App\Containers\AppSection\User\Tasks;

use Apiato\Core\Exceptions\CoreInternalErrorException;
use App\Containers\AppSection\User\Data\Repositories\UserRepository;
use App\Ship\Parents\Tasks\Task;
use Prettus\Repository\Exceptions\RepositoryException;

class GetAllUsersTask extends Task
{
Expand All @@ -12,8 +14,12 @@ public function __construct(
) {
}

/**
* @throws CoreInternalErrorException
* @throws RepositoryException
*/
public function run()
{
return $this->repository->paginate();
return $this->addRequestCriteria()->repository->paginate();
}
}

0 comments on commit d27b4ea

Please sign in to comment.