mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Vouchers\ControllersLogic;
|
|
|
|
|
|
use App\Classes\Exceptions\MalformedRequestException;
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Vouchers\Processors\CreateVoucherProcessor;
|
|
use App\Models\User;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
class CreateVoucherLogic extends AbstractControllerLogic
|
|
{
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Create Voucher',
|
|
'message' => 'You have successfully created a voucher'
|
|
];
|
|
}
|
|
|
|
/** @var CreateVoucherProcessor */
|
|
private $createVoucherProcessor;
|
|
|
|
/**
|
|
* CreateVoucherLogic constructor.
|
|
* @param CreateVoucherProcessor $createVoucherProcessor
|
|
*/
|
|
public function __construct(CreateVoucherProcessor $createVoucherProcessor)
|
|
{
|
|
$this->createVoucherProcessor = $createVoucherProcessor;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws MalformedRequestException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
$user = User::where('id', $request->input('userId'))->first();
|
|
$result = $this->createVoucherProcessor->execute($user, $request->input('voucherCode'), null);
|
|
return $this->response(['data' => $result]);
|
|
}
|
|
}
|