Files
izyim/app/Classes/Modules/FreightForwarder/Services/ListsCustomerRelation.php
2019-07-23 14:54:38 +08:00

53 lines
1.4 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: mhmj
* Date: 23/07/2019
* Time: 10:40 AM
*/
namespace App\Classes\Modules\FreightForwarder\Services;
use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException;
use App\Classes\Modules\FreightForwarder\DataTransferObjects\CustomerRelationObject;
use App\Models\CustomerRelation;
class ListsCustomerRelation
{
/** @var CustomerRelation */
private $repository;
/**
* ListsCustomerRelation constructor.
* @param CustomerRelation $repository
*/
public function __construct(CustomerRelation $repository)
{
$this->repository = $repository;
}
/**
* @param int $forwarderId
* @param int $companyId
* @return CustomerRelationObject
* @throws InternalServerErrorException
*/
public function execute(int $forwarderId, int $companyId): CustomerRelationObject {
try{
$repository = $this->repository->where('forwarder_id', $forwarderId)->where('company_id',$companyId)->first();
/** @var CustomerRelationObject $customerRelationObject */
$customerRelationObject = new CustomerRelationObject($forwarderId, $companyId, $repository->customer_rate, $repository->wave);
return $customerRelationObject;
}catch (\Exception $exception){
throw new InternalServerErrorException("Failed to retrieve Customer Relation because{$exception->getMessage()}");
}
}
}