Files
exchange-2.0/app/Classes/Modules/Documents/ControllerLogic/ListDocumentLogic.php
T
CheeSiong 98b354d6b2 document
2020-11-18 10:37:03 +08:00

82 lines
2.1 KiB
PHP

<?php
namespace App\Classes\Modules\Documents\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Documents\Services\ListsDocuments;
use App\Classes\Modules\Documents\Standards\Rules\CanListDocuments;
use App\Http\Resources\DocumentResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ListDocumentLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Retrieved Document',
'message' => 'You have successfully retrieved a list of Document'
];
}
/** @var CanListDocuments */
private $canListDocuments;
/** @var ListsDocuments */
private $listsDocuments;
/**
* ListStandardSegmentLogic constructor.
* @param CanListDocuments $canListDocuments
* @param ListsDocuments $listsDocuments
*/
public function __construct(CanListDocuments $canListDocuments, ListsDocuments $listsDocuments)
{
$this->canListDocuments = $canListDocuments;
$this->listsDocuments = $listsDocuments;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
try {
$document_type = $request->input('document_type');
$reference = $request->input('reference');
$status = $request->input('status');
$data = [];
if ($document_type) {
$data['document_type'] = $document_type;
}
if ($reference) {
$data['reference'] = $reference;
}
if ($status) {
$data['status'] = $status;
}
$this->canListDocuments->passes();
$query = $this->listsDocuments->execute($data);
return $this->collectionResponse(DocumentResource::collection($query));
} catch (\Exception $exception){
throw new ErrorException($exception->getMessage(), $exception->getCode());
}
}
}