Skip to content

Commit

Permalink
improve the way we get the information on the rapid controllers, inst…
Browse files Browse the repository at this point in the history
…ead of relaying on the id, we are based on the primary key
  • Loading branch information
kaioken committed Jun 13, 2019
1 parent 789cda6 commit 95d6ec5
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Contracts/Api/CrudBehaviorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ protected function processInput(array $request): array
return $request;
}

// TODO: Move it to its own class.
// TODO: Move it to its own class.

/**
* Given a process request return the records.
*
Expand Down Expand Up @@ -147,7 +148,6 @@ protected function processIndex()
$processedRequest = $this->processRequest($this->request);
$records = $this->getRecords($processedRequest);


//get the results and append its relationships
$results = $this->appendRelationshipsToResult($this->request, $records['results']);

Expand Down Expand Up @@ -177,7 +177,10 @@ protected function processIndex()
public function getById($id): Response
{
//find the info
$record = $this->model::findFirstOrFail($id);
$record = $this->model::findFirstOrFail([
'conditions' => $this->model->getPrimaryKey() . '= ?0',
'bind' => [$id]
]);

//get the results and append its relationships
$result = $this->appendRelationshipsToResult($this->request, $record);
Expand Down Expand Up @@ -222,7 +225,10 @@ protected function processCreate(Request $request): ModelInterface
*/
public function edit($id): Response
{
$record = $this->model::getByIdOrFail($id);
$record = $this->model::findFirstOrFail([
'conditions' => $this->model->getPrimaryKey() . '= ?0',
'bind' => [$id]
]);

//process the input
$result = $this->processEdit($this->request, $record);
Expand Down Expand Up @@ -256,7 +262,10 @@ protected function processEdit(Request $request, ModelInterface $record): ModelI
*/
public function delete($id): Response
{
$record = $this->model::getByIdOrFail($id);
$record = $this->model::findFirstOrFail([
'conditions' => $this->model->getPrimaryKey() . '= ?0',
'bind' => [$id]
]);

if ($this->softDelete == 1) {
$record->softDelete();
Expand Down

0 comments on commit 95d6ec5

Please sign in to comment.