-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from greenglobal/feat/api/create-api-tracking-b…
…y-ID Feat (api): Create api tracking by ID
- Loading branch information
Showing
3 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace GGPHP\Shipping\Http\Controllers\API; | ||
|
||
use Webkul\API\Http\Controllers\Shop\Controller; | ||
use Illuminate\Http\Response; | ||
|
||
class TrackingController extends Controller | ||
{ | ||
/** | ||
* Contains current guard | ||
* | ||
* @var array | ||
*/ | ||
protected $guard; | ||
|
||
/** | ||
* Contains route related configuration | ||
* | ||
* @var array | ||
*/ | ||
protected $_config; | ||
|
||
public function __construct() | ||
{ | ||
$this->guard = 'api'; | ||
|
||
$this->_config = request('_config'); | ||
|
||
if (isset($this->_config['authorization_required']) && $this->_config['authorization_required']) { | ||
auth()->setDefaultDriver($this->guard); | ||
|
||
$this->middleware('auth:' . $this->guard); | ||
} | ||
} | ||
|
||
/** | ||
* Returns a tracking info. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function get($id) | ||
{ | ||
$trackings = uspsTrackById([$id]); | ||
|
||
if (isset($trackings['status']) && !$trackings['status']) { | ||
return response()->json([ | ||
'errors' => [ | ||
[ | ||
'detail' => $trackings['message'] ?? '', | ||
] | ||
] | ||
], 400); | ||
} | ||
|
||
return response()->json([ | ||
'data' => $trackings, | ||
]); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ntrollers/Tracking/TrackingController.php → .../Controllers/Admin/TrackingController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
<?php | ||
|
||
// Admin Routes | ||
Route::group(['middleware' => ['web']], function () { | ||
Route::prefix(config('app.admin_url'))->group(function () { | ||
// Admin Routes | ||
Route::group(['middleware' => ['admin']], function () { | ||
Route::group(['namespace' => 'GGPHP\Shipping\Http\Controllers\Admin', 'middleware' => ['admin']], function () { | ||
// Sales Routes | ||
Route::prefix('sales')->group(function () { | ||
// Tracking Routes | ||
Route::get('tracking/{id}', 'GGPHP\Shipping\Http\Controllers\Tracking\TrackingController@view')->defaults('_config', [ | ||
Route::get('tracking/{id}', 'TrackingController@view')->defaults('_config', [ | ||
'view' => 'ggphp-shipping::tracking.view', | ||
]); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
// API Routes | ||
Route::group(['prefix' => 'api'], function ($router) { | ||
Route::group(['namespace' => 'GGPHP\Shipping\Http\Controllers\API', | ||
'middleware' => ['locale', 'theme', 'currency']], function ($router) | ||
{ | ||
Route::get('tracking/{id}', 'TrackingController@get')->defaults('_config', [ | ||
'authorization_required' => true | ||
]); | ||
}); | ||
}); |