Skip to content

Commit

Permalink
fix(console): updates caching logic for provinces and cities
Browse files Browse the repository at this point in the history
  • Loading branch information
rizkyilhampra committed Nov 20, 2024
1 parent 0d6fecd commit 2530a65
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 34 deletions.
24 changes: 8 additions & 16 deletions app/Console/Commands/RecachingCities.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,24 @@

namespace App\Console\Commands;

use App\Http\Controllers\Admin\BerandaController;
use App\Http\Controllers\KotaProvinsiController;
use App\Models\UserProfile;
use Illuminate\Console\Command;

class RecachingCities extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'cache:cities';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Recache cities data for chart from RajaOngkir API to local cache';

/**
* Execute the console command.
*/
public function handle()
{
(new BerandaController())->chartCity();
$provinces = UserProfile::select('province')->groupBy('province')->get();

$this->info('Cities data has been recached!');
$request = new \Illuminate\Http\Request;

foreach ($provinces as $province) {
(new KotaProvinsiController)->indexCity($request, $province);
}
}
}
15 changes: 1 addition & 14 deletions app/Console/Commands/RecachingProvinces.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,12 @@

class RecachingProvinces extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'cache:provinces';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Recache provinces data from RajaOngkir API to local cache';

/**
* Execute the console command.
*/
public function handle()
{
(new KotaProvinsiController())->indexProvince();
(new KotaProvinsiController)->indexProvince();
}
}
6 changes: 2 additions & 4 deletions routes/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

Schedule::command(RecachingProvinces::class)
->daily()
->timezone('Asia/Makassar')
->runInBackground();
->timezone('Asia/Makassar');

Schedule::command(RecachingCities::class)
->daily()
->timezone('Asia/Makassar')
->runInBackground();
->timezone('Asia/Makassar');

0 comments on commit 2530a65

Please sign in to comment.