Spaces:
Running
Running
File size: 3,245 Bytes
0c117c4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | <?php
namespace App\Http\Controllers\ApiControllers\V1\Frontend;
use App\Http\Controllers\BaseController;
use App\Services\BookingServices;
use App\Services\RoomServices;
use App\Tranformers\BookingResource\BookingDetailResource;
use App\Tranformers\BookingResource\BookingListResource;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Response;
class BookingController extends BaseController
{
private $bookingServices;
public function __construct(BookingServices $bookingServices)
{
$this->bookingServices = $bookingServices;
parent::__construct();
}
public function index(Request $request, $customerId)
{
$lists = $this->bookingServices->index($request, $customerId);
if ($lists instanceof \Illuminate\Pagination\LengthAwarePaginator){
return (new BookingListResource($lists))->additional([
'totalPage' => $lists->total(),
'lastPage' => $lists->lastPage(),
'currentPage' => $lists->currentPage(),
'perPage' => (int)$lists->perPage(),
]);
}
return (new BookingListResource($lists));
}
public function show(Request $request, $customerId, $bookingId)
{
try {
$entity = $this->bookingServices->show($bookingId);
return $this->responseJson('success', Response::HTTP_OK, new BookingDetailResource($entity));
} catch (\Exception $e) {
return $this->responseJson('fail', Response::HTTP_INTERNAL_SERVER_ERROR, []);
}
}
public function update(Request $request, $customerId, $bookingId)
{
$info = $request->only([
'id',
"checkin_at",
"checkout_at",
"number_guests",
"status",
"customer_id"
]);
DB::beginTransaction();
try {
$entity = $this->bookingServices->save($info);
DB::commit();
return $this->responseJson('success', Response::HTTP_OK, new BookingDetailResource($entity));
} catch (\Exception $e) {
DB::rollback();
return $this->responseJson('fail', Response::HTTP_INTERNAL_SERVER_ERROR, []);
}
}
public function store(Request $request)
{
// todo : neu that bai tra ve ly do that bai
$info = $request->only([
'packets',
'room',
'checkout_at',
'checkin_at',
'guests',
'payment.payment_method',
'payment.payment_date',
'payment.description',
'payment.payment_amount',
'payment.address',
'payment.email',
'payment.city',
'payment.state',
'payment.post_code',
]);
DB::beginTransaction();
try {
$entity = $this->bookingServices->makeCheckout($info);
DB::commit();
return $this->responseJson('success', Response::HTTP_OK, new BookingDetailResource($entity));
} catch (\Exception $e) {
DB::rollback();
return $this->responseJson($e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR, ["status" => 4]);
}
}
}
|