mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Affiliate\ControllersLogic;
|
|
|
|
use App\Classes\Modules\Affiliate\Services\CreatesAffiliate;
|
|
use App\Classes\Modules\Affiliate\DataTransferObjects\AffiliateObject;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CreateAffiliateLogic
|
|
{
|
|
/** @var CreatesAffiliate */
|
|
private $createsAffiliate;
|
|
|
|
/**
|
|
* @param CreatesAffiliate $createsAffiliate
|
|
*/
|
|
public function __construct(CreatesAffiliate $createsAffiliate)
|
|
{
|
|
$this->createsAffiliate = $createsAffiliate;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
*/
|
|
public function execute(Request $request): JsonResponse
|
|
{
|
|
$code = $request->input('code');
|
|
$code = $code !== null ? (string) $code : '';
|
|
|
|
$isActive = $request->input('is_active', true);
|
|
// Convert string 'true'/'false' to boolean if needed
|
|
if (is_string($isActive)) {
|
|
$isActive = filter_var($isActive, FILTER_VALIDATE_BOOLEAN);
|
|
}
|
|
$isActive = (bool) $isActive;
|
|
|
|
$object = new AffiliateObject(
|
|
$code,
|
|
$request->input('campaign_name'),
|
|
$request->input('campaign_description'),
|
|
$isActive
|
|
);
|
|
|
|
$affiliate = $this->createsAffiliate->execute($object);
|
|
|
|
return response()->json([
|
|
'message' => 'Affiliate code created successfully',
|
|
'data' => $affiliate
|
|
]);
|
|
}
|
|
}
|
|
|