Skip to content

Commit

Permalink
fix incr xp
Browse files Browse the repository at this point in the history
  • Loading branch information
xlcrr committed Sep 18, 2024
1 parent fbe160b commit 9790402
Show file tree
Hide file tree
Showing 63 changed files with 273 additions and 258 deletions.
14 changes: 10 additions & 4 deletions app/Actions/Locations/UpdateLeaderboardsXpAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ public function run (
$this->addXp("leaderboard:users:$year", $incrXp, $userId);
}

protected function addXp ($key, $xp, $userId) {
$currentScore = Redis::zscore($key, $userId) ?? 0;
$newScore = max(0, $currentScore + $xp);
Redis::zadd($key, $newScore, $userId);
protected function addXp ($key, $xp, $userId): void {
if ($xp <= 0) {
$currentScore = Redis::zscore($key, $userId) ?? 0;
$newScore = max(0, $currentScore + $xp);

Redis::zincrby($key, $newScore, $userId);
} else {

Redis::zincrby($key, $xp, $userId);
}
}
}
6 changes: 4 additions & 2 deletions app/Actions/Locations/UpdateTotalPhotosForLocationAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class UpdateTotalPhotosForLocationAction
* @param string $stateId State
* @param string $cityId City
* @param int $increaseBy can be negative, value will be subtracted, but not below 0
* @return void
*/
public function run(string $countryId, string $stateId, string $cityId, int $increaseBy = 1)
public function run (string $countryId, string $stateId, string $cityId, int $increaseBy = 1): void
{
$this->updateValue("country:$countryId", $increaseBy);

Expand All @@ -33,8 +34,9 @@ public function run(string $countryId, string $stateId, string $cityId, int $inc
*
* @param $hashName
* @param $value
* @return void
*/
protected function updateValue($hashName, $value)
protected function updateValue ($hashName, $value): void
{
// Separate if conditions to skip redis check when $value is positive
if ($value < 0) {
Expand Down
17 changes: 12 additions & 5 deletions app/Http/Controllers/Uploads/UploadPhotoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public function __invoke (UploadPhotoRequest $request): JsonResponse
'user_id' => $user->id
]);

if (!$user->has_uploaded) $user->has_uploaded = 1;
if (!$user->has_uploaded) {
$user->has_uploaded = 1;
}

$file = $request->file('file'); // /tmp/php7S8v..

Expand All @@ -94,8 +96,9 @@ public function __invoke (UploadPhotoRequest $request): JsonResponse
if ($exif["GPSLatitude"][0] === "0/0" && $exif["GPSLongitude"][0] === "0/0")
{
abort(500,
"Sorry, Your Images have GeoTags, but they have values of Zero.
You may have lost the geotags when transferring images across devices."
"Error: Your Images have GeoTags, but they have values of zero.
You may have lost the geotags when transferring images across devices
or you might need to enable another setting to make them available."
);
}

Expand Down Expand Up @@ -169,7 +172,11 @@ public function __invoke (UploadPhotoRequest $request): JsonResponse
if (($latitude === 0 && $longitude === 0) || ($latitude === '0' && $longitude === '0'))
{
\Log::info("invalid coordinates found for userId $user->id \n");
abort(500, "Invalid coordinates: lat=0, lon=0");
abort(500,
"Error: Your Images have GeoTags, but they have values of zero.
You may have lost the geotags when transferring images across devices
or you might need to enable another setting to make them available."
);
}

// Use OpenStreetMap to Reverse Geocode the coordinates into an Address.
Expand Down Expand Up @@ -239,7 +246,7 @@ public function __invoke (UploadPhotoRequest $request): JsonResponse

$user->refresh();

// Update the Leaderboards
// Update the Leaderboards and give xp.
$this->updateLeaderboardsAction->run(
$photo,
$user->id,
Expand Down
8 changes: 4 additions & 4 deletions app/Listeners/Teams/IncreaseTeamTotalPhotos.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace App\Listeners\Teams;

use App\Events\ImageUploaded;
use App\Models\Teams\Team;
use App\Models\User\User;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Models\Teams\Team;
use App\Events\ImageUploaded;
use Illuminate\Support\Facades\DB;
use Illuminate\Contracts\Queue\ShouldQueue;

class IncreaseTeamTotalPhotos implements ShouldQueue
{
Expand All @@ -21,7 +21,7 @@ class IncreaseTeamTotalPhotos implements ShouldQueue
* @param ImageUploaded $event
* @return void
*/
public function handle(ImageUploaded $event)
public function handle (ImageUploaded $event): void
{
if (!$event->teamId) {
return;
Expand Down

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9790402

Please sign in to comment.