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
70 changes: 0 additions & 70 deletions app/Console/Commands/GpsCommand.php

This file was deleted.

65 changes: 57 additions & 8 deletions app/Http/Controllers/ApiV1/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class IndexController extends Controller
{

public function Index(Request $request, $cp3, $cp4)
{
$results = DB::table('ctt')
Expand All @@ -25,18 +25,23 @@ public function Index(Request $request, $cp3, $cp4)
['ctt.cp3', '=', $cp3],
])->get();

return response()->json($results);
$data = [];
foreach($results as $result) {
$data[] = $this->normalizeData($result);
}

return response()->json($data);
}


public function Random()
{
$id = DB::table('ctt')
->select('id')
->inRandomOrder()
->first();

$results = DB::table('ctt')
$result = DB::table('ctt')
->leftJoin('districts', 'ctt.district_id', '=', 'districts.district_id')
->leftJoin('locations', 'ctt.location_id', '=', 'locations.location_id')
->leftJoin('municipalities', function ($join) {
Expand All @@ -46,8 +51,52 @@ public function Random()
->select('locations.name', 'districts.name AS district', 'municipalities.name AS municipality', 'ctt.*')
->where('ctt.id', $id->id)->first();

return response()->json($results);
return response()->json($this->normalizeData($result));
}

}


protected function normalizeData($result)
{
$fullAddress = [];
if(!empty(trim($result->art_tipo))) {
$fullAddress[] = trim($result->art_tipo);
}

if(!empty(trim($result->pri_prep))) {
$fullAddress[] = trim($result->pri_prep);
}

if(!empty(trim($result->art_titulo))) {
$fullAddress[] = trim($result->art_titulo);
}

if(!empty(trim($result->seg_prep))) {
$fullAddress[] = trim($result->seg_prep);
}

if(!empty(trim($result->art_desig))) {
$fullAddress[] = trim($result->art_desig);
}

if(!empty(trim($result->porta))) {
$fullAddress[] = ', '.trim($result->porta);
}

return [
'locationName' => trim($result->name),
'fullAddress' => implode(' ', $fullAddress),
'zone' => trim($result->art_local),
'section' => trim($result->troco),
'doorNumber' => trim($result->porta),
'clientName' => trim($result->cliente),
'cp4' => trim($result->cp4),
'cp3' => trim($result->cp3),
'cpalf' => trim($result->cpalf),
'districtName' => trim($result->district),
'municipalityName' => trim($result->municipality),
'latitude' => $result->latitude,
'longitude' => $result->longitude,
];
}

}
18 changes: 0 additions & 18 deletions app/Http/Controllers/ExampleController.php

This file was deleted.

20 changes: 0 additions & 20 deletions app/Http/Middleware/ExampleMiddleware.php

This file was deleted.

28 changes: 11 additions & 17 deletions resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
padding: 3rem 1.5rem;
text-align: center;
}
.label {
color:#145222
}
</style>
</head>
<body>
Expand All @@ -31,26 +34,17 @@
<p><pre>
[
{
"name": "Lisboa",
"district": "Lisboa",
"municipality": "Lisboa",
"id": 136883,
"location_id": 21696,
"municipality_id": 6,
"district_id": 11,
"art_cod": "300460611",
"art_tipo": "Rossio",
"pri_prep": "dos",
"art_titulo": "",
"seg_prep": "",
"art_desig": "Olivais",
"art_local": "",
"troco": "",
"porta": "",
"cliente": "",
"locationName": "Lisboa",
"fullAddress": "Rossio dos Olivais",
"zone": "",
"section": "",
"doorNumber": "",
"clientName": "",
"cp4": "1990",
"cp3": "231",
"cpalf": "LISBOA",
"districtName": "Lisboa",
"municipalityName": "Lisboa",
"latitude": null,
"longitude": null
}
Expand Down