Added /api/settings to retrieve all VA settings #120
This commit is contained in:
28
app/Http/Controllers/Api/SettingsController.php
Normal file
28
app/Http/Controllers/Api/SettingsController.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
use App\Repositories\SettingRepository;
|
||||||
|
use App\Http\Resources\Setting as SettingResource;
|
||||||
|
|
||||||
|
class SettingsController extends RestController
|
||||||
|
{
|
||||||
|
protected $settingRepo;
|
||||||
|
|
||||||
|
public function __construct(SettingRepository $settingRepo) {
|
||||||
|
$this->settingRepo = $settingRepo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all the airlines, paginated
|
||||||
|
*/
|
||||||
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
$settings = $this->settingRepo
|
||||||
|
->orderBy('order', 'asc')->get();
|
||||||
|
|
||||||
|
return SettingResource::collection($settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
21
app/Http/Resources/Setting.php
Normal file
21
app/Http/Resources/Setting.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\Resource;
|
||||||
|
|
||||||
|
class Setting extends Resource
|
||||||
|
{
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'type' => $this->type,
|
||||||
|
'name' => $this->name,
|
||||||
|
'value' => $this->value,
|
||||||
|
'group' => $this->group,
|
||||||
|
'order' => $this->order,
|
||||||
|
'description' => $this->description,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,4 +44,18 @@ class Setting extends BaseModel
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override the casting mechanism
|
||||||
|
* @param string $key
|
||||||
|
* @return mixed|string
|
||||||
|
*/
|
||||||
|
/*protected function getCastType($key)
|
||||||
|
{
|
||||||
|
if ($key === 'value' && !empty($this->type)) {
|
||||||
|
return $this->type;
|
||||||
|
} else {
|
||||||
|
return parent::getCastType($key);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,11 @@ Route::group(['middleware' => ['api.auth']], function ()
|
|||||||
Route::post('pireps/{id}/route', 'PirepController@route_post');
|
Route::post('pireps/{id}/route', 'PirepController@route_post');
|
||||||
Route::delete('pireps/{id}/route', 'PirepController@route_delete');
|
Route::delete('pireps/{id}/route', 'PirepController@route_delete');
|
||||||
|
|
||||||
|
Route::get('settings', 'SettingsController@index');
|
||||||
|
|
||||||
# This is the info of the user whose token is in use
|
# This is the info of the user whose token is in use
|
||||||
Route::get('user', 'UserController@index');
|
Route::get('user', 'UserController@index');
|
||||||
|
|
||||||
Route::get('users/{id}', 'UserController@get');
|
Route::get('users/{id}', 'UserController@get');
|
||||||
Route::get('users/{id}/bids', 'UserController@bids');
|
Route::get('users/{id}/bids', 'UserController@bids');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -190,4 +190,11 @@ class ApiTest extends TestCase
|
|||||||
$body = $resp->json();
|
$body = $resp->json();
|
||||||
$this->assertEquals($body['id'], $aircraft->id);
|
$this->assertEquals($body['id'], $aircraft->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetAllSettings()
|
||||||
|
{
|
||||||
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
|
$res = $this->get('/api/settings')->assertStatus(200);
|
||||||
|
$settings = $res->json();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user