Created
May 9, 2016 21:15
-
-
Save ivorobioff/3325a8e571feddc9d8f8d6a5d4aad62d to your computer and use it in GitHub Desktop.
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
<?php | |
namespace XXX\Api\Appraiser\V2_0\Controllers; | |
use XXX\Libraries\Kangaroo\Pagination\Paginator; | |
use Illuminate\Http\Response; | |
use XXX\Api\Appraisal\V2_0\Controllers\AbstractOrdersController; | |
use XXX\Api\Appraiser\V2_0\Processors\ConditionsProcessor; | |
use XXX\Api\Appraiser\V2_0\Processors\OrderDeclineProcessor; | |
use XXX\Api\Appraiser\V2_0\Processors\OrdersSearchableProcessor; | |
use XXX\Api\Appraisal\V2_0\Transformers\OrderTransformer; | |
use XXX\Api\Appraiser\V2_0\Transformers\TotalsTransformer; | |
use XXX\Api\Customer\V2_0\Transformers\AdditionalStatusTransformer; | |
use XXX\Api\Support\DefaultPaginatorAdapter; | |
use XXX\Core\Appraisal\Options\FetchOrdersOptions; | |
use XXX\Core\Appraiser\Services\AppraiserService; | |
use XXX\Core\Shared\Options\PaginationOptions; | |
/** | |
* @author Igor Vorobiov <[email protected]> | |
*/ | |
class OrdersController extends AbstractOrdersController | |
{ | |
/** | |
* @param int $appraiserId | |
* @param OrdersSearchableProcessor $processor | |
* @return Response | |
*/ | |
public function index($appraiserId, OrdersSearchableProcessor $processor) | |
{ | |
$adapter = new DefaultPaginatorAdapter([ | |
'getAll' => function($page, $perPage) use ($appraiserId, $processor){ | |
$options = new FetchOrdersOptions(); | |
$options->setPagination(new PaginationOptions($page, $perPage)); | |
$options->setCriteria($processor->createCriteria()); | |
$options->setSortables($processor->createSortables()); | |
return $this->orderService->getAllByAppraiserId($appraiserId, $options); | |
}, | |
'getTotal' => function() use ($appraiserId, $processor){ | |
return $this->orderService->getTotalByAppraiserId($appraiserId, $processor->createCriteria()); | |
} | |
]); | |
return $this->resource->makeAll( | |
new Paginator($adapter), | |
$this->transformer(OrderTransformer::class) | |
); | |
} | |
/** | |
* @param int $appraiserId | |
* @param int $orderId | |
* @return Response | |
*/ | |
public function show($appraiserId, $orderId) | |
{ | |
return $this->resource->make( | |
$this->orderService->get($orderId), | |
$this->transformer(OrderTransformer::class) | |
); | |
} | |
/** | |
* @param int $appraiserId | |
* @param int $orderId | |
* @return Response | |
*/ | |
public function accept($appraiserId, $orderId) | |
{ | |
$this->orderService->accept($orderId); | |
return $this->resource->blank(); | |
} | |
/** | |
* @param int $appraiserId | |
* @param int $orderId | |
* @param ConditionsProcessor $processor | |
* @return Response | |
*/ | |
public function acceptWithConditions($appraiserId, $orderId, ConditionsProcessor $processor) | |
{ | |
$this->orderService->acceptWithConditions($orderId, $processor->createConditions()); | |
return $this->resource->blank(); | |
} | |
/** | |
* @param int $appraiserId | |
* @param int $orderId | |
* @param OrderDeclineProcessor $processor | |
* @return Response | |
*/ | |
public function decline($appraiserId, $orderId, OrderDeclineProcessor $processor) | |
{ | |
$this->orderService->decline( | |
$orderId, | |
$processor->getDeclineReason(), | |
$processor->getDeclineMessage() | |
); | |
return $this->resource->blank(); | |
} | |
/** | |
* @param int $appraiserId | |
* @return Response | |
*/ | |
public function totals($appraiserId) | |
{ | |
return $this->resource->make([ | |
'paid' => $this->orderService->getPaidTotalsByAppraiserId($appraiserId), | |
'unpaid' => $this->orderService->getUnpaidTotalsByAppraiserId($appraiserId) | |
], $this->transformer(TotalsTransformer::class)); | |
} | |
/** | |
* @param int $appraiserId | |
* @param int $orderId | |
* @return Response | |
*/ | |
public function pay($appraiserId, $orderId) | |
{ | |
$this->orderService->payTechFee($orderId); | |
return $this->resource->blank(); | |
} | |
/** | |
* @param int $appraiserId | |
* @param int $orderId | |
* @return Response | |
*/ | |
public function listAdditionalStatuses($appraiserId, $orderId) | |
{ | |
return $this->resource->makeAll( | |
$this->orderService->getAllActiveAdditionalStatuses($orderId), | |
$this->transformer(AdditionalStatusTransformer::class) | |
); | |
} | |
/** | |
* @param AppraiserService $appraiserService | |
* @param int $appraiserId | |
* @param int $orderId | |
* @return bool | |
*/ | |
public static function verifyAction( | |
AppraiserService $appraiserService, | |
$appraiserId, | |
$orderId = null | |
) | |
{ | |
if (!$appraiserService->exists($appraiserId)){ | |
return false; | |
} | |
if ($orderId === null){ | |
return true; | |
} | |
return $appraiserService->hasOrder($appraiserId, $orderId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment