Skip to content

Commit

Permalink
App: Helpers: Misc updates
Browse files Browse the repository at this point in the history
- AppHelper
	* Introduce new way to generate UUID to avoid any possibility duplicate
	on foreign or primary table
- NotificationHelper
	* Reflected re-factoring

Signed-off-by: Dicky Herlambang (花) <herlambangdicky5@gmail.com>
  • Loading branch information
Nicklas373 committed Nov 5, 2024
1 parent 8c38b1f commit 41c7848
Show file tree
Hide file tree
Showing 2 changed files with 261 additions and 314 deletions.
38 changes: 33 additions & 5 deletions app/Helpers/AppHelper.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php
namespace App\Helpers;

use Illuminate\Support\Str;
use App\Models\appLogModel;
use App\Models\notifyLogModel;
use Carbon\Carbon;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Ramsey\Uuid\Uuid;

class AppHelper
{
Expand Down Expand Up @@ -93,13 +97,37 @@ function getGitCommitHash()
return substr($hash, 0, 7);
}

function get_guid() {
$guid = Str::uuid();
return $guid;
function generateSingleUniqueUuid($customModel, $customColumn) {
$startProc = Carbon::now()->format('Y-m-d H:i:s');
// $uniqueID = Uuid::uuid4(); --> Need to know how to avoid unrelated relation on first migration !
do {
$uniqueID = Uuid::uuid4();
} while (
$customModel::where($customColumn, $uniqueID)->exists()
);
$end = Carbon::now();
$duration = $end->diffInSeconds(Carbon::parse($startProc));
Log::Info('New single unique UUID has been generated with response time: '.$duration.' seconds');
return $uniqueID->toString();
}

function generateUniqueUuid($customModel, $customColumn) {
$startProc = Carbon::now()->format('Y-m-d H:i:s');
// $uniqueID = Uuid::uuid4(); --> Need to know how to avoid unrelated relation on first migration !
do {
$uniqueID = Uuid::uuid4();
} while (
appLogModel::where($customColumn, $uniqueID)->exists() ||
$customModel::where($customColumn, $uniqueID)->exists()
);
$end = Carbon::now();
$duration = $end->diffInSeconds(Carbon::parse($startProc));
Log::Info('New unique UUID has been generated with response time: '.$duration.' seconds');
return $uniqueID->toString();
}

public static function instance()
{
return new AppHelper();
}
}
}
Loading

0 comments on commit 41c7848

Please sign in to comment.