-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
copying controller actions to the LumenJSONAPIController #105
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,17 @@ | |
use Laravel\Lumen\Application; | ||
use Laravel\Lumen\Routing\Controller; | ||
|
||
use Illuminate\Container\Container; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Http\Request; | ||
use NilPortugues\Api\JsonApi\Http\Factory\RequestFactory; | ||
use NilPortugues\Api\JsonApi\Http\Response\ResourceNotFound; | ||
use NilPortugues\Laravel5\JsonApi\Actions\CreateResource; | ||
use NilPortugues\Laravel5\JsonApi\Actions\DeleteResource; | ||
use NilPortugues\Laravel5\JsonApi\Actions\GetResource; | ||
use NilPortugues\Laravel5\JsonApi\Actions\ListResource; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* Class LumenJsonApiController. | ||
*/ | ||
|
@@ -39,4 +50,116 @@ protected function uriGenerator($controllerAction) | |
} | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Get many resources. | ||
* | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
public function index() | ||
{ | ||
$apiRequest = RequestFactory::create(); | ||
|
||
$page = $apiRequest->getPage(); | ||
if (!$page->size()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected 8 spaces, found 9 |
||
$page->setSize($this->pageSize); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected 12 spaces, found 9 |
||
|
||
$fields = $apiRequest->getFields(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
$sorting = $apiRequest->getSort(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
$included = $apiRequest->getIncludedRelationships(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
$filters = $apiRequest->getFilters(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
|
||
$resource = new ListResource($this->serializer, $page, $fields, $sorting, $included, $filters); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
|
||
$totalAmount = $this->totalAmountResourceCallable(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
$results = $this->listResourceCallable(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
|
||
$controllerAction = '\\'.get_called_class().'@index'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
$uri = $this->uriGenerator($controllerAction); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
|
||
return $this->addHeaders($resource->get($totalAmount, $results, $uri, get_class($this->getDataModel()))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected 8 spaces, found 5 |
||
|
||
/** | ||
* Get single resource. | ||
* | ||
* @param $id | ||
* | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
public function show($id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected 8 spaces, found 5 |
||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 8 spaces, found 5 |
||
$apiRequest = RequestFactory::create(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
|
||
$resource = new GetResource( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
$this->serializer, | ||
$apiRequest->getFields(), | ||
$apiRequest->getIncludedRelationships() | ||
); | ||
|
||
$find = $this->findResourceCallable($id); | ||
|
||
return $this->addHeaders($resource->get($id, get_class($this->getDataModel()), $find)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected 8 spaces, found 5 |
||
|
||
/** | ||
* @return ResourceNotFound | ||
*/ | ||
public function create() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected 8 spaces, found 5 |
||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 8 spaces, found 5 |
||
return new ResourceNotFound(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected 8 spaces, found 5 |
||
|
||
/** | ||
* Post Action. | ||
* | ||
* @param Request $request | ||
* | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
public function store(Request $request) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected 8 spaces, found 5 |
||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 8 spaces, found 5 |
||
$createResource = $this->createResourceCallable(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
$resource = new CreateResource($this->serializer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
return $this->addHeaders( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 12 spaces, found 9 |
||
$resource->get((array) $request->get('data'), get_class($this->getDataModel()), $createResource) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected 8 spaces, found 5 |
||
|
||
/** | ||
* @param $id | ||
* | ||
* @return Response | ||
*/ | ||
public function update(Request $request, $id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected 8 spaces, found 5 |
||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected at least 8 spaces, found 5 |
||
return (strtoupper($request->getMethod()) === 'PUT') ? $this->putAction($request, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$id) : $this->patchAction($request, $id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected 8 spaces, found 5 |
||
|
||
/** | ||
* @return ResourceNotFound | ||
*/ | ||
public function edit() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected 8 spaces, found 5 |
||
{ | ||
return new ResourceNotFound(); | ||
} | ||
|
||
/** | ||
* @param $id | ||
* | ||
* @return Response | ||
*/ | ||
public function destroy($id) | ||
{ | ||
$find = $this->findResourceCallable($id); | ||
|
||
$delete = $this->deleteResourceCallable($id); | ||
|
||
$resource = new DeleteResource($this->serializer); | ||
|
||
return $this->addHeaders($resource->get($id, get_class($this->getDataModel()), $find, $delete)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line indented incorrectly; expected 4 spaces, found 5