Skip to content

Commit 23e2ad8

Browse files
Merge pull request #30 from IFRCGo/bugfix/WN-288
updated version references to use v2
2 parents f11a80e + 4dfd758 commit 23e2ad8

9 files changed

Lines changed: 65 additions & 52 deletions

File tree

app/Http/Controllers/UsageLogController.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,15 @@ public function getApplicationLogs(Request $request)
8383
$this->validate($request, [
8484
'fromDate' => 'sometimes|date',
8585
'toDate' => 'sometimes|date',
86+
'orderBy' => 'sometimes|string|in:name,username,estimatedUsers,requestCount',
87+
'sort' => 'sometimes|string|in:asc,desc',
8688
]);
8789

8890
try {
91+
$orderBy = $request->query('orderBy', 'name');
92+
$sort = strtolower($request->query('sort', 'asc')) === 'desc';
8993
$apps = $this->applicationRepo->allDesc(['id', 'tenant_user_id', 'name', 'estimated_users_count']);
90-
94+
9195
$usageLogs = collect([]);
9296

9397
foreach ($apps as $app) {
@@ -108,7 +112,7 @@ public function getApplicationLogs(Request $request)
108112
'errors' => [],
109113
], 500);
110114
}
111-
115+
$usageLogs = $usageLogs->sortBy($orderBy, SORT_REGULAR, $sort)->values();
112116
$paginated = $usageLogs->paginate(10)->toArray();
113117

114118
// TODO: Create custom paginator class
@@ -374,7 +378,7 @@ public function getTotals(Request $request)
374378
$query = $usageLog->query();
375379

376380
if (isset($request->society)) {
377-
$query->where('endpoint', 'v1/org/'.$request->society.'/whatnow');
381+
$query->where('endpoint', config('app.api_version') . '/org/' .$request->society.'/whatnow');
378382
}
379383
if (isset($request->subnational)) {
380384
$query->where('subnational', $request->subnational);

config/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,5 @@
249249

250250
'bucket_container' => env('AZURE_STORAGE_CONTAINER'),
251251

252+
'api_version' => 'v2',
252253
];

routes/api.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
|
1414
*/
1515

