From 3a9fe9ee0e67ded91938d554f5140259ad6d396a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Ioni=C8=9B=C4=83?= Date: Tue, 29 Oct 2024 07:27:29 +0000 Subject: [PATCH] wip --- app/Concerns/Enums/Arrayable.php | 9 +++++ app/Events/CountryCodeNotFound.php | 31 ++++++++++++++++ .../Turnout/ImportAbroadTurnoutJob.php | 20 ++++++++--- .../Turnout/ImportCountyTurnoutJob.php | 14 ++++++++ app/Providers/Filament/AdminPanelProvider.php | 3 +- ...05_create_personal_access_tokens_table.php | 3 -- ...1_01_000020_create_notifications_table.php | 22 ++++++++++++ ...0001_01_02_000000_create_siruta_tables.php | 1 + ..._02_000005_create_scheduled_jobs_table.php | 3 -- ...0001_01_02_000010_create_parties_table.php | 3 -- ...001_01_10_000000_create_turnouts_table.php | 3 -- docker-compose.yml | 36 +++++++++++++++++++ 12 files changed, 131 insertions(+), 17 deletions(-) create mode 100644 app/Events/CountryCodeNotFound.php create mode 100644 database/migrations/0001_01_01_000020_create_notifications_table.php create mode 100644 docker-compose.yml diff --git a/app/Concerns/Enums/Arrayable.php b/app/Concerns/Enums/Arrayable.php index a43a622..4abacd6 100644 --- a/app/Concerns/Enums/Arrayable.php +++ b/app/Concerns/Enums/Arrayable.php @@ -6,6 +6,9 @@ trait Arrayable { + /** + * @return array + */ public static function names(): array { return collect(self::cases()) @@ -13,6 +16,9 @@ public static function names(): array ->all(); } + /** + * @return array + */ public static function values(): array { return collect(self::cases()) @@ -20,6 +26,9 @@ public static function values(): array ->all(); } + /** + * @return array + */ public static function options(): array { return collect(self::cases()) diff --git a/app/Events/CountryCodeNotFound.php b/app/Events/CountryCodeNotFound.php new file mode 100644 index 0000000..6590102 --- /dev/null +++ b/app/Events/CountryCodeNotFound.php @@ -0,0 +1,31 @@ +country = $country; + $this->election = $election; + } +} diff --git a/app/Jobs/Europarl240609/Turnout/ImportAbroadTurnoutJob.php b/app/Jobs/Europarl240609/Turnout/ImportAbroadTurnoutJob.php index eb57d9d..3012bf6 100644 --- a/app/Jobs/Europarl240609/Turnout/ImportAbroadTurnoutJob.php +++ b/app/Jobs/Europarl240609/Turnout/ImportAbroadTurnoutJob.php @@ -4,6 +4,7 @@ namespace App\Jobs\Europarl240609\Turnout; +use App\Events\CountryCodeNotFound; use App\Exceptions\CountryCodeNotFoundException; use App\Exceptions\MissingSourceFileException; use App\Models\Country; @@ -16,7 +17,6 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use League\Csv\Reader; -use Throwable; class ImportAbroadTurnoutJob implements ShouldQueue { @@ -65,19 +65,31 @@ public function handle(): void 'mobile' => $record['UM'], 'area' => $record['Mediu'], + 'has_issues' => $this->determineIfHasIssues($record), ...$segments->map(fn (string $segment) => $record[$segment]), ]); } catch (CountryCodeNotFoundException $th) { - logger()->info($th->getMessage()); - } catch (Throwable $th) { - // TODO: filament notification + CountryCodeNotFound::dispatch($record['UAT'], $this->scheduledJob->election); } } Turnout::saveToTemporaryTable($values->all()); } + protected function determineIfHasIssues(array $record): bool + { + $computedTotal = collect(['LP', 'LC', 'LS', 'UM']) + ->map(fn (string $key) => $record[$key]) + ->sum(); + + if ($computedTotal !== $record['LT']) { + return true; + } + + return false; + } + protected function getCountryId(string $name): string { $country = Country::search($name)->first(); diff --git a/app/Jobs/Europarl240609/Turnout/ImportCountyTurnoutJob.php b/app/Jobs/Europarl240609/Turnout/ImportCountyTurnoutJob.php index 0de1c7f..3405131 100644 --- a/app/Jobs/Europarl240609/Turnout/ImportCountyTurnoutJob.php +++ b/app/Jobs/Europarl240609/Turnout/ImportCountyTurnoutJob.php @@ -66,6 +66,7 @@ public function handle(): void 'mobile' => $record['UM'], 'area' => $record['Mediu'], + 'has_issues' => $this->determineIfHasIssues($record), ...$segments->map(fn (string $segment) => $record[$segment]), ]); @@ -74,6 +75,19 @@ public function handle(): void Turnout::saveToTemporaryTable($values->all()); } + protected function determineIfHasIssues(array $record): bool + { + $computedTotal = collect(['LP', 'LC', 'LS', 'UM']) + ->map(fn (string $key) => $record[$key]) + ->sum(); + + if ($computedTotal !== $record['LT']) { + return true; + } + + return false; + } + /** * Get the tags that should be assigned to the job. * diff --git a/app/Providers/Filament/AdminPanelProvider.php b/app/Providers/Filament/AdminPanelProvider.php index 4ed732d..ff28e97 100644 --- a/app/Providers/Filament/AdminPanelProvider.php +++ b/app/Providers/Filament/AdminPanelProvider.php @@ -86,7 +86,8 @@ public function panel(Panel $panel): Panel ->icon('heroicon-o-cog') ->url(fn () => ElectionResource::getUrl('view', ['record' => Filament::getTenant()])), ]) - ->collapsibleNavigationGroups(false); + ->collapsibleNavigationGroups(false) + ->databaseNotifications(); } public function register(): void diff --git a/database/migrations/0001_01_01_000005_create_personal_access_tokens_table.php b/database/migrations/0001_01_01_000005_create_personal_access_tokens_table.php index 55fff76..c0f276c 100644 --- a/database/migrations/0001_01_01_000005_create_personal_access_tokens_table.php +++ b/database/migrations/0001_01_01_000005_create_personal_access_tokens_table.php @@ -8,9 +8,6 @@ return new class extends Migration { - /** - * Run the migrations. - */ public function up(): void { Schema::create('personal_access_tokens', function (Blueprint $table) { diff --git a/database/migrations/0001_01_01_000020_create_notifications_table.php b/database/migrations/0001_01_01_000020_create_notifications_table.php new file mode 100644 index 0000000..62e6b5d --- /dev/null +++ b/database/migrations/0001_01_01_000020_create_notifications_table.php @@ -0,0 +1,22 @@ +uuid('id')->primary(); + $table->string('type'); + $table->morphs('notifiable'); + $table->text('data'); + $table->timestamp('read_at')->nullable(); + $table->timestamps(); + }); + } +}; diff --git a/database/migrations/0001_01_02_000000_create_siruta_tables.php b/database/migrations/0001_01_02_000000_create_siruta_tables.php index ed82be8..1ae4b43 100644 --- a/database/migrations/0001_01_02_000000_create_siruta_tables.php +++ b/database/migrations/0001_01_02_000000_create_siruta_tables.php @@ -8,6 +8,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; +use Illuminate\Support\Facades\Storage; use Maatwebsite\Excel\Facades\Excel; return new class extends Migration diff --git a/database/migrations/0001_01_02_000005_create_scheduled_jobs_table.php b/database/migrations/0001_01_02_000005_create_scheduled_jobs_table.php index 7d93b50..8a7c5a2 100644 --- a/database/migrations/0001_01_02_000005_create_scheduled_jobs_table.php +++ b/database/migrations/0001_01_02_000005_create_scheduled_jobs_table.php @@ -9,9 +9,6 @@ return new class extends Migration { - /** - * Run the migrations. - */ public function up(): void { Schema::create('scheduled_jobs', function (Blueprint $table) { diff --git a/database/migrations/0001_01_02_000010_create_parties_table.php b/database/migrations/0001_01_02_000010_create_parties_table.php index 9b7ebd2..c6c8fe8 100644 --- a/database/migrations/0001_01_02_000010_create_parties_table.php +++ b/database/migrations/0001_01_02_000010_create_parties_table.php @@ -9,9 +9,6 @@ return new class extends Migration { - /** - * Run the migrations. - */ public function up(): void { Schema::create('parties', function (Blueprint $table) { diff --git a/database/migrations/0001_01_10_000000_create_turnouts_table.php b/database/migrations/0001_01_10_000000_create_turnouts_table.php index fa32f46..2bdc007 100644 --- a/database/migrations/0001_01_10_000000_create_turnouts_table.php +++ b/database/migrations/0001_01_10_000000_create_turnouts_table.php @@ -10,9 +10,6 @@ return new class extends Migration { - /** - * Run the migrations. - */ public function up(): void { Schema::create('turnouts', function (Blueprint $table) { diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c76721a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,36 @@ +services: + typesense: + image: typesense/typesense:27.1 + ports: + - ${FORWARD_TYPESENSE_PORT:-8108}:8108 + environment: + TYPESENSE_DATA_DIR: ${TYPESENSE_DATA_DIR:-/typesense-data} + TYPESENSE_API_KEY: ${TYPESENSE_API_KEY:-xyz} + TYPESENSE_ENABLE_CORS: ${TYPESENSE_ENABLE_CORS:-true} + volumes: + - sail-typesense:/typesense-data + healthcheck: + test: + - CMD + - wget + - '--no-verbose' + - '--spider' + - 'http://localhost:8108/health' + retries: 5 + timeout: 7s + + soketi: + image: quay.io/soketi/soketi:latest-16-alpine + environment: + SOKETI_DEBUG: ${SOKETI_DEBUG:-1} + SOKETI_METRICS_SERVER_PORT: 9601 + SOKETI_DEFAULT_APP_ID: ${PUSHER_APP_ID} + SOKETI_DEFAULT_APP_KEY: ${PUSHER_APP_KEY} + SOKETI_DEFAULT_APP_SECRET: ${PUSHER_APP_SECRET} + ports: + - ${PUSHER_PORT:-6001}:6001 + - ${PUSHER_METRICS_PORT:-9601}:9601 + +volumes: + sail-typesense: + driver: local