public function store()
 {
     //TODO: maybe the name of the device is not needed -> retrieve it from jwt
     $responseObs = $this->validateObservation();
     if ($responseObs->status == 'error') {
         return $responseObs;
     } else {
         $device = Device::where('device_uuid', \Request::get('device_uuid'))->first();
         //first check if the device is registered for this mission to radical
         //for our db, that means that there's a row in devices_missions table
         if (!$this->deviceService->isRegistered(\Request::get('mission_id'), \Request::get('device_uuid'))) {
             if ($this->mission == null) {
                 $this->mission = Mission::find(\Request::get('mission_id'));
             }
             if (!\Request::has('latitude') || \Request::get('latitude') == '') {
                 $latitude = number_format(0, 6);
             } else {
                 $latitude = number_format(\Request::get('latitude'), 6);
             }
             if (!\Request::has('longitude') || \Request::get('longitude') == '') {
                 $longitude = number_format(0, 6);
             } else {
                 $longitude = number_format(\Request::get('longitude'), 6);
             }
             //first create a row in devices_missions table
             $device->missions()->attach($this->mission->id, ['device_uuid' => env('RADICAL_CITYNAME') . '.' . $this->mission->radical_service_id . '.' . $device->device_uuid, 'latitude' => $latitude, 'longitude' => $longitude, 'registration_date' => date('Y-m-d H:i:s')]);
             $this->mission->users()->attach(\Auth::user()->id);
             //then send data to radical api
             $tmp_device = ['Device_UUID' => env('RADICAL_CITYNAME') . '.' . $this->mission->radical_service_id . '.' . $device->device_uuid, 'Model' => $device->model, 'Manufacturer' => $device->manufacturer, 'Latitude' => $latitude, 'Longitude' => $longitude, 'Type' => $device->type, 'Status' => intval($device->status), 'Registration_Date' => date('Y-m-d H:i:s')];
             $this->deviceService->registerToRadical($tmp_device);
         }
         $responseMeas = $this->validateMeasurements(\Request::get('measurements'));
         if ($responseMeas->status == 'error') {
             return \Response::json($responseMeas);
         }
         if ($this->mission == null) {
             $this->mission = Mission::find(\Request::get('mission_id'));
         }
         $observation = new Observation(['device_uuid' => env('RADICAL_CITYNAME') . '.' . $this->mission->radical_service_id . '.' . $device->device_uuid, 'latitude' => \Request::get('latitude'), 'longitude' => \Request::get('longitude'), 'observation_date' => \Request::get('observation_date'), 'device_id' => $device->id]);
         //save new observation to the db
         $observation->save();
         $radicalMeasurements = $this->getMeasurements($observation->id);
         $radicalObservation = ['Device_UUID' => env('RADICAL_CITYNAME') . '.' . $this->mission->radical_service_id . '.' . $device->device_uuid, 'Latitude' => \Request::get('latitude'), 'Longitude' => \Request::get('longitude'), 'Observation_Date' => \Request::get('observation_date'), 'Measurements' => $radicalMeasurements];
         $this->radicalIntegrationManager->storeObservation($radicalObservation);
         return $observation;
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\JsonResponse
  *
  * @SWG\Get(
  *     summary="Get all observations",
  *     path="/missions",
  *     description="Retrieve all the oservations.",
  *     operationId="api.observations",
  *     produces={"application/json"},
  *     tags={"observations"},
  *     @SWG\Response(
  *         response=200,
  *         description="Returns all the observations of the application"
  *     ),
  *     @SWG\Response(
  *         response=400,
  *         description="Unauthorized action",
  *     )
  * )
  */
 public function index()
 {
     $observations = Observation::get();
     $response = new ApiResponse();
     $response->status = 'success';
     $response->message = ['observations' => $observations];
     return \Response::json($response);
 }