transfer booking owner

This commit is contained in:
edmondlang
2023-02-07 00:48:20 +08:00
parent 8743efd33a
commit f4cc6113a7
6 changed files with 201 additions and 0 deletions
@@ -0,0 +1,87 @@
<?php
namespace App\Classes\Modules\Bookings\ControllersLogic;
use App\Http\Resources\BookingResource;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Bookings\Services\FetchesBooking;
use App\Classes\Modules\Bookings\Standards\Rules\CanUpdateBooking;
use App\Classes\Modules\Bookings\Services\UpdatesBookingOwner;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Classes\Modules\Bookings\Standards\Rules\CanFetchBooking;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Models\Company;
class UpdateBookingOwnerLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification(): array
{
return [
'title' => 'Update Booking Owner',
'message' => "You have successfully updated booking's owner"
];
}
/** @var CanUpdateBooking */
private $canUpdateBooking;
/** @var UpdatesBookingOwner */
private $updatesBookingOwner;
/** @var FetchesBooking */
private $fetchesBooking;
/** @var CanFetchBooking */
private $canFetchBooking;
/** @var FetchesCompany */
private $fetchesCompany;
/**
* UpdateBookingLogic constructor.
* @param CanUpdateBooking $canUpdateBooking
* @param UpdatesBookingOwner $updatesBookingOwner
* @param CanFetchBooking $canFetchBooking
* @param FetchesBooking $fetchesBooking
* @param FetchesCompany $fetchesCompany
*/
public function __construct(
CanUpdateBooking $canUpdateBooking,
UpdatesBookingOwner $updatesBookingOwner,
CanFetchBooking $canFetchBooking,
FetchesBooking $fetchesBooking,
FetchesCompany $fetchesCompany
) {
$this->canUpdateBooking = $canUpdateBooking;
$this->updatesBookingOwner = $updatesBookingOwner;
$this->canFetchBooking = $canFetchBooking;
$this->fetchesBooking = $fetchesBooking;
$this->fetchesCompany = $fetchesCompany;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request): JsonResponse
{
$this->canFetchBooking->passes();
$booking = $this->fetchesBooking->execute([
'id' => $request->route('id'),
]);
$newCompanyId = Company::where('reference', $request->input('newMarking'))->first()->id;
$this->updatesBookingOwner->execute($booking, $newCompanyId);
return $this->resourceResponse(new BookingResource($booking));
}
}
@@ -0,0 +1,22 @@
<?php
namespace App\Classes\Modules\Bookings\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Models\Booking;
class UpdatesBookingOwner extends AbstractUpdateRecord
{
/**
* @param Booking $model
* @param int $id
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Booking $model, int $id)
{
$model->company_id = $id;
return $this->handler($model);
}
}