mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2026-01-27 06:33:18 +00:00
voting system with nostr added
This commit is contained in:
@@ -5,7 +5,6 @@ namespace App\Console\Commands\Nostr;
|
||||
use App\Models\EinundzwanzigPleb;
|
||||
use App\Traits\NostrFetcherTrait;
|
||||
use Illuminate\Console\Command;
|
||||
use swentel\nostr\Subscription\Subscription;
|
||||
|
||||
class SyncProfiles extends Command
|
||||
{
|
||||
|
||||
50
app/Enums/AssociationStatus.php
Normal file
50
app/Enums/AssociationStatus.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use ArchTech\Enums\From;
|
||||
use ArchTech\Enums\InvokableCases;
|
||||
use ArchTech\Enums\Meta\Meta;
|
||||
use ArchTech\Enums\Metadata;
|
||||
use ArchTech\Enums\Names;
|
||||
use ArchTech\Enums\Options;
|
||||
use ArchTech\Enums\Values;
|
||||
|
||||
#[Meta(Label::class, Color::class)]
|
||||
enum AssociationStatus: int
|
||||
{
|
||||
use InvokableCases;
|
||||
use Names;
|
||||
use Values;
|
||||
use Options;
|
||||
use Metadata;
|
||||
use From;
|
||||
|
||||
#[Label('kein Mitglied')] #[Color('cyan')]
|
||||
case DEFAULT = 1;
|
||||
#[Label('Passiv')] #[Color('orange')]
|
||||
case PASSIVE = 2;
|
||||
#[Label('Aktiv')] #[Color('purple')]
|
||||
case ACTIVE = 3;
|
||||
#[Label('Ehrenmitglied')] #[Color('negative')]
|
||||
case HONORARY = 4;
|
||||
|
||||
public static function selectOptions()
|
||||
{
|
||||
return collect(self::options())
|
||||
->map(
|
||||
fn(
|
||||
$option,
|
||||
$name
|
||||
) => [
|
||||
'value' => $option,
|
||||
'label' => __(
|
||||
self::fromName($name)
|
||||
->label()
|
||||
),
|
||||
]
|
||||
)
|
||||
->values()
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
11
app/Enums/Color.php
Normal file
11
app/Enums/Color.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use ArchTech\Enums\Meta\MetaProperty;
|
||||
use Attribute;
|
||||
|
||||
#[Attribute]
|
||||
class Color extends MetaProperty
|
||||
{
|
||||
}
|
||||
11
app/Enums/Label.php
Normal file
11
app/Enums/Label.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use ArchTech\Enums\Meta\MetaProperty;
|
||||
use Attribute;
|
||||
|
||||
#[Attribute]
|
||||
class Label extends MetaProperty
|
||||
{
|
||||
}
|
||||
24
app/Http/Controllers/Api/Nostr/GetProfile.php
Normal file
24
app/Http/Controllers/Api/Nostr/GetProfile.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Nostr;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Profile;
|
||||
use App\Traits\NostrFetcherTrait;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class GetProfile extends Controller
|
||||
{
|
||||
use NostrFetcherTrait;
|
||||
|
||||
public function __invoke($key, Request $request)
|
||||
{
|
||||
if (!Profile::query()->where('pubkey', $key)->exists()) {
|
||||
$this->fetchProfile([$key]);
|
||||
}
|
||||
|
||||
return Profile::query()
|
||||
->where('pubkey', $key)
|
||||
->first();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\AssociationStatus;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EinundzwanzigPleb extends Model
|
||||
@@ -9,6 +10,13 @@ class EinundzwanzigPleb extends Model
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'association_status' => AssociationStatus::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function profile()
|
||||
{
|
||||
return $this->hasOne(Profile::class, 'pubkey', 'pubkey');
|
||||
|
||||
10
app/Models/Election.php
Normal file
10
app/Models/Election.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Election extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -17,6 +17,14 @@ trait NostrFetcherTrait
|
||||
{
|
||||
$hex = collect([]);
|
||||
foreach ($npubs as $item) {
|
||||
// check if $item is already a hex string
|
||||
if (preg_match('/^[0-9a-fA-F]+$/', $item)) {
|
||||
$hex->push([
|
||||
'hex' => $item,
|
||||
'npub' => (new Key)->convertPublicKeyToBech32($item),
|
||||
]);
|
||||
continue;
|
||||
}
|
||||
$hex->push([
|
||||
'hex' => (new Key)->convertToHex($item),
|
||||
'npub' => $item,
|
||||
|
||||
Reference in New Issue
Block a user