Skip to content

Commit

Permalink
fix double events
Browse files Browse the repository at this point in the history
  • Loading branch information
xlcrr committed Sep 15, 2024
1 parent 40866eb commit 0a44b6b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 91 deletions.
2 changes: 0 additions & 2 deletions app/Events/NewCityAdded.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

Expand Down
25 changes: 0 additions & 25 deletions app/Helpers/Post/UploadHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ public function getCountryFromAddressArray (array $addressArray)
['country' => $addressArray["country"] ?? '', 'created_by' => auth()->id()]
);

if ($country->wasRecentlyCreated) {
// Broadcast an event to anyone viewing the Global Map
event(new NewCountryAdded($country->country, $countryCode, now()));
}

return $country;
}

Expand Down Expand Up @@ -62,12 +57,6 @@ public function getStateFromAddressArray (Country $country, array $addressArray)
['created_by' => auth()->id()]
);

if ($state->wasRecentlyCreated)
{
// Broadcast an event to anyone viewing the Global Map
event(new NewStateAdded($stateName, $country->country, now()));
}

return $state;
}

Expand Down Expand Up @@ -96,20 +85,6 @@ public function getCityFromAddressArray (Country $country, State $state, $addres
['created_by' => auth()->id()]
);

if ($city->wasRecentlyCreated)
{
// Broadcast an event to anyone viewing the Global Map
event(new NewCityAdded(
$cityName,
$state->state,
$country->country,
now(),
$city->id,
$lat,
$lon
));
}

return $city;
}

Expand Down
27 changes: 26 additions & 1 deletion app/Http/Controllers/ApiPhotosController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Http\Controllers;

use App\Events\NewCityAdded;
use App\Events\NewCountryAdded;
use App\Events\NewStateAdded;
use GeoHash;
use Carbon\Carbon;
use App\Models\Photo;
Expand Down Expand Up @@ -196,7 +199,29 @@ protected function storePhoto (Request $request): Photo
$city
));

// Move this to redis
// Broadcast an event to anyone viewing the Global Map
// Sends Notification to Twitter & Slack
if ($country->wasRecentlyCreated) {
event(new NewCountryAdded($country->country, $country->shortcode, now()));
}

if ($state->wasRecentlyCreated) {
event(new NewStateAdded($state->state, $country->country, now()));
}

if ($city->wasRecentlyCreated) {
event(new NewCityAdded(
$city->city,
$state->state,
$country->country,
now(),
$city->id,
$lat,
$lon,
$photo->id
));
}

