API get_location (#14779)

* api endpoint to get specific location

* missing nl

* fix missed styleci error

* make requested change
This commit is contained in:
VTS
2023-08-03 20:35:20 -04:00
committed by GitHub
parent fe1b280a99
commit 7381c2046c
3 changed files with 43 additions and 0 deletions

View File

@@ -112,3 +112,30 @@ Output:
"message": "Location updated successfully"
}
```
###`get_location`
Gets a specific location
Route: `/api/v0/location/:location`
- location: name or id of the location to get
Output:
```json
{
"status": "ok",
"get_location": [
{
"id": 1,
"location": "TEST",
"lat": 00.000000,
"lng": 00.000000,
"timestamp": "2023-01-01 00:00:00",
"fixed_coordinates": 1
}
],
"count": 1
}
```

View File

@@ -17,6 +17,7 @@ use App\Models\Availability;
use App\Models\Device;
use App\Models\DeviceGroup;
use App\Models\DeviceOutage;
use App\Models\Location;
use App\Models\MplsSap;
use App\Models\MplsService;
use App\Models\OspfPort;
@@ -2900,6 +2901,20 @@ function edit_location(Illuminate\Http\Request $request)
return api_error(500, 'Failed to update location');
}
function get_location(Illuminate\Http\Request $request)
{
$location = $request->route('location_id_or_name');
if (empty($location)) {
return api_error(400, 'No location has been provided to get');
}
$data = ctype_digit($location) ? Location::find($location_id) : Location::where('location', $location)->first();
if (empty($data)) {
return api_error(404, 'Location does not exist');
}
return api_success($data, 'get_location');
}
function get_location_id_by_name($location)
{
return dbFetchCell('SELECT id FROM locations WHERE location = ?', $location);

View File

@@ -89,6 +89,7 @@ Route::prefix('v0')->namespace('\App\Api\Controllers')->group(function () {
Route::post('devices/{id}/parents', 'LegacyApiController@add_parents_to_host')->name('add_parents_to_host');
Route::delete('/devices/{id}/parents', 'LegacyApiController@del_parents_from_host')->name('del_parents_from_host');
Route::post('locations', 'LegacyApiController@add_location')->name('add_location');
Route::get('location/{location_id_or_name}', 'LegacyApiController@get_location')->name('get_location');
Route::patch('locations/{location_id_or_name}', 'LegacyApiController@edit_location')->name('edit_location');
Route::delete('locations/{location}', 'LegacyApiController@del_location')->name('del_location');
Route::delete('services/{id}', 'LegacyApiController@del_service_from_host')->name('del_service_from_host');