| Server IP : 34.87.99.72 / Your IP : 216.73.217.31 Web Server : Apache/2.4.46 (Unix) OpenSSL/1.1.1n System : Linux zlock-bitnami-lamp-prod-v2-vm 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 User : bitnami ( 1000) PHP Version : 7.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /opt/bitnami/apache/htdocs/app/app/Http/Controllers/ |
Upload File : |
<?php
namespace App\Http\Controllers;
use App\Http\Requests\LockerMiddlewares\LockerMiddlewareDisconnectRequest;
use App\Http\Requests\LockerMiddlewares\LockerMiddlewareOpenBoxRequest;
use App\Http\Requests\LockerMiddlewares\LockerMiddlewareKeepAliveRequest;
use App\Http\Requests\LockerMiddlewares\LockerMiddlewareSignInRequest;
use App\Http\Requests\LockerMiddlewares\ReadQrRequest;
use App\Http\Services\LockerMiddlewareService;
use App\Http\Services\BoxInventoryService;
use App\Http\Services\BoxDeliveryService;
use Pylon\Exceptions\BadRequestException;
use Illuminate\Validation\ValidationException;
use DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Contracts\Encryption\DecryptException;
class LockerMiddlewareController extends Controller
{
public function __construct(
LockerMiddlewareService $lockerMiddlewareService,
BoxInventoryService $boxInventoryService,
BoxDeliveryService $boxDeliveryService
)
{
$this->lockerMiddlewareService = $lockerMiddlewareService;
$this->boxInventoryService = $boxInventoryService;
$this->boxDeliveryService = $boxDeliveryService;
}
/**
* @OA\Post(
*
* path="/api/signIn",
* operationId="lockerSignIn",
* tags={"Locker Hardware Integration"},
* summary="Update locker online status and create locker if it doesn't exist in database.",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="terminalID",
* description="Unique ID used to identify the locker",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="totalBoxNums",
* description="Total number of boxes available at the locker",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="displayName",
* description="Name of the locker",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Response(
* response=200,
* description="Success",
* @OA\JsonContent()
* ),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=404, description="Resource Not Found"),
* @OA\Response(response=422, description="Unprocessable Entity"),
* @OA\Response(response=500, description="Internal Server Error"),
* )
*/
public function signIn(LockerMiddlewareSignInRequest $request)
{
// DB::transaction(function () use ($request){
// $locker = $this->lockerMiddlewareService->signIn( $request->validated() );
// return null;
// });
$locker = $this->lockerMiddlewareService->signIn( $request->validated() );
return self::successResponse('Success', $locker );
}
/**
* @OA\Post(
*
* path="/api/keepAlive",
* operationId="LockerKeepAlive",
* tags={"Locker Hardware Integration"},
* summary="Update locker online status and inform server which locker box is open/close",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="terminalID",
* description="Unique ID used to identify the locker",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="openStatusArray",
* description="Each locker box open/close status in order of the locker box number where value 1 if locker is close and value 0 if locker is open, with each value seperated by a comma. ",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="webSocketStatus",
* description="Locker web socket status",
* in="query",
* @OA\Schema(
* type="enum",
* default="",
* enum={"CONNECTING", "CONNECTED", "DISCONNECTED", "RECONNECTING"}
* )
* ),
* @OA\Response(
* response=200,
* description="Success",
* @OA\JsonContent()
* ),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=404, description="Resource Not Found"),
* @OA\Response(response=422, description="Unprocessable Entity"),
* @OA\Response(response=500, description="Internal Server Error"),
* )
*/
public function keepAlive(LockerMiddlewareKeepAliveRequest $request)
{
// DB::transaction(function () use ($request){
// $creditItems = $this->lockerMiddlewareService->keepAlive( $request->validated() );
// return null;
// });
$locker = $this->lockerMiddlewareService->keepAlive( $request->validated() );
return self::successResponse('Success', $locker);
}
/**
* @OA\Post(
*
* path="/api/disconnect",
* operationId="LockerDisconnect",
* tags={"Locker Hardware Integration"},
* summary="Update locker online status to offline",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="terminalID",
* description="Unique ID used to identify the locker",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Response(
* response=200,
* description="Success",
* @OA\JsonContent()
* ),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=404, description="Resource Not Found"),
* @OA\Response(response=422, description="Unprocessable Entity"),
* @OA\Response(response=500, description="Internal Server Error"),
* )
*/
public function disconnect(LockerMiddlewareDisconnectRequest $request)
{
$locker = $this->lockerMiddlewareService->disconnect( $request->validated() );
return self::successResponse('Success', $locker );
}
/**
* @OA\Post(
*
* path="/api/openBox",
* operationId="LockerOpenBox",
* tags={"Locker Hardware Integration"},
* summary="Open Locker Box",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="terminalID",
* description="Unique ID used to identify the locker",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="lockerBoxID",
* description="Unique ID used to identify the locker box",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="attemp",
* description="Number of attempts to open the box",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Response(
* response=200,
* description="Success",
* @OA\JsonContent()
* ),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=404, description="Resource Not Found"),
* @OA\Response(response=422, description="Unprocessable Entity"),
* @OA\Response(response=500, description="Internal Server Error"),
* )
*/
public function openBox(LockerMiddlewareOpenBoxRequest $request)
{
$locker = $this->lockerMiddlewareService->openBox( $request->validated() );
return self::successResponse('Success', $locker );
}
/**
* @OA\Post(
*
* path="/api/locker/test",
* operationId="testLocker (temporary)",
* tags={"Locker"},
* summary="testLocker",
* security={
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="box_no",
* description="box_no",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Response(
* response=200,
* description="Success",
* @OA\JsonContent()
* ),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=404, description="Resource Not Found"),
* @OA\Response(response=422, description="Unprocessable Entity"),
* @OA\Response(response=500, description="Internal Server Error"),
* )
*/
public function testLocker(Request $request)
{
$request->validate([
"box_no" => "required|integer",
]);
$response = $this->lockerMiddlewareService->testLocker($request);
return self::successResponse('Success',[ "response" => $response ] );
}
/**
* @OA\Post(
*
* path="/api/read-qr-code",
* operationId="readQrCode",
* tags={"Locker Hardware Integration"},
* summary="Read QR Code",
* security={
* {
* "open_key": {}
* },
* {
* "api_key": {}
* }
* },
* @OA\Parameter(
* name="terminal_id",
* description="The terminal id of the locker",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Parameter(
* name="json_string",
* description="json string",
* in="query",
* @OA\Schema(
* type="string",
* default=""
* )
* ),
* @OA\Response(
* response=200,
* description="Success",
* @OA\JsonContent()
* ),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=404, description="Resource Not Found"),
* @OA\Response(response=422, description="Unprocessable Entity"),
* @OA\Response(response=500, description="Internal Server Error"),
* )
*/
public function readQrCode(ReadQrRequest $request)
{
$payload = $request->validated();
try{
$decrypted_text = base64_decode($payload['json_string']);
}catch (DecryptException $e) {
throw (new BadRequestException("Invalid QR code!"))
->withErrorType('QR_CODE_INVALID');
}
$json = json_decode($decrypted_text);
if(!isset($json->booking_type) || !isset($json->id) || !isset($json->type) || !isset($json->user_id))
throw (new BadRequestException("Invalid QR code!"))
->withErrorType('QR_CODE_INVALID');
if(isset($payload['terminal_id']))
{
$json->terminal_id = $payload['terminal_id'];
}
$qrResponse = $this->lockerMiddlewareService->readQrCode( $json );
return self::successResponse('Success',$qrResponse);
}
}