Skip to content

Commit 413f4c0

Browse files
authored
Merge pull request #4 from tuxonice/task-readme-update
Update documentation
2 parents b80a5e8 + fccdd2d commit 413f4c0

File tree

5 files changed

+68
-133
lines changed

5 files changed

+68
-133
lines changed

app/Console/Commands/GpsCommand.php

Lines changed: 0 additions & 70 deletions
This file was deleted.

app/Http/Controllers/ApiV1/IndexController.php

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class IndexController extends Controller
1111
{
12-
12+
1313
public function Index(Request $request, $cp3, $cp4)
1414
{
1515
$results = DB::table('ctt')
@@ -25,18 +25,23 @@ public function Index(Request $request, $cp3, $cp4)
2525
['ctt.cp3', '=', $cp3],
2626
])->get();
2727

28-
return response()->json($results);
28+
$data = [];
29+
foreach($results as $result) {
30+
$data[] = $this->normalizeData($result);
31+
}
32+
33+
return response()->json($data);
2934
}
30-
31-
35+
36+
3237
public function Random()
3338
{
3439
$id = DB::table('ctt')
3540
->select('id')
3641
->inRandomOrder()
3742
->first();
3843

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

49-
return response()->json($results);
54+
return response()->json($this->normalizeData($result));
5055
}
51-
52-
}
5356

57+
58+
protected function normalizeData($result)
59+
{
60+
$fullAddress = [];
61+
if(!empty(trim($result->art_tipo))) {
62+
$fullAddress[] = trim($result->art_tipo);
63+
}
64+
65+
if(!empty(trim($result->pri_prep))) {
66+
$fullAddress[] = trim($result->pri_prep);
67+
}
68+
69+
if(!empty(trim($result->art_titulo))) {
70+
$fullAddress[] = trim($result->art_titulo);
71+
}
72+
73+
if(!empty(trim($result->seg_prep))) {
74+
$fullAddress[] = trim($result->seg_prep);
75+
}
76+
77+
if(!empty(trim($result->art_desig))) {
78+
$fullAddress[] = trim($result->art_desig);
79+
}
80+
81+
if(!empty(trim($result->porta))) {
82+
$fullAddress[] = ', '.trim($result->porta);
83+
}
84+
85+
return [
86+
'locationName' => trim($result->name),
87+
'fullAddress' => implode(' ', $fullAddress),
88+
'zone' => trim($result->art_local),
89+
'section' => trim($result->troco),
90+
'doorNumber' => trim($result->porta),
91+
'clientName' => trim($result->cliente),
92+
'cp4' => trim($result->cp4),
93+
'cp3' => trim($result->cp3),
94+
'cpalf' => trim($result->cpalf),
95+
'districtName' => trim($result->district),
96+
'municipalityName' => trim($result->municipality),
97+
'latitude' => $result->latitude,
98+
'longitude' => $result->longitude,
99+
];
100+
}
101+
102+
}

app/Http/Controllers/ExampleController.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

app/Http/Middleware/ExampleMiddleware.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

resources/views/index.blade.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
padding: 3rem 1.5rem;
1616
text-align: center;
1717
}
18+
.label {
19+
color:#145222
20+
}
1821
</style>
1922
</head>
2023
<body>
@@ -31,26 +34,17 @@
3134
<p><pre>
3235
[
3336
{
34-
"name": "Lisboa",
35-
"district": "Lisboa",
36-
"municipality": "Lisboa",
37-
"id": 136883,
38-
"location_id": 21696,
39-
"municipality_id": 6,
40-
"district_id": 11,
41-
"art_cod": "300460611",
42-
"art_tipo": "Rossio",
43-
"pri_prep": "dos",
44-
"art_titulo": "",
45-
"seg_prep": "",
46-
"art_desig": "Olivais",
47-
"art_local": "",
48-
"troco": "",
49-
"porta": "",
50-
"cliente": "",
37+
"locationName": "Lisboa",
38+
"fullAddress": "Rossio dos Olivais",
39+
"zone": "",
40+
"section": "",
41+
"doorNumber": "",
42+
"clientName": "",
5143
"cp4": "1990",
5244
"cp3": "231",
5345
"cpalf": "LISBOA",
46+
"districtName": "Lisboa",
47+
"municipalityName": "Lisboa",
5448
"latitude": null,
5549
"longitude": null
5650
}

0 commit comments

Comments
 (0)