event(new IncrementPhotoMonth(
$country->id,
$state->id,
Expand Down
54 changes: 22 additions & 32 deletions app/Http/Controllers/PhotosController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,35 @@

namespace App\Http\Controllers;

use App\Actions\Photos\AddCustomTagsToPhotoAction;
use App\Actions\Photos\AddTagsToPhotoAction;
use App\Actions\Photos\DeletePhotoAction;
use App\Actions\Photos\GetPreviousCustomTagsAction;
use App\Actions\Locations\UpdateLeaderboardsForLocationAction;
use App\Events\ImageDeleted;
use App\Http\Requests\AddTagsRequest;
use App\Models\Photo;
use App\Models\User\User;

use App\Models\Photo;
use Illuminate\Http\Request;
use App\Events\ImageDeleted;
use App\Events\TagsVerifiedByAdmin;

use App\Helpers\Post\UploadHelper;
use App\Http\Requests\AddTagsRequest;

use App\Actions\Photos\DeletePhotoAction;
use App\Actions\Photos\AddTagsToPhotoAction;
use App\Actions\Photos\AddCustomTagsToPhotoAction;
use App\Actions\Photos\GetPreviousCustomTagsAction;
use App\Actions\Locations\UpdateLeaderboardsForLocationAction;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class PhotosController extends Controller
{
/** @var UploadHelper */
protected $uploadHelper;
/** @var AddTagsToPhotoAction */
private $addTagsAction;
/** @var UpdateLeaderboardsForLocationAction */
private $updateLeaderboardsAction;
/** @var DeletePhotoAction */
private $deletePhotoAction;
protected UploadHelper $uploadHelper;
private AddTagsToPhotoAction $addTagsAction;
private DeletePhotoAction $deletePhotoAction;
private UpdateLeaderboardsForLocationAction $updateLeaderboardsAction;

/**
* PhotosController constructor
* Apply middleware to all of these routes
*
* @param UploadHelper $uploadHelper
* @param AddTagsToPhotoAction $addTagsAction
* @param UpdateLeaderboardsForLocationAction $updateLeaderboardsAction
* @param DeletePhotoAction $deletePhotoAction
*/
public function __construct(
UploadHelper $uploadHelper,
Expand All @@ -57,11 +50,9 @@ public function __construct(
/**
* Delete an image
*/
public function deleteImage(Request $request)
public function deleteImage (Request $request)
{
/** @var User $user */
$user = Auth::user();
/** @var Photo $photo */
$photo = Photo::findOrFail($request->photoid);

if ($user->id !== $photo->user_id) {
Expand All @@ -86,7 +77,7 @@ public function deleteImage(Request $request)
$photo->team_id
));

return ['message' => 'Photo deleted successfully!'];
return response()->json(['message' => 'Photo deleted successfully!']);
}

/**
Expand Down Expand Up @@ -138,18 +129,17 @@ public function addTags (AddTagsRequest $request, AddCustomTagsToPhotoAction $cu

$photo->save();

return [
return response()->json([
'success' => true,
'msg' => 'success'
];
]);
}

/**
* Get unverified photos for tagging
*/
public function unverified (GetPreviousCustomTagsAction $previousTagsAction)
public function unverified (GetPreviousCustomTagsAction $previousTagsAction): JsonResponse
{
/** @var User $user */
$user = Auth::user();

$query = Photo::where([
Expand All @@ -168,11 +158,11 @@ public function unverified (GetPreviousCustomTagsAction $previousTagsAction)

$total = Photo::where('user_id', $user->id)->count();

return [
return response()->json([
'photos' => $photos,
'remaining' => $remaining,
'total' => $total,
'custom_tags' => $previousTagsAction->run($user)
];
]);
}
}
47 changes: 17 additions & 30 deletions app/Http/Controllers/Uploads/UploadPhotoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,37 @@

namespace App\Http\Controllers\Uploads;

use App\Exceptions\InvalidCoordinates;
use Carbon\Carbon;
use Geohash\GeoHash;
use App\Actions\Locations\UpdateLeaderboardsForLocationAction;
use App\Actions\Photos\MakeImageAction;
use App\Actions\Photos\UploadPhotoAction;

use App\Events\NewCityAdded;
use App\Events\NewCountryAdded;
use App\Events\NewStateAdded;
use App\Helpers\Post\UploadHelper;
use Carbon\Carbon;
use App\Models\Photo;
use App\Models\User\User;
use App\Events\ImageUploaded;
use App\Events\Photo\IncrementPhotoMonth;
use App\Http\Requests\UploadPhotoRequest;
use App\Exceptions\InvalidCoordinates;

use App\Actions\Photos\MakeImageAction;
use App\Actions\Photos\UploadPhotoAction;
use App\Actions\Locations\ReverseGeocodeLocationAction;
use App\Actions\Locations\UpdateLeaderboardsForLocationAction;

use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class UploadPhotoController extends Controller
{
/** @var MakeImageAction */
private $makeImageAction;

/** @var UploadPhotoAction */
private $uploadPhotoAction;

/** @var UploadHelper */
protected $uploadHelper;

/** @var UpdateLeaderboardsForLocationAction */
private $updateLeaderboardsAction;
protected UploadHelper $uploadHelper;
private MakeImageAction $makeImageAction;
private UploadPhotoAction $uploadPhotoAction;
private UpdateLeaderboardsForLocationAction $updateLeaderboardsAction;

/**
* Initialise Helper Actions
*
* @param MakeImageAction $makeImageAction
* @param UploadPhotoAction $uploadPhotoAction
* @param UploadHelper $uploadHelper
*/
public function __construct (
MakeImageAction $makeImageAction,
UploadPhotoAction $uploadPhotoAction,
Expand All @@ -67,11 +56,10 @@ public function __construct (
* then persist new record to photos table
*
* @param UploadPhotoRequest $request
* @return array
* @return JsonResponse
*/
public function __invoke (UploadPhotoRequest $request): array
public function __invoke (UploadPhotoRequest $request): JsonResponse
{
/** @var User $user */
$user = Auth::user();

\Log::channel('photos')->info([
Expand Down Expand Up @@ -105,8 +93,7 @@ public function __invoke (UploadPhotoRequest $request): array
if ($exif["GPSLatitude"][0] === "0/0" && $exif["GPSLongitude"][0] === "0/0")
{
abort(500,
"Sorry, Your Images have GeoTags,
but they have values of Zero.
"Sorry, Your Images have GeoTags, but they have values of Zero.
You may have lost the geotags when transferring images across devices."
);
}
Expand Down Expand Up @@ -306,9 +293,9 @@ public function __invoke (UploadPhotoRequest $request): array
$dateTime
));

return [
return response()->json([
'success' => true
];
]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion resources/js/views/general/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
</template>

<script>
import vue2Dropzone from 'vue2-dropzone';
import Vue from 'vue';
import vue2Dropzone from 'vue2-dropzone';
export default {
name: 'Upload',
Expand Down

0 comments on commit 0a44b6b

Please sign in to comment.