Skip to content

Commit

Permalink
Merge branch 'master' into 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhall17 committed May 29, 2020
2 parents 91549ea + 31ceaec commit c5f48a2
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 73 deletions.
172 changes: 142 additions & 30 deletions src/Support/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ protected function getApiDataField()
return $this->resource->getApiDataField();
}

public function find($id, $column="")
public function find($id, $column="")
{
if(is_array($id)){
return $this->whereIn($id, $column)->get(null, $raw);
Expand All @@ -180,27 +180,27 @@ public function find($id, $column="")
]), "individual", "allow");
}

public function findMany(array $id, $column="")
public function findMany(array $id, $column="")
{
return $this->whereIn($id, $column)->get();
}

public function findOrFail($id)
public function findOrFail($id)
{
return $this->handleResponse($this->sendRequest('get', [
$this->retreiveEndPoint('get').'/'.$id
]), "individual", "error");
}

public function firstOrFail()
public function firstOrFail()
{
if(!is_null($model = $this->first())){
return $model;
}
throw (new ModelNotFoundException)->setModel(get_class($this->resource));
}

protected function processHeaders()
protected function processHeaders()
{
if($this->asForm){
$this->request->asForm();
Expand All @@ -210,7 +210,7 @@ protected function processHeaders()
}
}

protected function processFiles()
protected function processFiles()
{
if($this->files != []){
foreach($this->files as $key => $file){
Expand Down Expand Up @@ -238,7 +238,7 @@ public function handleResponse($response, $type="individual", $ifEmpty="default"
}
}

public function handleRaw($response)
public function handleRaw($response)
{
if(!$this->throwExceptionsIfRaw){
return $response;
Expand All @@ -249,7 +249,7 @@ public function handleRaw($response)
}
}

public function handle404($response, $ifEmpty)
public function handle404($response, $ifEmpty)
{
if($ifEmpty == 'allow'){
return null;
Expand All @@ -260,7 +260,7 @@ public function handle404($response, $ifEmpty)
}
}

public function all()
public function all()
{
$this->setPerPageToMax();
if($this->resource->beforeQuery($this) === false){
Expand All @@ -270,7 +270,7 @@ public function all()
$this->retreiveEndPoint('get'),
$this->addPagination($this->combineQueries()),
]), 'all');

}

public function get()
Expand Down Expand Up @@ -304,7 +304,7 @@ public function post($attributes, $type="individual")
$this->retreiveEndPoint('post'),
$attributes,
$this->combineQueries()
]), $type);
]), $type.'Post');
}

public function patch($attributes, $type="individual")
Expand All @@ -316,7 +316,7 @@ public function patch($attributes, $type="individual")
$this->retreiveEndPoint('patch'),
$attributes,
$this->combineQueries()
]), $type);
]), $type.'Patch');
}

public function put($attributes, $type="individual")
Expand All @@ -328,18 +328,18 @@ public function put($attributes, $type="individual")
$this->retreiveEndPoint('put'),
$attributes,
$this->combineQueries()
]), $type);
]), $type.'Put');
}

public function delete($type="individual")
public function delete($type="individual")
{
if($this->resource->beforeDeleteQuery($this) === false){
return;
}
return $this->handleResponse($this->sendRequest('delete', [
$this->retreiveEndPoint('delete'),
$this->combineQueries()
]), $type);
]), $type.'Delete');
}

public function first()
Expand All @@ -364,12 +364,12 @@ public function addQuery($key, $value)
return $this;
}

public function whereRaw($column, $value)
public function whereRaw($column, $value)
{
$this->addQuery($column, $value);
return $this;
}

public function where($column, $operand = null, $value = null)
{
if(is_array($column)){
Expand Down Expand Up @@ -433,7 +433,7 @@ protected function addWhereContains($column, $operand, $value)
$this->wheres[] = ['column' => $column, 'operand' => $operand, 'value' => $value];
}

public function whereIn(array $values, $column="")
public function whereIn(array $values, $column="")
{
$string = implode(',', $values);
if($column == ''){
Expand All @@ -443,24 +443,24 @@ public function whereIn(array $values, $column="")
return $this;
}

public function orderBy($value, $column='order')
public function orderBy($value, $column='order')
{
$this->orders[$column] = $value;
return $this;
}

public function count()
public function count()
{
return $this->get()->count();
}

public function setPaginate($status=true)
public function setPaginate($status=true)
{
$this->paginate = $status;
return $this;
}

public function shouldPaginate()
public function shouldPaginate()
{
return $this->paginate;
}
Expand Down Expand Up @@ -519,13 +519,13 @@ public function setPage($page)
return $this;
}

public function raw($status=true)
public function raw($status=true)
{
$this->raw = $status;
return $this;
}

public function withExceptions($status=true)
public function withExceptions($status=true)
{
$this->throwExceptionsIfRaw = $status;
return $this;
Expand All @@ -536,7 +536,7 @@ public function isRaw()
return $this->raw;
}

protected function combineQueries()
protected function combineQueries()
{
return array_merge($this->processQueries(), $this->processOrders());
}
Expand All @@ -556,12 +556,12 @@ protected function processWheres()
return $this;
}

