Spaces:
Running
Running
File size: 2,506 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 | <?php
namespace App\Http\Controllers\ApiControllers\V1\Frontend;
use App\Http\Controllers\BaseController;
use App\Services\RatingServices;
use App\Tranformers\RatingResource\RatingDetailResource;
use App\Tranformers\RatingResource\RatingListResource;
use App\Tranformers\RatingResource\RatingRoomListResource;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
use Tymon\JWTAuth\Facades\JWTAuth;
class RatingController extends BaseController
{
private $ratingServices;
public function __construct(RatingServices $ratingServices)
{
$this->ratingServices = $ratingServices;
parent::__construct();
}
public function index(Request $request)
{
$lists = $this->ratingServices->index($request);
if ($lists instanceof \Illuminate\Pagination\LengthAwarePaginator){
return (new RatingListResource($lists))->additional([
'totalPage' => $lists->total(),
'lastPage' => $lists->lastPage(),
'currentPage' => $lists->currentPage(),
'perPage' => (int)$lists->perPage(),
]);
}
return (new RatingListResource($lists));
}
public function ratingRoom(Request $request,$roomTypeId,$packetId)
{
$request['checkCanReview']=1;
$request['room_type_id'] =$roomTypeId;
$request['packet_id'] =$packetId;
$lists = $this->ratingServices->index($request);
if ($lists instanceof \Illuminate\Pagination\LengthAwarePaginator){
return (new RatingRoomListResource($lists))->additional([
'totalPage' => $lists->total(),
'lastPage' => $lists->lastPage(),
'currentPage' => $lists->currentPage(),
'perPage' => (int)$lists->perPage(),
]);
}
return (new RatingRoomListResource($lists));
}
public function store(Request $request)
{
$info = $request->only([
'id',
'room_type_packet_id',
"comment",
"rate",
"packet_id",
"room_type_id",
]);
DB::beginTransaction();
try {
$entity = $this->ratingServices->save($info);
DB::commit();
return $this->responseJson('success', Response::HTTP_OK, new RatingDetailResource($entity));
} catch (\Exception $e) {
DB::rollback();
return $this->responseJson('fail', Response::HTTP_INTERNAL_SERVER_ERROR, []);
}
}
}
|