Browse Source

update bulk location, add solving search, and update rest-client

pull/3/head
ibnu 2 years ago
parent
commit
361ac26923
  1. 25
      app/Http/Controllers/PresenceController.php
  2. 6
      rest-client.http

25
app/Http/Controllers/PresenceController.php

@ -18,11 +18,6 @@ class PresenceController extends Controller
$this->validate($request, [ $this->validate($request, [
'user_id' => 'required' 'user_id' => 'required'
]); ]);
// $test = $this->getLoc($request->clock_in_lat, $request->clock_in_lng)->display_name;
// // display_name
// return response()->json(["data"=>$test,'code'=>400], 400);
$checkLocation = $this->checkLocation($request); $checkLocation = $this->checkLocation($request);
$statusBoundary = false; $statusBoundary = false;
@ -276,14 +271,6 @@ class PresenceController extends Controller
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); $dataGet = $builder->get();
$finalData = [];
foreach($dataGet as $data){
// $responseIn = $this->getLoc($clock_in_lat, $clock_in_lng);
// $responseOut = $this->getLoc($clock_in_lat, $clock_in_lng);
$data->clock_in_loc = $responseIn->json()["display_name"];
$data->clock_out_loc = $responseOut->json()["display_name"];
}
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} }
@ -310,17 +297,16 @@ class PresenceController extends Controller
$clock_in_lat = $objRow->clock_in_lat; $clock_in_lat = $objRow->clock_in_lat;
$clock_in_lng = $objRow->clock_in_lng; $clock_in_lng = $objRow->clock_in_lng;
$objRow->clock_in_loc = ""; $objRow->clock_in_loc = "";
if (isset($clock_in_lat) && isset($clock_in_lng)) { if (isset($clock_in_lat) && isset($clock_in_lng)) {
$response = Http::get(config('api.nominatim') . "/reverse?lat=".$clock_in_lat."&lon=".$clock_in_lng."&format=json"); $objRow->clock_in_loc = $this->getLoc($clock_in_lat, $clock_in_lng)->display_name;
$objRow->clock_in_loc = $response->json()["display_name"];
} }
$clock_out_lat = $objRow->clock_out_lat; $clock_out_lat = $objRow->clock_out_lat;
$clock_out_lng = $objRow->clock_out_lng; $clock_out_lng = $objRow->clock_out_lng;
$objRow->clock_out_loc = ""; $objRow->clock_out_loc = "";
if (isset($clock_out_lat) && isset($clock_out_lng)) { if (isset($clock_out_lat) && isset($clock_out_lng) && $clock_out_lng != null) {
$response = Http::get(config('api.nominatim') . "/reverse?lat=".$clock_out_lat."&lon=".$clock_out_lng."&format=json"); $locAddress = $this->getLoc($clock_out_lat, $clock_out_lng);
$objRow->clock_out_loc = $response->json()["display_name"]; $objRow->clock_out_loc = isset($locAddress->display_name) ? $locAddress->display_name : "-";
} }
@ -328,5 +314,6 @@ class PresenceController extends Controller
$presence->clock_out_loc = $objRow->clock_out_loc; $presence->clock_out_loc = $objRow->clock_out_loc;
$presence->save(); $presence->save();
} }
return response()->json(['status'=>'success','message'=>'success update!','code'=>200], 200);
} }
} }

6
rest-client.http

@ -804,10 +804,10 @@ Authorization: Bearer {{token}}
content-type: application/json content-type: application/json
{ {
"clock_in_lat": -6.2622811, "clock_out_lat": -6.2622811,
"clock_in_lng": 106.7881746, "clock_out_lng": 106.7881746,
"clock_time": "2023-02-06T16:40:17+07:00", "clock_time": "2023-02-06T16:40:17+07:00",
"type": "in", "type": "out",
"user_id": 1 "user_id": 1
} }

Loading…
Cancel
Save