Skip to content

Commit

Permalink
Merge pull request #4 from greenglobal/feat/api/create-api-tracking-b…
Browse files Browse the repository at this point in the history
…y-ID

Feat (api): Create api tracking by ID
  • Loading branch information
HuynhHungManh authored Oct 12, 2020
2 parents 9003b0e + 26120c3 commit 04031e7
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
61 changes: 61 additions & 0 deletions src/Http/Controllers/API/TrackingController.php
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,
]);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace GGPHP\Shipping\Http\Controllers\Tracking;
namespace GGPHP\Shipping\Http\Controllers\Admin;

use Webkul\Admin\Http\Controllers\Controller;

Expand Down
16 changes: 14 additions & 2 deletions src/Http/routes.php
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
]);
});
});

0 comments on commit 04031e7

Please sign in to comment.