Ejemplo n.º 1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  *
  * @return \Illuminate\Http\Response
  *
  */
 public function store(Request $request)
 {
     // Read subscriber details
     $uuid = $request->json('uuid');
     $latitude = $request->json('latitude');
     $longitude = $request->json('longitude');
     // Validate latitude/longitude
     if (!is_numeric($latitude)) {
         return response()->json(['message' => "Latitude must be a number."], Response::HTTP_BAD_REQUEST);
     }
     if (!is_numeric($longitude)) {
         return response()->json(['message' => "Longitude must be a number."], Response::HTTP_BAD_REQUEST);
     }
     // Check if user is already subscribed
     $repository = SubscriberRepository::getInstance();
     $subscriber = $repository->getByUuid($uuid);
     if (!empty($subscriber)) {
         return response()->json(['message' => "Already subscribed."], Response::HTTP_BAD_REQUEST);
     }
     $subscriber = new Subscriber();
     $subscriber->setUuid($uuid);
     $subscriber->setLatitude(doubleval($latitude));
     $subscriber->setLongitude(doubleval($longitude));
     try {
         $subscriber->save();
     } catch (QueryException $exception) {
         return response()->json(['message' => "Oops, something went wrong."], Response::HTTP_INTERNAL_SERVER_ERROR);
     }
     return response()->json([], Response::HTTP_CREATED);
 }
Ejemplo n.º 2
0
 /**
  * Display the specified resource.
  *
  * @param  int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $repository = AlertQueueRepository::getInstance();
     $subscriberRepository = SubscriberRepository::getInstance();
     // Get subscriber
     $subscriber = $subscriberRepository->getByUuid($id);
     if (empty($subscriber)) {
         return response()->json(['message' => 'Unknown subscriber'], Response::HTTP_BAD_REQUEST);
     }
     $messages = $repository->getForSubscriber($subscriber);
     if (empty($messages)) {
         return response()->json([], Response::HTTP_NO_CONTENT);
     }
     /** @var AlertQueueItem $message */
     foreach ($messages as $message) {
         $message->setNotified(true);
         $message->save();
     }
     return response()->json($messages);
 }