public function processWhereEquals($detail)
public function processWhereEquals($detail)
{
$this->processedWheres[$detail['column']] = $detail['value'];
}

public function processWhereNotEquals($detail)
public function processWhereNotEquals($detail)
{
$this->processedWheres[$detail['column']] = '-'.$detail['value'];
}
Expand Down Expand Up @@ -601,7 +601,7 @@ protected function processOrders()
return $this->orders;
}

public function addPagination($array)
public function addPagination($array)
{
if($this->perPage != ''){
$array[$this->perPageField] = $this->perPage;
Expand Down Expand Up @@ -647,7 +647,7 @@ public function resetOrders()
$this->orders = [];
return $this;
}

protected function processGetResponse($response)
{
return new ResultSet($this, $response, $this->resource);
Expand All @@ -672,9 +672,121 @@ protected function processIndividualResponse($response)
}
}

protected function processIndividualPostResponse($response)
{
if($this->getApiDataField() != null){
$data = $response->json()[$this->getApiDataField()];
} else {
$data = $response->json();
}
if(isset($data[0])){
return $this->resource->updateFromBuilder($this->resource->passOnAttributes($data[0]));
} else {
return $this->resource->updateFromBuilder($this->resource->passOnAttributes($data));
}
}

protected function processMultiPostResponse($response)
{
// if($this->getApiDataField() != null){
// $data = $response->json()[$this->getApiDataField()];
// } else {
// $data = $response->json();
// }
// if(isset($data[0])){
// return $this->resource->newFromBuilder($this->resource->passOnAttributes($data[0]));
// } else {
// return $this->resource->newFromBuilder($this->resource->passOnAttributes($data));
// }
}

protected function processIndividualPatchResponse($response)
{
if($this->getApiDataField() != null){
$data = $response->json()[$this->getApiDataField()];
} else {
$data = $response->json();
}
if(isset($data[0])){
return $this->resource->updateFromBuilder($this->resource->passOnAttributes($data[0]));
} else {
return $this->resource->updateFromBuilder($this->resource->passOnAttributes($data));
}
}

protected function processMultiPatchResponse($response)
{
// if($this->getApiDataField() != null){
// $data = $response->json()[$this->getApiDataField()];
// } else {
// $data = $response->json();
// }
// if(isset($data[0])){
// return $this->resource->newFromBuilder($this->resource->passOnAttributes($data[0]));
// } else {
// return $this->resource->newFromBuilder($this->resource->passOnAttributes($data));
// }
}

protected function processIndividualPutResponse($response)
{
if($this->getApiDataField() != null){
$data = $response->json()[$this->getApiDataField()];
} else {
$data = $response->json();
}
if(isset($data[0])){
return $this->resource->updateFromBuilder($this->resource->passOnAttributes($data[0]));
} else {
return $this->resource->updateFromBuilder($this->resource->passOnAttributes($data));
}
}

protected function processMultiPutResponse($response)
{
// if($this->getApiDataField() != null){
// $data = $response->json()[$this->getApiDataField()];
// } else {
// $data = $response->json();
// }
// if(isset($data[0])){
// return $this->resource->newFromBuilder($this->resource->passOnAttributes($data[0]));
// } else {
// return $this->resource->newFromBuilder($this->resource->passOnAttributes($data));
// }
}

protected function processIndividualDeleteResponse($response)
{
if($this->getApiDataField() != null){
$data = $response->json()[$this->getApiDataField()];
} else {
$data = $response->json();
}
if(isset($data[0])){
return $this->resource->updateFromBuilder($this->resource->passOnAttributes($data[0]));
} else {
return $this->resource->updateFromBuilder($this->resource->passOnAttributes($data));
}
}

protected function processMultiDeleteResponse($response)
{
// if($this->getApiDataField() != null){
// $data = $response->json()[$this->getApiDataField()];
// } else {
// $data = $response->json();
// }
// if(isset($data[0])){
// return $this->resource->newFromBuilder($this->resource->passOnAttributes($data[0]));
// } else {
// return $this->resource->newFromBuilder($this->resource->passOnAttributes($data));
// }
}

public function prepareHttpErrorMessage($response)
{
return $response->json()['message'];
}

}
}
Loading

0 comments on commit c5f48a2

Please sign in to comment.