Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Oct 29, 2024
1 parent 7c3cbb4 commit 3a9fe9e
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 17 deletions.
9 changes: 9 additions & 0 deletions app/Concerns/Enums/Arrayable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@

trait Arrayable
{
/**
* @return array<int|string, string>
*/
public static function names(): array
{
return collect(self::cases())
->pluck('name')
->all();
}

/**
* @return array<int|string, string>
*/
public static function values(): array
{
return collect(self::cases())
->pluck('value')
->all();
}

/**
* @return array<int|string, string|null>
*/
public static function options(): array
{
return collect(self::cases())
Expand Down
31 changes: 31 additions & 0 deletions app/Events/CountryCodeNotFound.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace App\Events;

use App\Models\Election;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class CountryCodeNotFound
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

public string $country;

public Election $election;

/**
* Create a new event instance.
*/
public function __construct(string $country, Election $election)
{
$this->country = $country;
$this->election = $election;
}
}
20 changes: 16 additions & 4 deletions app/Jobs/Europarl240609/Turnout/ImportAbroadTurnoutJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,7 +17,6 @@
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use League\Csv\Reader;
use Throwable;

class ImportAbroadTurnoutJob implements ShouldQueue
{
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions app/Jobs/Europarl240609/Turnout/ImportCountyTurnoutJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
]);
Expand All @@ -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.
*
Expand Down
3 changes: 2 additions & 1 deletion app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('personal_access_tokens', function (Blueprint $table) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create('notifications', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('type');
$table->morphs('notifiable');
$table->text('data');
$table->timestamp('read_at')->nullable();
$table->timestamps();
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('scheduled_jobs', function (Blueprint $table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('parties', function (Blueprint $table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('turnouts', function (Blueprint $table) {
Expand Down
36 changes: 36 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3a9fe9e

Please sign in to comment.