Files
exchange-2.0/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php
T
2021-10-07 21:15:29 +08:00

77 lines
2.3 KiB
PHP

<?php
namespace App\Classes\Modules\Wallets\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
use App\Classes\Modules\Wallets\Services\CreatesWallet;
use App\Classes\Modules\Wallets\Services\GeneratesWalletCode;
use App\Classes\Modules\Wallets\Standards\Rules\CanCreateCompanyWallet;
use App\Http\Resources\WalletResource;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class CreateWalletLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Created Company Wallet',
'message' => 'You have successfully created a company wallet'
];
}
/** @var CreatesWallet */
private $createsWallet;
/** @var GeneratesWalletCode */
private $generatesWalletCode;
/** @var CanCreateCompanyWallet */
private $canCreateCompanyWallet;
/** @var FetchesCompany */
private $fetchesCompany;
/**
* CreateWalletLogic constructor.
* @param CreatesWallet $createsWallet
* @param GeneratesWalletCode $generatesWalletCode
* @param CanCreateCompanyWallet $canCreateCompanyWallet
*/
public function __construct(CreatesWallet $createsWallet, GeneratesWalletCode $generatesWalletCode, CanCreateCompanyWallet $canCreateCompanyWallet, FetchesCompany $fetchesCompany)
{
$this->fetchesCompany = $fetchesCompany;
$this->createsWallet = $createsWallet;
$this->generatesWalletCode = $generatesWalletCode;
$this->canCreateCompanyWallet = $canCreateCompanyWallet;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
$object = new WalletObject($request->input('company_id'), $request->input('currency_id'), $this->generatesWalletCode->execute());
$this->canCreateCompanyWallet->passes($object);
$company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]);
$wallet = $this->createsWallet->execute($object, $company);
return $this->resourceResponse(new WalletResource($wallet));
}
}