mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
Create Booking Logic Class
Update Booking Logic Class Delete Booking Logic Class
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Bookings\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Classes\Modules\CompanyBanks\Services\FetchesCompanyBank;
|
||||
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
|
||||
|
||||
use App\Classes\Modules\Bookings\Standards\Rules\CanCreateBooking;
|
||||
use App\Classes\Modules\Bookings\Services\CreatesBooking;
|
||||
use App\Classes\Modules\Bookings\Services\GeneratesBookingMarking;
|
||||
|
||||
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
|
||||
use App\Http\Resources\BookingResource;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CreateBookingLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Created Booking',
|
||||
'message' => 'You have successfully created a new Booking'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanCreateBooking */
|
||||
private $canCreateBooking;
|
||||
|
||||
/** @var CreatesBooking */
|
||||
private $createsBooking;
|
||||
|
||||
/** @var GeneratesBookingMarking */
|
||||
private $generatesBookingMarking;
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
|
||||
/** @var FetchesCompanyBank */
|
||||
private $fetchesCompanyBank;
|
||||
|
||||
/** @var FetchesCurrency */
|
||||
private $fetchesCurrency;
|
||||
|
||||
/**
|
||||
* CreateSegmentLogic constructor.
|
||||
* @param CanCreateBooking $canCreateBooking
|
||||
* @param CreatesBooking $createsBooking
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param FetchesCompanyBank $fetchesCompanyBank
|
||||
* @param FetchesCurrency $fetchesCurrency
|
||||
*/
|
||||
public function __construct(
|
||||
CanCreateBooking $canCreateBooking,
|
||||
CreatesBooking $createsBooking,
|
||||
GeneratesBookingMarking $generatesBookingMarking,
|
||||
FetchesCompany $fetchesCompany,
|
||||
FetchesCompanyBank $fetchesCompanyBank,
|
||||
FetchesCurrency $fetchesCurrency
|
||||
)
|
||||
{
|
||||
$this->canCreateBooking = $canCreateBooking;
|
||||
$this->createsBooking = $createsBooking;
|
||||
$this->generatesBookingMarking = $generatesBookingMarking;
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->fetchesCompanyBank = $fetchesCompanyBank;
|
||||
$this->fetchesCurrency = $fetchesCurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$booking_object = new BookingObject(
|
||||
$request->input('company_id'),
|
||||
$request->input('transferable_bank_id'),
|
||||
$this->generatesBookingMarking->execute(),
|
||||
$request->input('reference'),
|
||||
number_format( (float) $request->input('fix_amount'), 5, '.', ''),
|
||||
$request->input('fix_currency_id'),
|
||||
$request->input('convertible_currency_id'),
|
||||
$request->input('conversion_currency_id')
|
||||
);
|
||||
$this->canCreateBooking->passes($booking_object);
|
||||
|
||||
$company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]);
|
||||
$transferable_bank = $this->fetchesCompanyBank->execute(['id' => $request->input('transferable_bank_id')]);
|
||||
$fix_currency = $this->fetchesCurrency->execute(['id' => $request->input('fix_currency_id')]);
|
||||
$convertible_currency = $this->fetchesCurrency->execute(['id' => $request->input('convertible_currency_id')]);
|
||||
$conversion_currency = $this->fetchesCurrency->execute(['id' => $request->input('conversion_currency_id')]);
|
||||
|
||||
$booking = $this->createsBooking->execute($booking_object);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $this->resourceResponse(new BookingResource($booking));
|
||||
|
||||
} catch (\Exception $exception) {
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?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\CanDeleteBooking;
|
||||
use App\Classes\Modules\Bookings\Services\DeletesBooking;
|
||||
use App\Classes\Modules\Bookings\DataTransferObjects\SegmentObject;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DeleteBookingLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Delete Booking',
|
||||
'message' => 'You have successfully deleted the Booking'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanDeleteBooking */
|
||||
private $canDeleteBooking;
|
||||
|
||||
/** @var DeletesBooking */
|
||||
private $deletesBooking;
|
||||
|
||||
/** @var FetchesBooking */
|
||||
private $fetchesBooking;
|
||||
|
||||
/**
|
||||
* UpdateStandardSegmentConstantLogic constructor.
|
||||
* @param CanUpdateSegment $canDeleteBooking
|
||||
* @param UpdatesSegment $deletesSegment
|
||||
* @param FetchesBooking $fetchesBooking
|
||||
*/
|
||||
public function __construct(
|
||||
CanDeleteBooking $canDeleteBooking,
|
||||
DeletesBooking $deletesBooking,
|
||||
FetchesBooking $fetchesBooking
|
||||
)
|
||||
{
|
||||
$this->canDeleteBooking = $canDeleteBooking;
|
||||
$this->deletesBooking = $deletesBooking;
|
||||
$this->fetchesBooking = $fetchesBooking;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$booking = $this->fetchesBooking->execute(['id' => $request->route('id')]);
|
||||
$this->canDeleteBooking->passes();
|
||||
$this->deletesBooking->execute($booking);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $this->resourceResponse(new BookingResource($booking));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?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\UpdatesBooking;
|
||||
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateBookingLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated Booking',
|
||||
'message' => 'You have successfully updated the Booking'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanUpdateBooking */
|
||||
private $canUpdateBooking;
|
||||
|
||||
/** @var UpdatesBookingRate */
|
||||
private $updatesBookingRate;
|
||||
|
||||
/** @var FetchesBooking */
|
||||
private $fetchesBooking;
|
||||
|
||||
/**
|
||||
* UpdateStandardSegmentConstantLogic constructor.
|
||||
* @param CanUpdateBooking $canUpdateBooking
|
||||
* @param UpdatesBooking $updatesBooking
|
||||
* @param FetchesBooking $fetchesBooking
|
||||
*/
|
||||
public function __construct(
|
||||
CanUpdateBooking $canUpdateBooking,
|
||||
UpdatesBooking $updatesBooking,
|
||||
FetchesBooking $fetchesBooking
|
||||
)
|
||||
{
|
||||
$this->canUpdateBooking = $canUpdateBooking;
|
||||
$this->updatesBooking = $updatesBooking;
|
||||
$this->fetchesBooking = $fetchesBooking;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$booking = $this->fetchesBooking->execute(['id' => $request->route('id')]);
|
||||
|
||||
$booking_object = new BookingObject(
|
||||
$booking->company_id,
|
||||
$request->input('transferable_bank_id', $booking->transferable_bank_id),
|
||||
$booking->marking,
|
||||
$request->input('reference', $booking->reference),
|
||||
$request->input('fix_amount', $booking->fix_amount),
|
||||
$request->input('fix_currency_id', $booking->fix_currency_id),
|
||||
$request->input('convertible_currency_id', $booking->convertible_currency_id),
|
||||
$request->input('conversion_currency_id', $booking->conversion_currency_id)
|
||||
);
|
||||
$this->canUpdateBooking->passes($booking_object);
|
||||
$booking = $this->updatesBooking->execute($booking, $booking_object);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $this->resourceResponse(new BookingResource($booking));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Bookings\DataTransferObjects;
|
||||
|
||||
use App\Classes\Interfaces\DataTransferObject;
|
||||
|
||||
class BookingObject implements DataTransferObject
|
||||
{
|
||||
private $company_id;
|
||||
private $transferable_bank_id;
|
||||
private $marking;
|
||||
private $reference;
|
||||
private $fix_amount;
|
||||
private $fix_currency_id;
|
||||
private $convertible_currency_id;
|
||||
private $conversion_currency_id;
|
||||
/**
|
||||
* BookingObject constructor.
|
||||
* @param int|null $company_id
|
||||
* @param int|null $transferable_bank_id
|
||||
* @param string|null $marking
|
||||
* @param string|null $reference
|
||||
* @param float|null $fix_amount
|
||||
* @param int|null $fix_currency_id
|
||||
* @param int|null $convertible_currency_id
|
||||
* @param int|null $conversion_currency_id
|
||||
*/
|
||||
public function __construct(
|
||||
?int $company_id,
|
||||
?int $transferable_bank_id,
|
||||
?string $marking,
|
||||
?string $reference,
|
||||
?float $fix_amount,
|
||||
?int $fix_currency_id,
|
||||
?int $convertible_currency_id,
|
||||
?int $conversion_currency_id
|
||||
)
|
||||
{
|
||||
$this->company_id = $company_id;
|
||||
$this->transferable_bank_id = $transferable_bank_id;
|
||||
$this->marking = $marking;
|
||||
$this->reference = $reference;
|
||||
$this->fix_amount = $fix_amount;
|
||||
$this->fix_currency_id = $fix_currency_id;
|
||||
$this->convertible_currency_id = $convertible_currency_id;
|
||||
$this->conversion_currency_id = $conversion_currency_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCompanyId(): ?int
|
||||
{
|
||||
return $this->company_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTransferableBankId(): ?int
|
||||
{
|
||||
return $this->transferable_bank_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMarking(): ?string
|
||||
{
|
||||
return $this->marking;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getReference(): ?string
|
||||
{
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getFixAmount(): ?float
|
||||
{
|
||||
return $this->fix_amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getFixCurrencyId(): ?int
|
||||
{
|
||||
return $this->fix_currency_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getConvertibleCurrencyId(): ?int
|
||||
{
|
||||
return $this->convertible_currency_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getConversionCurrencyId(): ?int
|
||||
{
|
||||
return $this->conversion_currency_id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Bookings\Services;
|
||||
|
||||
|
||||
use App\Models\Booking;
|
||||
|
||||
class ChecksIfBookingMarkingExists
|
||||
{
|
||||
|
||||
/** @var Booking */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ChecksIfBookingMarkingExists constructor.
|
||||
* @param Booking $repository
|
||||
*/
|
||||
public function __construct(Booking $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function execute(int $marking): bool {
|
||||
return $this->repository->where('marking', $marking)->exists();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Bookings\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
|
||||
use App\Models\Booking;
|
||||
|
||||
class CreatesBooking extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param BookingObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(BookingObject $object) {
|
||||
$model = new Booking();
|
||||
$model->company_id = $object->getCompanyId();
|
||||
$model->transferable_bank_id = $object->getTransferableBankId();
|
||||
$model->marking = $object->getMarking();
|
||||
$model->reference = $object->getReference();
|
||||
$model->fix_amount = $object->getFixAmount();
|
||||
$model->fix_currency_id = $object->getFixCurrencyId();
|
||||
$model->convertible_currency_id = $object->getConvertibleCurrencyId();
|
||||
$model->conversion_currency_id = $object->getConversionCurrencyId();
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Bookings\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractDeleteRecord;
|
||||
use App\Models\Booking;
|
||||
|
||||
class DeletesBooking extends AbstractDeleteRecord
|
||||
{
|
||||
|
||||
public function execute(Booking $model) {
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Bookings\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Booking;
|
||||
|
||||
class FetchesBooking extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var Booking */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesUser constructor.
|
||||
* @param Booking $repository
|
||||
*/
|
||||
public function __construct(Booking $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Bookings\Services;
|
||||
|
||||
|
||||
class GeneratesBookingMarking
|
||||
{
|
||||
|
||||
/** @var ChecksIfBookingMarkingExists */
|
||||
private $bookingMarkingExists;
|
||||
|
||||
/**
|
||||
* GeneratesWalletCode constructor.
|
||||
* @param ChecksIfBookingMarkingExists $bookingMarkingExists
|
||||
*/
|
||||
public function __construct(ChecksIfBookingMarkingExists $bookingMarkingExists)
|
||||
{
|
||||
$this->bookingMarkingExists = $bookingMarkingExists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function execute(): int {
|
||||
|
||||
$marking = mt_rand(100000001, 999999999);
|
||||
return !$this->bookingMarkingExists->execute($marking) ? $marking : self::execute();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Bookings\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
|
||||
use App\Models\Booking;
|
||||
|
||||
class UpdatesBooking extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param BookingObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Booking $model, BookingObject $object)
|
||||
{
|
||||
$model->transferable_bank_id = $object->getTransferableBankId();
|
||||
$model->reference = $object->getReference();
|
||||
$model->fix_amount = $object->getFixAmount();
|
||||
$model->fix_currency_id = $object->getFixCurrencyId();
|
||||
$model->convertible_currency_id = $object->getConvertibleCurrencyId();
|
||||
$model->conversion_currency_id = $object->getConversionCurrencyId();
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Bookings\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Bookings\DataTransferObjects\SegmentObject;
|
||||
use App\Classes\Modules\Bookings\Standards\Validators\BookingValidation;
|
||||
|
||||
class CanCreateBooking extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var BookingValidation */
|
||||
private $bookingValidation;
|
||||
|
||||
/**
|
||||
* CanCreateBooking constructor.
|
||||
* @param BookingValidation $BookingValidation
|
||||
*/
|
||||
public function __construct(BookingValidation $bookingValidation)
|
||||
{
|
||||
$this->bookingValidation = $bookingValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
if (!\Auth::user()->can('add booking')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SegmentObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->bookingValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SegmentObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Bookings\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
|
||||
|
||||
class CanDeleteBooking extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
if (!\Auth::user()->can('delete booking')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BookingObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param BookingObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Bookings\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
|
||||
use App\Classes\Modules\Bookings\Standards\Validators\BookingValidation;
|
||||
|
||||
class CanUpdateBooking extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var BookingValidation */
|
||||
private $bookingValidation;
|
||||
|
||||
/**
|
||||
* CanCreateAddress constructor.
|
||||
* @param BookingValidation $BookingValidation
|
||||
*/
|
||||
public function __construct(BookingValidation $bookingValidation)
|
||||
{
|
||||
$this->bookingValidation = $bookingValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
if (!\Auth::user()->can('edit booking')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BookingValidation $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->bookingValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BookingValidation $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Bookings\Standards\Validators;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
|
||||
|
||||
class BookingValidation extends AbstractValidation
|
||||
{
|
||||
/**
|
||||
* @param BookingObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array
|
||||
{
|
||||
return [
|
||||
'company_id' => $object->getCompanyId(),
|
||||
'transferable_bank_id' => $object->getTransferableBankId(),
|
||||
'marking' => $object->getMarking(),
|
||||
'reference' => $object->getReference(),
|
||||
'fix_amount' => $object->getFixAmount(),
|
||||
'fix_currency_id' => $object->getFixCurrencyId(),
|
||||
'convertible_currency_id' => $object->getConvertibleCurrencyId(),
|
||||
'conversion_currency_id' => $object->getConversionCurrencyId(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'company_id' => 'required',
|
||||
'transferable_bank_id' => 'required',
|
||||
'marking' => 'required',
|
||||
'reference' => 'required',
|
||||
'fix_amount' => 'required',
|
||||
'fix_currency_id' => 'required',
|
||||
'convertible_currency_id' => 'required',
|
||||
'conversion_currency_id' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Company;
|
||||
|
||||
class FetchesCompany extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var Company */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesUser constructor.
|
||||
* @param Company $repository
|
||||
*/
|
||||
public function __construct(Company $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bookings;
|
||||
|
||||
use App\Classes\Modules\Bookings\ControllersLogic\CreateBookingLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateBookingController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param CreateBookingLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function create(Request $request, CreateBookingLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bookings;
|
||||
|
||||
use App\Classes\Modules\Bookings\ControllersLogic\DeleteBookingLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DeleteBookingController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param DeleteBookingLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function delete(Request $request, DeleteBookingLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bookings;
|
||||
|
||||
use App\Classes\Modules\Bookings\ControllersLogic\UpdateBookingLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateBookingController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param UpdateBookingLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(Request $request, UpdateBookingLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class BookingResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'company_id' => $this->company_id,
|
||||
'transferable_bank_id' => $this->transferable_bank_id,
|
||||
'marking' => $this->marking,
|
||||
'reference' => $this->reference,
|
||||
'fix_amount' => $this->fix_amount,
|
||||
'fix_currency_id' => $this->fix_currency_id,
|
||||
'convertible_currency_id' => $this->convertible_currency_id,
|
||||
'conversion_currency_id' => $this->conversion_currency_id,
|
||||
'status' => $this->status
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* Class Booking
|
||||
* @package App\Models
|
||||
* @version August 4, 2020, 4:36 am
|
||||
*
|
||||
* @property \App\Models\Company company_id
|
||||
* @property \App\Models\CompanyBank transferable_bank_id
|
||||
* @property string marking
|
||||
* @property string reference
|
||||
* @property float fix_amount
|
||||
* @property \App\Models\Currency convertible_currency_id
|
||||
* @property \App\Models\Currency conversion_currency_id
|
||||
*/
|
||||
class Booking extends AbstractModel
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'bookings';
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateBookingsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('bookings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->bigInteger('company_id')->unsigned()->nullable();
|
||||
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
|
||||
$table->bigInteger('transferable_bank_id')->unsigned()->nullable();
|
||||
$table->foreign('transferable_bank_id')->references('id')->on('company_banks')->onDelete('cascade');
|
||||
$table->string('marking');
|
||||
$table->string('reference');
|
||||
$table->float('fix_amount', 20, 5)->nullable();
|
||||
$table->bigInteger('fix_currency_id')->unsigned()->nullable();
|
||||
$table->foreign('fix_currency_id')->references('id')->on('currencies')->onDelete('cascade');
|
||||
$table->bigInteger('convertible_currency_id')->unsigned()->nullable();
|
||||
$table->foreign('convertible_currency_id')->references('id')->on('currencies')->onDelete('cascade');
|
||||
$table->bigInteger('conversion_currency_id')->unsigned()->nullable();
|
||||
$table->foreign('conversion_currency_id')->references('id')->on('currencies')->onDelete('cascade');
|
||||
$table->integer('status')->default(1);
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('bookings');
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,11 @@ class AdminUserPermissionsTableSeeder extends Seeder
|
||||
Permission::create(['name' => 'edit currency', 'guard_name' => 'web']);
|
||||
Permission::create(['name' => 'delete currency', 'guard_name' => 'web']);
|
||||
|
||||
Permission::create(['name' => 'view booking', 'guard_name' => 'web']);
|
||||
Permission::create(['name' => 'add booking', 'guard_name' => 'web']);
|
||||
Permission::create(['name' => 'edit booking', 'guard_name' => 'web']);
|
||||
Permission::create(['name' => 'delete booking', 'guard_name' => 'web']);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
$shadow_admin_role = Role::create([
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CompanyBanksTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
DB::table('company_banks')->insert([
|
||||
[
|
||||
'id' => 1,
|
||||
'country_id' => 1,
|
||||
'bank_name' => '12345678',
|
||||
'holder_name' => '12345678',
|
||||
'account_no' => '12345678',
|
||||
'type' => 1,
|
||||
'default' => 1,
|
||||
'status' => 1,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ class DatabaseSeeder extends Seeder
|
||||
$this->call(SegmentConstantsTableSeeder::class);
|
||||
|
||||
$this->call(CompaniesTableSeeder::class);
|
||||
$this->call(CompanyBanksTableSeeder::class);
|
||||
|
||||
// Admin
|
||||
$this->call(AdminUserTableSeeder::class);
|
||||
|
||||
+3
-1
@@ -24,7 +24,9 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function
|
||||
|
||||
require __DIR__ . '/segment.php';
|
||||
|
||||
require __DIR__ . '/company_bank.php';
|
||||
// require __DIR__ . '/company_bank.php';
|
||||
|
||||
require __DIR__ . '/booking.php';
|
||||
|
||||
Route::group(['middleware' => 'valid.token'], function () {
|
||||
require __DIR__ . '/crud.php';
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::group(['namespace' => 'Bookings'], function () {
|
||||
Route::group(['middleware' => 'valid.token'], function () {
|
||||
Route::group(['prefix' => 'booking'], function () {
|
||||
Route::post('/create', 'CreateBookingController@create')->name('create');
|
||||
Route::put('/update/{id}', 'UpdateBookingController@update')->name('update');
|
||||
Route::delete('/delete/{id}', 'DeleteBookingController@delete')->name('delete');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user