16-
Route::group(['prefix' => 'v1'], function () {
16+
Route::group(['prefix' => config('app.api_version')], function () {
1717
// Unauthenticated endpoints
1818
Route::get('alerts/rss', 'AlertController@getRss');
1919
Route::get('alerts/{identifier}', 'AlertController@getByIdentifier');
@@ -22,14 +22,14 @@
2222
Route::get('org/{code}/alerts/rss', 'AlertController@getRssByOrg');
2323
});
2424

25-
Route::group(['middleware' => 'BasicAuth', 'prefix' => 'v1'], function () {
25+
Route::group(['middleware' => 'BasicAuth', 'prefix' => config('app.api_version')], function () {
2626
// Alert management
2727
Route::post('alerts', 'AlertController@post');
2828
});
2929

3030
Route::group([
3131
'middleware' => 'ApiAuth',
32-
'prefix' => 'v1',
32+
'prefix' => config('app.api_version'),
3333
], function () {
3434
// Endpoints requiring API key authentication
3535
Route::get('org/', 'OrganisationController@getAll');
@@ -40,7 +40,7 @@
4040

4141
Route::group([
4242
'middleware' => 'BasicAuth',
43-
'prefix' => 'v1',
43+
'prefix' => config('app.api_version'),
4444
], function () {
4545
Route::get('/subnationals/{country_code}', 'RegionController@getAllForOrganisation');
4646
Route::get('/subnationals/{country_code}/{code}', 'RegionController@getForCountryCode');
@@ -88,3 +88,11 @@
8888
Route::get('/health', function () {
8989
return response()->json(['status' => 'ok']); // Or a more detailed status
9090
});
91+
92+
Route::prefix('v1')->group(function () {
93+
Route::any('{any}', function () {
94+
return response()->json([
95+
'error' => 'API version v1 is no longer supported. Please use /v2/.'
96+
], 410);
97+
})->where('any', '.*');
98+
});

storage/api-docs/api-docs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"servers": [
99
{
10-
"url": "https://api.whatnow.jazusoft.com/v1",
10+
"url": "https://api.whatnow.jazusoft.com/v2",
1111
"description": "API Base URL"
1212
}
1313
],

tests/Feature/AlertFeedTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private function _postAlert($alert = null)
2828
$alert = factory(\App\Models\Alert::class)->make();
2929
}
3030

31-
return $this->json('POST', '/v1/alerts', [
31+
return $this->json('POST', '/' . config('app.api_version') . '/alerts', [
3232
'country' => $alert->country_code,
3333
'language' => $alert->language_code,
3434
'event' => $alert->event,
@@ -56,7 +56,7 @@ public function test_rss_feed_returns_alerts_filtered_by_severity()
5656

5757
$alert = Alert::find($alert->json('id'));
5858

59-
$response = $this->call('GET', '/v1/alerts/rss', [
59+
$response = $this->call('GET', '/' . config('app.api_version') . '/alerts/rss', [
6060
'severity' => $alert->severity,
6161
]);
6262

@@ -68,7 +68,7 @@ public function test_rss_feed_returns_alerts_filtered_by_severity()
6868
$this->assertEquals($alert->getPublicUrl(), (string)$item[0]);
6969

7070
// Load the xml from disk
71-
$path = storage_path('app/public/v1/alerts/cap12/') . $alert->getXmlPath();
71+
$path = storage_path('app/public/' . config('app.api_version') . '/alerts/cap12/') . $alert->getXmlPath();
7272
$this->assertFileExists($path);
7373

7474
$cap = simplexml_load_file($path);
@@ -86,7 +86,7 @@ public function test_rss_feed_returns_alerts_filtered_by_event_type()
8686

8787
$response = $this->call(
8888
'GET',
89-
'/v1/org/' . strtolower($alert->organisation->country_code) . '/alerts/rss',
89+
'/' . config('app.api_version') . '/org/' . strtolower($alert->organisation->country_code) . '/alerts/rss',
9090
['eventType' => $alert->event]
9191
);
9292

@@ -104,7 +104,7 @@ public function test_json_feed_returns_alerts_filtered_by_event_type()
104104

105105
$response = $this->call(
106106
'GET',
107-
'/v1/org/' . strtolower($alert->organisation->country_code) . '/alerts',
107+
'/' . config('app.api_version') . '/org/' . strtolower($alert->organisation->country_code) . '/alerts',
108108
['eventType' => $alert->event]
109109
);
110110

@@ -115,7 +115,7 @@ public function test_json_feed_returns_alerts_filtered_by_event_type()
115115

116116
public function test_json_feed_returns_alerts_filtered_by_severity()
117117
{
118-
$response = $this->call('GET', '/v1/alerts', [
118+
$response = $this->call('GET', '/' . config('app.api_version') . '/alerts', [
119119
'severity' => 'extreme',
120120
]);
121121

@@ -134,7 +134,7 @@ public function test_rss_item_link_self_reference_permalink_is_true()
134134

135135
$alert = Alert::find($alert->json('id'));
136136

137-
$response = $this->call('GET', '/v1/alerts/rss');
137+
$response = $this->call('GET', '/' . config('app.api_version') . '/alerts/rss');
138138

139139
$xml = new SimpleXMLElement($response->content());
140140
$item = $xml->xpath('//rss/channel/item[1]/guid/@isPermaLink');
@@ -158,7 +158,7 @@ public function test_active_filter_returns_only_active_alerts()
158158

159159
$response = $this->call(
160160
'GET',
161-
'/v1/alerts/rss',
161+
'/' . config('app.api_version') . '/alerts/rss',
162162
['active' => 'true']
163163
);
164164

@@ -187,7 +187,7 @@ public function test_feed_returns_active_and_inactive_alerts_when_active_filter_
187187

188188
$response = $this->call(
189189
'GET',
190-
'/v1/alerts/rss'
190+
'/' . config('app.api_version') . '/alerts/rss'
191191
);
192192

193193
$xml = new SimpleXMLElement($response->content());
@@ -211,7 +211,7 @@ public function test_date_filter_return_alerts_sent_within_specified_range()
211211
// Request last 24 hrs of alerts
212212
$response = $this->call(
213213
'GET',
214-
'/v1/alerts/rss',
214+
'/' . config('app.api_version') . '/alerts/rss',
215215
[
216216
'startTime' => (new DateTime('now'))->sub(new DateInterval('PT24H'))->format('c'),
217217
'endTime' => (new DateTime('now'))->format('c'),
@@ -236,7 +236,7 @@ public function test_date_filter_excludes_alerts_sent_outside_specified_range()
236236
// Request alerts up to 24hrs old
237237
$response = $this->call(
238238
'GET',
239-
'/v1/alerts/rss',
239+
'/' . config('app.api_version') . '/alerts/rss',
240240
[
241241
'startTime' => (new DateTime('now'))->sub(new DateInterval('PT24H'))->format('c'),
242242
'endTime' => (new DateTime('now'))->format('c'),

tests/Feature/AlertTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private function _postAlert($alert = null)
2323
$alert = factory(\App\Models\Alert::class)->make();
2424
}
2525

26-
return $this->json('POST', '/v1/alerts', [
26+
return $this->json('POST', '/' . config('app.api_version') . '/alerts', [
2727
'country' => $alert->country_code,
2828
'language' => $alert->language_code,
2929
'event' => $alert->event,
@@ -93,7 +93,7 @@ public function test_it_generates_a_valid_cap_file()
9393

9494
$alert = Alert::find($alert->json('id'));
9595

96-
$path = storage_path('app/public') . '/v1/alerts/cap12/' . $alert->getXmlPath();
96+
$path = storage_path('app/public') . '/' . config('app.api_version') . '/alerts/cap12/' . $alert->getXmlPath();
9797

9898
$this->assertFileExists($path);
9999

@@ -111,7 +111,7 @@ public function test_it_appears_in_rss_feed()
111111

112112
$alert = Alert::find($alert->json('id'));
113113

114-
$response = $this->call('GET', '/v1/alerts/rss');
114+
$response = $this->call('GET', '/' . config('app.api_version') . '/alerts/rss');
115115
$this->assertEquals(200, $response->status());
116116

117117
$xml = new SimpleXMLElement($response->content());
@@ -126,7 +126,7 @@ public function test_it_appears_in_country_feed()
126126

127127
$alert = Alert::find($alert->json('id'));
128128

129-
$response = $this->call('GET', '/v1/org/' . strtolower($alert->organisation->country_code) . '/alerts/rss');
129+
$response = $this->call('GET', '/' . config('app.api_version') . '/org/' . strtolower($alert->organisation->country_code) . '/alerts/rss');
130130
$this->assertEquals(200, $response->status());
131131

132132
$xml = new SimpleXMLElement($response->content());
@@ -141,7 +141,7 @@ public function test_it_appears_in_json_feed()
141141

142142
$alert = Alert::find($alert->json('id'));
143143

144-
$response = $this->call('GET', '/v1/alerts');
144+
$response = $this->call('GET', '/' . config('app.api_version') . '/alerts');
145145

146146
$response->assertStatus(200);
147147

@@ -156,7 +156,7 @@ public function test_it_is_returned_by_identifier()
156156

157157
$alert = Alert::find($alert->json('id'));
158158

159-
$response = $this->call('GET', '/v1/alerts/' . $alert->getCapIdentifier());
159+
$response = $this->call('GET', '/' . config('app.api_version') . '/alerts/' . $alert->getCapIdentifier());
160160

161161
$response->assertStatus(200);
162162

tests/Feature/ApplicationTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function test_it_lists_apps()
4242
],
4343
];
4444

45-
$response = $this->json('GET', '/v1/apps?userId=999');
45+
$response = $this->json('GET', '/' . config('app.api_version') . '/apps?userId=999');
4646

4747
$response->assertStatus(200);
4848

@@ -71,7 +71,7 @@ public function test_it_gets_app()
7171
],
7272
];
7373

74-
$response = $this->json('GET', '/v1/apps/'.$app->id);
74+
$response = $this->json('GET', '/' . config('app.api_version') . '/apps/'.$app->id);
7575

7676
$response->assertStatus(200);
7777

@@ -91,7 +91,7 @@ public function test_it_deletes_app()
9191
'key' => '1234567890',
9292
]);
9393

94-
$this->json('DELETE', '/v1/apps/'.$app->id)->assertStatus(200);
94+
$this->json('DELETE', '/' . config('app.api_version') . '/apps/'.$app->id)->assertStatus(200);
9595

9696
$this->assertDatabaseHas('applications', [
9797
'id' => $app->id,
@@ -106,7 +106,7 @@ public function test_it_creates_app()
106106
{
107107
$this->markTestSkipped('Bug Request POST parameters lost when unit testing https://github.com/laravel/lumen-framework/issues/559 upgrade to Lumen 5.4.2+');
108108

109-
$this->json('POST', '/v1/apps/', [
109+
$this->json('POST', '/' . config('app.api_version') . '/apps/', [
110110
'userId' => '55',
111111
'name' => 'Hello',
112112
])->assertStatus(200);

tests/Feature/RegionTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testCreateRegionForOrganisation()
4646
],
4747
];
4848

49-
$response = $this->json('POST', '/v1/subnationals', $data);
49+
$response = $this->json('POST', '/' . config('app.api_version') . '/subnationals', $data);
5050

5151
//dd($response);
5252

@@ -98,7 +98,7 @@ public function testUpdateRegion()
9898

9999
$this->assertEquals(0, $matched);
100100

101-
$this->json('PUT', "/v1/subnationals/subnational/{$region->id}", $data)
101+
$this->json('PUT', '/' . config('app.api_version') . '/subnationals/subnational/{$region->id}', $data)
102102
->assertStatus(201);
103103

104104
$matched = RegionTranslation::where('region_id', '=', $region->id)
@@ -111,13 +111,13 @@ public function testUpdateRegion()
111111

112112
public function testGetRegionsForOrganisation()
113113
{
114-
$this->json('GET', '/v1/subnationals/USA')
114+
$this->json('GET', '/' . config('app.api_version') . '/subnationals/USA')
115115
->assertStatus(200);
116116
}
117117

118118
public function testGetLaguageSpecificRegionsForOrganisation()
119119
{
120-
$this->json('GET', '/v1/subnationals/USA/es')
120+
$this->json('GET', '/' . config('app.api_version') . '/subnationals/USA/es')
121121
->assertStatus(200);
122122
}
123123

@@ -139,7 +139,7 @@ public function testDeleteRegionForOrganisation()
139139
],
140140
]);
141141

142-
$this->json('DELETE', "/v1/subnationals/subnational/{$region->id}")
142+
$this->json('DELETE', '/' . config('app.api_version') . '/subnationals/subnational/{$region->id}')
143143
->assertStatus(202);
144144
}
145145
}

0 commit comments

Comments
 (0)