Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Classes/Feeds/WhatNowFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function setOrganisation(Organisation $org)
*/
public function setRegion(Region $region = null)
{
$this->region = $region;
$this->subnational = $region;
return $this;
}

Expand Down Expand Up @@ -134,7 +134,7 @@ public function loadData()
$this->organisation->id,
$this->language,
$this->filterEventTypes,
$this->region->id ?? null
$this->subnational->id ?? null
);

if ($data instanceof Collection) {
Expand Down
2 changes: 1 addition & 1 deletion app/Classes/Transformers/WhatNowEntityTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function transform(WhatNowEntity $model)
'countryCode' => $model->organisation->country_code,
'eventType' => $model->event_type,
'regionName' => $model->region_name,
'region' => $model->region,
'subnational' => $model->subnational,
'attribution' => [
'name' => $model->organisation->org_name,
'countryCode' => $model->organisation->country_code,
Expand Down
50 changes: 25 additions & 25 deletions app/Http/Controllers/RegionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ public function __construct(

/**
* @OA\Post(
* path="/regions",
* path="/subnationals",
* tags={"Regions"},
* summary="Create a new region",
* summary="Create a new subnational",
* operationId="createRegion",
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* required={"countryCode", "title"},
* @OA\Property(property="countryCode", type="string", example="USA", description="Country code (3 characters)"),
* @OA\Property(property="title", type="string", example="North America", description="Title of the region"),
* @OA\Property(property="slug", type="string", example="north-america", description="Slug for the region (optional)"),
* @OA\Property(property="title", type="string", example="North America", description="Title of the subnational"),
* @OA\Property(property="slug", type="string", example="north-america", description="Slug for the subnational (optional)"),
* @OA\Property(
* property="translations",
* type="array",
Expand All @@ -58,7 +58,7 @@ public function __construct(
* @OA\Property(property="webUrl", type="string", format="url", example="https://example.com", description="Web URL for the translation"),
* @OA\Property(property="lang", type="string", example="en", description="Language code (2 characters)"),
* @OA\Property(property="title", type="string", example="North America", description="Title in the specified language"),
* @OA\Property(property="description", type="string", example="Description of the region", description="Description in the specified language")
* @OA\Property(property="description", type="string", example="Description of the subnational", description="Description in the specified language")
* )
* )
* )
Expand Down Expand Up @@ -103,10 +103,10 @@ public function createRegion(Request $request)
}

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

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

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

/**
* @OA\Put(
* path="/regions/region/{regionId}",
* path="/subnationals/subnational/{regionId}",
* tags={"Regions"},
* summary="Update an existing region",
* summary="Update an existing subnational",
* operationId="updateRegion",
* @OA\Parameter(
* name="regionId",
* in="path",
* required=true,
* description="ID of the region to update",
* description="ID of the subnational to update",
* @OA\Schema(type="integer", format="int64")
* ),
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* @OA\Property(property="title", type="string", example="Updated Region Title", description="Updated title of the region (optional)"),
* @OA\Property(property="slug", type="string", example="updated-region-slug", description="Updated slug for the region (optional)"),
* @OA\Property(property="title", type="string", example="Updated Region Title", description="Updated title of the subnational (optional)"),
* @OA\Property(property="slug", type="string", example="updated-subnational-slug", description="Updated slug for the subnational (optional)"),
* @OA\Property(
* property="translations",
* type="array",
Expand Down Expand Up @@ -172,7 +172,7 @@ public function updateRegion(Request $request, $regionId)
$region = Region::find($regionId);

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

$this->validate($request, [
Expand Down Expand Up @@ -216,8 +216,8 @@ public function updateRegion(Request $request, $regionId)

/**
* @OA\Get(
* path="/regions/{country_code}",
* summary="Get all regions for a specific organisation by country code",
* path="/subnationals/{country_code}",
* summary="Get all subnationals for a specific organisation by country code",
* tags={"Regions"},
* @OA\Parameter(
* name="country_code",
Expand Down Expand Up @@ -248,7 +248,7 @@ public function getAllForOrganisation($country_code)
}

$list = [];
foreach ($organisation->regions as $region) {
foreach ($organisation->subnationals as $region) {
$data = [
'id' => $region->id,
'title' => $region->title,
Expand All @@ -270,8 +270,8 @@ public function getAllForOrganisation($country_code)

/**
* @OA\Get(
* path="/regions/{country_code}/{code}",
* summary="Get regions for a specific organisation by country code and language code",
* path="/subnationals/{country_code}/{code}",
* summary="Get subnationals for a specific organisation by country code and language code",
* tags={"Regions"},
* @OA\Parameter(
* name="country_code",
Expand Down Expand Up @@ -309,7 +309,7 @@ public function getForCountryCode($country_code, $code)
}

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

/**
* @OA\Delete(
* path="/regions/region/{regionId}",
* path="/subnationals/subnational/{regionId}",
* tags={"Regions"},
* summary="Delete a region",
* summary="Delete a subnational",
* operationId="deleteRegion",
* @OA\Parameter(
* name="regionId",
* in="path",
* required=true,
* description="ID of the region to delete",
* description="ID of the subnational to delete",
* @OA\Schema(type="integer", format="int64")
* ),
* @OA\Response(
Expand All @@ -355,7 +355,7 @@ public function deleteRegion($regionId)
$region = Region::find($regionId);

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

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

/**
* @OA\Delete(
* path="/regions/region/translation/{translationId}",
* path="/subnationals/subnational/translation/{translationId}",
* tags={"Regions"},
* summary="Delete a region translation",
* summary="Delete a subnational translation",
* operationId="deleteTranslation",
* @OA\Parameter(
* name="translationId",
Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/UsageLogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@ public function getForApplication(int $applicationId)
* @OA\Schema(type="string")
* ),
* @OA\Parameter(
* name="region",
* name="subnational",
* in="query",
* required=false,
* description="Filter by region ID",
* description="Filter by subnational ID",
* @OA\Schema(type="integer")
* ),
* @OA\Parameter(
Expand Down Expand Up @@ -355,7 +355,7 @@ public function getTotals(Request $request)
{
$this->validate($request, [
'society' => 'sometimes|string',
'region' => 'sometimes|int',
'subnational' => 'sometimes|int',
'hazard' => 'sometimes|string',
'date' => 'sometimes|date',
'language' => 'sometimes|string',
Expand All @@ -368,8 +368,8 @@ public function getTotals(Request $request)
if (isset($request->society)) {
$query->where('endpoint', 'v1/org/'.$request->society.'/whatnow');
}
if (isset($request->region)) {
$query->where('region', $request->region);
if (isset($request->subnational)) {
$query->where('subnational', $request->subnational);
}
if (isset($request->hazard)) {
$query->where('event_type', 'like', '%' . $request->hazard . '%');
Expand Down
22 changes: 11 additions & 11 deletions app/Http/Controllers/WhatNowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ public function deleteById($id)
* @OA\Schema(type="string")
* ),
* @OA\Parameter(
* name="region",
* name="subnational",
* in="query",
* required=false,
* description="Filter by region slug",
* description="Filter by subnational slug",
* @OA\Schema(type="string")
* ),
* @OA\Parameter(
Expand Down Expand Up @@ -313,7 +313,7 @@ public function getFeed(WhatNowFeed $feed, $code)
}
$feed->setOrganisation($org);

$regName = $this->request->query('region', null);
$regName = $this->request->query('subnational', null);
if ($regName) {
try {
$reg = $this->regionRepo->findBySlug($org->id, $regName);
Expand Down Expand Up @@ -412,9 +412,9 @@ public function getLatestForCountryCode($code)
*/
/**
* @OA\Get(
* path="/org/{code}/{region}/whatnow/revisions/latest",
* path="/org/{code}/{subnational}/whatnow/revisions/latest",
* tags={"Whatnow"},
* summary="Get the latest revisions for a specific region",
* summary="Get the latest revisions for a specific subnational",
* operationId="getLatestForRegion",
* @OA\Parameter(
* name="code",
Expand All @@ -424,7 +424,7 @@ public function getLatestForCountryCode($code)
* @OA\Schema(type="string")
* ),
* @OA\Parameter(
* name="region",
* name="subnational",
* in="path",
* required=true,
* description="Region slug to fetch the latest revisions for",
Expand All @@ -451,7 +451,7 @@ public function getLatestForRegion($code, $region)
}

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

Expand Down Expand Up @@ -507,7 +507,7 @@ public function getAllRevisions()
* required={"countryCode", "eventType", "translations"},
* @OA\Property(property="countryCode", type="string", example="USA", description="Country code (3 characters)"),
* @OA\Property(property="eventType", type="string", example="Flood", description="Type of event (max 50 characters)"),
* @OA\Property(property="regionName", type="string", example="North Region", description="Name of the region (optional)"),
* @OA\Property(property="regionName", type="string", example="North Region", description="Name of the subnational (optional)"),
* @OA\Property(
* property="translations",
* type="array",
Expand Down Expand Up @@ -574,7 +574,7 @@ public function post()
return response()->json([
'status' => 500,
'error_message' => 'Unable to create item',
'errors' => ['No matching region for country code'],
'errors' => ['No matching subnational for country code'],
], 500);
}
}
Expand Down Expand Up @@ -642,7 +642,7 @@ public function post()
* required={"countryCode", "eventType", "translations"},
* @OA\Property(property="countryCode", type="string", example="USA", description="Country code (3 characters)"),
* @OA\Property(property="eventType", type="string", example="Flood", description="Type of event (max 50 characters)"),
* @OA\Property(property="regionName", type="string", example="North Region", description="Name of the region (optional)"),
* @OA\Property(property="regionName", type="string", example="North Region", description="Name of the subnational (optional)"),
* @OA\Property(
* property="translations",
* type="array",
Expand Down Expand Up @@ -718,7 +718,7 @@ public function putById($id)
return response()->json([
'status' => 500,
'error_message' => 'Unable to create item',
'errors' => ['No matching region for country code'],
'errors' => ['No matching subnational for country code'],
], 500);
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/ApiAuthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function handle($request, Closure $next)
$usageLog->timestamp = Carbon::now()->toDateTimeString();
$usageLog->code_status = 200;
$usageLog->language = $request->input('language', false) ? $request->input('language', null) : $request->header('Accept-Language', null);
$usageLog->region = $request->input('region', null);
$usageLog->subnational = $request->input('subnational', null);
$usageLog->event_type = $request->input('eventType', null);
$usageLog->save();
$request->usageLog=$usageLog;
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Organisation.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function details()
return $this->hasMany('App\Models\OrganisationDetails', 'org_id');
}

public function regions()
public function subnationals()
{
return $this->hasMany(Region::class);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Region extends Model
*
* @var string
*/
protected $table = 'regions';
protected $table = 'subnationals';

/**
* The attributes that are mass assignable.
Expand Down
2 changes: 1 addition & 1 deletion app/Models/RegionTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RegionTranslation extends Model
];


public function region()
public function subnational()
{
return $this->belongsTo(Region::class);
}
Expand Down
6 changes: 3 additions & 3 deletions app/Models/WhatNowEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function organisation()
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function region()
public function subnational()
{
return $this->belongsTo('App\Models\Region', 'region_id', 'id');
}
Expand All @@ -111,11 +111,11 @@ public function region()
*/
public function getRegionNameAttribute()
{
if(empty($this->region)){
if(empty($this->subnational)){
return 'National';
}

return $this->region->title;
return $this->subnational->title;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/Models/WhatNowEntityTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ public function errors()

// public function getRegionNameAttribute()
// {
// if(empty($this->entity->region)){
// if(empty($this->entity->subnational)){
// return '';
// }
//
// return $this->entity->region->title;
// return $this->entity->subnational->title;
// }

/**
Expand Down
2 changes: 1 addition & 1 deletion config/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
'driver' => 'dynamodb',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
'subnational' => env('AWS_DEFAULT_REGION', 'us-east-1'),
'table' => env('DYNAMODB_CACHE_TABLE', 'cache'),
'endpoint' => env('DYNAMODB_ENDPOINT'),
],
Expand Down
2 changes: 1 addition & 1 deletion config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'subnational' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
Expand Down
Loading
Loading