Add new column to booking, create new api to trust the seller from online

This commit is contained in:
Uwais Al-Qarni
2022-05-16 14:55:41 +08:00
parent e9114670ed
commit ad49b8e339
7 changed files with 191 additions and 0 deletions
@@ -0,0 +1,57 @@
<?php
namespace App\Classes\Modules\Bookings\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Bookings\Services\FetchesBooking;
use App\Classes\Modules\Bookings\Services\UpdatesBookingTrusted;
use App\Classes\ValueObjects\Constants\BookingTrust;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class TrustedSellerLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Trust the seller',
'message' => 'You have successfully approved the seller'
];
}
/** @var FetchesBooking */
private $fetchesBooking;
/** @var UpdatesBookingTrusted */
private $updatesBookingTrusted;
/**
* TrustedSellerLogic constructor.
* @param FetchesBooking $fetchesBooking
* @param UpdatesBookingTrusted $updatesBookingTrusted
*/
public function __construct(FetchesBooking $fetchesBooking, UpdatesBookingTrusted $updatesBookingTrusted)
{
$this->fetchesBooking = $fetchesBooking;
$this->updatesBookingTrusted = $updatesBookingTrusted;
}
/**
* @param Request $request
* @return JsonResponse
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function logic(Request $request) : JsonResponse
{
$booking = $this->fetchesBooking->execute(['id' => $request->route('id')]);
$this->updatesBookingTrusted->execute($booking, BookingTrust::TRUSTED);
return $this->response([]);
}
}
@@ -0,0 +1,21 @@
<?php
namespace App\Classes\Modules\Bookings\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Models\Booking;
class UpdatesBookingTrusted extends AbstractUpdateRecord
{
/**
* @param Booking $model
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Booking $model, int $bool)
{
$model->trusted = $bool;
return $this->handler($model);
}
}
@@ -0,0 +1,10 @@
<?php
namespace App\Classes\ValueObjects\Constants;
final class BookingTrust {
public const UNTRUSTED = 0;
public const TRUSTED = 1;
}
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace App\Console\Commands;
use App\Classes\Modules\ServiceTypes\Services\FetchesServiceType;
use Illuminate\Console\Command;
class testingGround extends Command
{
public $fetchesServiceType;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test:script';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(FetchesServiceType $fetchesServiceType)
{
$this->fetchesServiceType = $fetchesServiceType;
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$test = $this->fetchesServiceType->execute(['id' => 5]);
dd($test->name);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Bookings;
use App\Classes\Modules\Bookings\ControllersLogic\TrustedSellerLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class TrustSellerController
{
/**
* @param Request $request
* @param TrustedSellerLogic $logic
* @return JsonResponse
*/
public function trust(Request $request, TrustedSellerLogic $logic): JsonResponse
{
return $logic->execute($request);
}
}
@@ -0,0 +1,33 @@
<?php
use App\Classes\ValueObjects\Constants\BookingTrust;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddColumnToBookings extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('bookings', function (Blueprint $table) {
$table->integer('trusted')->default(BookingTrust::UNTRUSTED)->nullable()->after('status');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('bookings', function (Blueprint $table) {
$table->dropColumn('trusted');
});
}
}
+2
View File
@@ -32,4 +32,6 @@ Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Booking
Route::post('{id}/proforma/create', 'CreateProformaInvoiceTransaction@create')->name('proforma.create');
Route::post('{id}/trust_seller', 'TrustSellerController@trust')->name('trust_seller');
});