Skip to content

Commit e2b5699

Browse files
Merge pull request #22 from IFRCGo/feature/WN-285
feature/WN-285
2 parents 0b3f406 + a1ec45a commit e2b5699

23 files changed

+630
-630
lines changed

app/Classes/Feeds/WhatNowFeed.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function setOrganisation(Organisation $org)
9696
*/
9797
public function setRegion(Region $region = null)
9898
{
99-
$this->region = $region;
99+
$this->subnational = $region;
100100
return $this;
101101
}
102102

@@ -134,7 +134,7 @@ public function loadData()
134134
$this->organisation->id,
135135
$this->language,
136136
$this->filterEventTypes,
137-
$this->region->id ?? null
137+
$this->subnational->id ?? null
138138
);
139139

140140
if ($data instanceof Collection) {

app/Classes/Transformers/WhatNowEntityTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function transform(WhatNowEntity $model)
6464
'countryCode' => $model->organisation->country_code,
6565
'eventType' => $model->event_type,
6666
'regionName' => $model->region_name,
67-
'region' => $model->region,
67+
'subnational' => $model->subnational,
6868
'attribution' => [
6969
'name' => $model->organisation->org_name,
7070
'countryCode' => $model->organisation->country_code,

app/Http/Controllers/RegionController.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ public function __construct(
3939

4040
/**
4141
* @OA\Post(
42-
* path="/regions",
42+
* path="/subnationals",
4343
* tags={"Regions"},
44-
* summary="Create a new region",
44+
* summary="Create a new subnational",
4545
* operationId="createRegion",
4646
* @OA\RequestBody(
4747
* required=true,
4848
* @OA\JsonContent(
4949
* required={"countryCode", "title"},
5050
* @OA\Property(property="countryCode", type="string", example="USA", description="Country code (3 characters)"),
51-
* @OA\Property(property="title", type="string", example="North America", description="Title of the region"),
52-
* @OA\Property(property="slug", type="string", example="north-america", description="Slug for the region (optional)"),
51+
* @OA\Property(property="title", type="string", example="North America", description="Title of the subnational"),
52+
* @OA\Property(property="slug", type="string", example="north-america", description="Slug for the subnational (optional)"),
5353
* @OA\Property(
5454
* property="translations",
5555
* type="array",
@@ -58,7 +58,7 @@ public function __construct(
5858
* @OA\Property(property="webUrl", type="string", format="url", example="https://example.com", description="Web URL for the translation"),
5959
* @OA\Property(property="lang", type="string", example="en", description="Language code (2 characters)"),
6060
* @OA\Property(property="title", type="string", example="North America", description="Title in the specified language"),
61-
* @OA\Property(property="description", type="string", example="Description of the region", description="Description in the specified language")
61+
* @OA\Property(property="description", type="string", example="Description of the subnational", description="Description in the specified language")
6262
* )
6363
* )
6464
* )
@@ -103,10 +103,10 @@ public function createRegion(Request $request)
103103
}
104104

105105
$slug = empty($request->input('slug')) ? str_slug($request->input('title')) : $request->input('slug');
106-
$existing = $org->regions()->where('slug', '=', $request->input('slug'))->count();
106+
$existing = $org->subnationals()->where('slug', '=', $request->input('slug'))->count();
107107

108108
if ($existing > 0) {
109-
return response()->json([ 'error_message' => 'This region already exists', 'errors' => []], 409);
109+
return response()->json([ 'error_message' => 'This subnational already exists', 'errors' => []], 409);
110110
}
111111

112112
$region = Region::create([
@@ -128,22 +128,22 @@ public function createRegion(Request $request)
128128

129129
/**
130130
* @OA\Put(
131-
* path="/regions/region/{regionId}",
131+
* path="/subnationals/subnational/{regionId}",
132132
* tags={"Regions"},
133-
* summary="Update an existing region",
133+
* summary="Update an existing subnational",
134134
* operationId="updateRegion",
135135
* @OA\Parameter(
136136
* name="regionId",
137137
* in="path",
138138
* required=true,
139-
* description="ID of the region to update",
139+
* description="ID of the subnational to update",
140140
* @OA\Schema(type="integer", format="int64")
141141
* ),
142142
* @OA\RequestBody(
143143
* required=true,
144144
* @OA\JsonContent(
145-
* @OA\Property(property="title", type="string", example="Updated Region Title", description="Updated title of the region (optional)"),
146-
* @OA\Property(property="slug", type="string", example="updated-region-slug", description="Updated slug for the region (optional)"),
145+
* @OA\Property(property="title", type="string", example="Updated Region Title", description="Updated title of the subnational (optional)"),
146+
* @OA\Property(property="slug", type="string", example="updated-subnational-slug", description="Updated slug for the subnational (optional)"),
147147
* @OA\Property(
148148
* property="translations",
149149
* type="array",
@@ -172,7 +172,7 @@ public function updateRegion(Request $request, $regionId)
172172
$region = Region::find($regionId);
173173

174174
if (empty($region)) {
175-
return response()->json([ 'error_message' => 'No region found', 'errors' => []], 404);
175+
return response()->json([ 'error_message' => 'No subnational found', 'errors' => []], 404);
176176
}
177177

178178
$this->validate($request, [
@@ -216,8 +216,8 @@ public function updateRegion(Request $request, $regionId)
216216

217217
/**
218218
* @OA\Get(
219-
* path="/regions/{country_code}",
220-
* summary="Get all regions for a specific organisation by country code",
219+
* path="/subnationals/{country_code}",
220+
* summary="Get all subnationals for a specific organisation by country code",
221221
* tags={"Regions"},
222222
* @OA\Parameter(
223223
* name="country_code",
@@ -248,7 +248,7 @@ public function getAllForOrganisation($country_code)
248248
}
249249

250250
$list = [];
251-
foreach ($organisation->regions as $region) {
251+
foreach ($organisation->subnationals as $region) {
252252
$data = [
253253
'id' => $region->id,
254254
'title' => $region->title,
@@ -270,8 +270,8 @@ public function getAllForOrganisation($country_code)
270270

271271
/**
272272
* @OA\Get(
273-
* path="/regions/{country_code}/{code}",
274-
* summary="Get regions for a specific organisation by country code and language code",
273+
* path="/subnationals/{country_code}/{code}",
274+
* summary="Get subnationals for a specific organisation by country code and language code",
275275
* tags={"Regions"},
276276
* @OA\Parameter(
277277
* name="country_code",
@@ -309,7 +309,7 @@ public function getForCountryCode($country_code, $code)
309309
}
310310

311311
$list = [];
312-
foreach ($organisation->regions as $region) {
312+
foreach ($organisation->subnationals as $region) {
313313
$translation = $region->translations()
314314
->where('language_code', '=', $code)
315315
->first();
@@ -329,15 +329,15 @@ public function getForCountryCode($country_code, $code)
329329

330330
/**
331331
* @OA\Delete(
332-
* path="/regions/region/{regionId}",
332+
* path="/subnationals/subnational/{regionId}",
333333
* tags={"Regions"},
334-
* summary="Delete a region",
334+
* summary="Delete a subnational",
335335
* operationId="deleteRegion",
336336
* @OA\Parameter(
337337
* name="regionId",
338338
* in="path",
339339
* required=true,
340-
* description="ID of the region to delete",
340+
* description="ID of the subnational to delete",
341341
* @OA\Schema(type="integer", format="int64")
342342
* ),
343343
* @OA\Response(
@@ -355,7 +355,7 @@ public function deleteRegion($regionId)
355355
$region = Region::find($regionId);
356356

357357
if (empty($region)) {
358-
return response()->json([ 'error_message' => 'No region found', 'errors' => []], 404);
358+
return response()->json([ 'error_message' => 'No subnational found', 'errors' => []], 404);
359359
}
360360

361361
$keys = $region->translations()->pluck('id')->toArray();
@@ -368,9 +368,9 @@ public function deleteRegion($regionId)
368368

369369
/**
370370
* @OA\Delete(
371-
* path="/regions/region/translation/{translationId}",
371+
* path="/subnationals/subnational/translation/{translationId}",
372372
* tags={"Regions"},
373-
* summary="Delete a region translation",
373+
* summary="Delete a subnational translation",
374374
* operationId="deleteTranslation",
375375
* @OA\Parameter(
376376
* name="translationId",

app/Http/Controllers/UsageLogController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,10 @@ public function getForApplication(int $applicationId)
314314
* @OA\Schema(type="string")
315315
* ),
316316
* @OA\Parameter(
317-
* name="region",
317+
* name="subnational",
318318
* in="query",
319319
* required=false,
320-
* description="Filter by region ID",
320+
* description="Filter by subnational ID",
321321
* @OA\Schema(type="integer")
322322
* ),
323323
* @OA\Parameter(
@@ -355,7 +355,7 @@ public function getTotals(Request $request)
355355
{
356356
$this->validate($request, [
357357
'society' => 'sometimes|string',
358-
'region' => 'sometimes|int',
358+
'subnational' => 'sometimes|int',
359359
'hazard' => 'sometimes|string',
360360
'date' => 'sometimes|date',
361361
'language' => 'sometimes|string',
@@ -368,8 +368,8 @@ public function getTotals(Request $request)
368368
if (isset($request->society)) {
369369
$query->where('endpoint', 'v1/org/'.$request->society.'/whatnow');
370370
}
371-
if (isset($request->region)) {
372-
$query->where('region', $request->region);
371+
if (isset($request->subnational)) {
372+
$query->where('subnational', $request->subnational);
373373
}
374374
if (isset($request->hazard)) {
375375
$query->where('event_type', 'like', '%' . $request->hazard . '%');

app/Http/Controllers/WhatNowController.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,10 @@ public function deleteById($id)
271271
* @OA\Schema(type="string")
272272
* ),
273273
* @OA\Parameter(
274-
* name="region",
274+
* name="subnational",
275275
* in="query",
276276
* required=false,
277-
* description="Filter by region slug",
277+
* description="Filter by subnational slug",
278278
* @OA\Schema(type="string")
279279
* ),
280280
* @OA\Parameter(
@@ -313,7 +313,7 @@ public function getFeed(WhatNowFeed $feed, $code)
313313
}
314314
$feed->setOrganisation($org);
315315

316-
$regName = $this->request->query('region', null);
316+
$regName = $this->request->query('subnational', null);
317317
if ($regName) {
318318
try {
319319
$reg = $this->regionRepo->findBySlug($org->id, $regName);
@@ -412,9 +412,9 @@ public function getLatestForCountryCode($code)
412412
*/
413413
/**
414414
* @OA\Get(
415-
* path="/org/{code}/{region}/whatnow/revisions/latest",
415+
* path="/org/{code}/{subnational}/whatnow/revisions/latest",
416416
* tags={"Whatnow"},
417-
* summary="Get the latest revisions for a specific region",
417+
* summary="Get the latest revisions for a specific subnational",
418418
* operationId="getLatestForRegion",
419419
* @OA\Parameter(
420420
* name="code",
@@ -424,7 +424,7 @@ public function getLatestForCountryCode($code)
424424
* @OA\Schema(type="string")
425425
* ),
426426
* @OA\Parameter(
427-
* name="region",
427+
* name="subnational",
428428
* in="path",
429429
* required=true,
430430
* description="Region slug to fetch the latest revisions for",
@@ -451,7 +451,7 @@ public function getLatestForRegion($code, $region)
451451
}
452452

453453
try {
454-
$region = $org->regions()->where('slug', str_slug($region))->firstOrFail();
454+
$region = $org->subnationals()->where('slug', str_slug($region))->firstOrFail();
455455
} catch (\Exception $e) {
456456
Log::error('Organisation not found', ['message' => $e->getMessage()]);
457457

@@ -507,7 +507,7 @@ public function getAllRevisions()
507507
* required={"countryCode", "eventType", "translations"},
508508
* @OA\Property(property="countryCode", type="string", example="USA", description="Country code (3 characters)"),
509509
* @OA\Property(property="eventType", type="string", example="Flood", description="Type of event (max 50 characters)"),
510-
* @OA\Property(property="regionName", type="string", example="North Region", description="Name of the region (optional)"),
510+
* @OA\Property(property="regionName", type="string", example="North Region", description="Name of the subnational (optional)"),
511511
* @OA\Property(
512512
* property="translations",
513513
* type="array",
@@ -574,7 +574,7 @@ public function post()
574574
return response()->json([
575575
'status' => 500,
576576
'error_message' => 'Unable to create item',
577-
'errors' => ['No matching region for country code'],
577+
'errors' => ['No matching subnational for country code'],
578578
], 500);
579579
}
580580
}
@@ -642,7 +642,7 @@ public function post()
642642
* required={"countryCode", "eventType", "translations"},
643643
* @OA\Property(property="countryCode", type="string", example="USA", description="Country code (3 characters)"),
644644
* @OA\Property(property="eventType", type="string", example="Flood", description="Type of event (max 50 characters)"),
645-
* @OA\Property(property="regionName", type="string", example="North Region", description="Name of the region (optional)"),
645+
* @OA\Property(property="regionName", type="string", example="North Region", description="Name of the subnational (optional)"),
646646
* @OA\Property(
647647
* property="translations",
648648
* type="array",
@@ -718,7 +718,7 @@ public function putById($id)
718718
return response()->json([
719719
'status' => 500,
720720
'error_message' => 'Unable to create item',
721-
'errors' => ['No matching region for country code'],
721+
'errors' => ['No matching subnational for country code'],
722722
], 500);
723723
}
724724
}

app/Http/Middleware/ApiAuthMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function handle($request, Closure $next)
3131
$usageLog->timestamp = Carbon::now()->toDateTimeString();
3232
$usageLog->code_status = 200;
3333
$usageLog->language = $request->input('language', false) ? $request->input('language', null) : $request->header('Accept-Language', null);
34-
$usageLog->region = $request->input('region', null);
34+
$usageLog->subnational = $request->input('subnational', null);
3535
$usageLog->event_type = $request->input('eventType', null);
3636
$usageLog->save();
3737
$request->usageLog=$usageLog;

app/Models/Organisation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function details()
3737
return $this->hasMany('App\Models\OrganisationDetails', 'org_id');
3838
}
3939

40-
public function regions()
40+
public function subnationals()
4141
{
4242
return $this->hasMany(Region::class);
4343
}

app/Models/Region.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Region extends Model
1212
*
1313
* @var string
1414
*/
15-
protected $table = 'regions';
15+
protected $table = 'subnationals';
1616

1717
/**
1818
* The attributes that are mass assignable.

app/Models/RegionTranslation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class RegionTranslation extends Model
3838
];
3939

4040

41-
public function region()
41+
public function subnational()
4242
{
4343
return $this->belongsTo(Region::class);
4444
}

app/Models/WhatNowEntity.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function organisation()
100100
/**
101101
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
102102
*/
103-
public function region()
103+
public function subnational()
104104
{
105105
return $this->belongsTo('App\Models\Region', 'region_id', 'id');
106106
}
@@ -111,11 +111,11 @@ public function region()
111111
*/
112112
public function getRegionNameAttribute()
113113
{
114-
if(empty($this->region)){
114+
if(empty($this->subnational)){
115115
return 'National';
116116
}
117117

118-
return $this->region->title;
118+
return $this->subnational->title;
119119
}
120120

121121
/**

0 commit comments

Comments
 (0)