Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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 <igor.vorobioff@gmail.com>
*/
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
You can’t perform that action at this time.