Skip to content

Commit

Permalink
Merge pull request #24 from CardanoGateKeeper/reporting-updates
Browse files Browse the repository at this point in the history
Reporting updates
  • Loading branch information
Crypto2099 authored Nov 16, 2023
2 parents 1828ab3 + b69e7f7 commit d38cd19
Show file tree
Hide file tree
Showing 15 changed files with 639 additions and 298 deletions.
273 changes: 126 additions & 147 deletions application/app/Http/Controllers/API/V1/NonceController.php

Large diffs are not rendered by default.

86 changes: 42 additions & 44 deletions application/app/Http/Controllers/Admin/ManageEventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,94 +2,92 @@

namespace App\Http\Controllers\Admin;

use Throwable;
use App\Http\Controllers\Controller;
use App\Models\Event;
use Illuminate\Http\Request;
use App\Services\EventService;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Throwable;

class ManageEventsController extends Controller {

class ManageEventsController extends Controller
{
private EventService $eventService;

public function __construct(EventService $eventService)
{
public function __construct(EventService $eventService) {
$this->eventService = $eventService;
}

public function index(): Renderable
{
public function index(): Renderable {
$allEvents = $this->eventService->getEventList(true);

return view(
'admin.manage-events.index',
compact('allEvents'),
);
return view('admin.manage-events.index', compact('allEvents'),);
}

public function create(): Renderable
{
public function create(): Renderable {
$event = null;

return view(
'admin.manage-events.form',
compact('event'),
);
return view('admin.manage-events.form', compact('event'),);
}

public function store(Request $request): RedirectResponse
{
public function store(Request $request): RedirectResponse {
try {

$payload = $request->only([
'event_id',
'name',
'location',
'eventDate',
'eventStart',
'eventEnd',
'startDateTime',
'endDateTime',
'hodlAsset',
'policyIds',
'nonceValidForMinutes',
]);

if ($request->file('image')) {
$payload['image'] = $request->file('image')->store('public');
}


$this->eventService->save($payload);

return redirect()
->route('manage-events.index')
->with('status', !empty($request->event_id)
? trans('Event updated')
: trans('Event created')
);
->with('status', !empty($request->event_id) ? trans('Event updated') : trans('Event created'));

} catch (Throwable $exception) {

return redirectBackWithError(
trans('Failed to save event'),
$exception,
);
return redirectBackWithError(trans('Failed to save event'), $exception,);

}
}

public function show(Event $event): Renderable
{
return view(
'admin.manage-events.view',
compact('event'),
);
public function show(Event $event): Renderable {
$event_tickets = $event->tickets;
$tickets = [
'total' => count($event_tickets),
'checked_in' => 0,
'event_tickets' => $event_tickets,
];

foreach ($event_tickets as $ticket) {
if ($ticket->isCheckedIn) {
$tickets['checked_in']++;
}
}

// $tickets = $event->tickets;
return view('admin.manage-events.view', compact('event', 'tickets'),);
}

public function edit(Event $event): Renderable
{
return view(
'admin.manage-events.form',
compact('event'),
);
public function edit(Event $event): Renderable {
return view('admin.manage-events.form', compact('event'),);
}

public function destroy(Event $event): void
{
public function destroy(Event $event): void {
dd('TODO');
}
}
36 changes: 34 additions & 2 deletions application/app/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

use App\Casts\Json;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Event extends Model {

class Event extends Model
{
/**
* @var string[] $fillable
*/
Expand All @@ -18,6 +19,11 @@ class Event extends Model
'hodlAsset',
'startDateTime',
'endDateTime',
'location',
'eventStart',
'eventEnd',
'eventDate',
'image',
];

/**
Expand All @@ -38,4 +44,30 @@ class Event extends Model
'startDateTime',
'endDateTime',
];

public function tickets(): HasMany {
return $this->hasMany(Ticket::class, 'eventId');
}

public function description() {
$description = "";
if ($this->eventDate) {
$description .= date('l, F jS, Y', strtotime($this->eventDate));
}

if ($this->eventStart && $this->eventEnd) {
$description .= " " . $this->eventStart . " to " . $this->eventEnd . ".";
} else if ($this->eventStart) {
$description .= " " . $this->eventStart;
} else if ($this->eventEnd) {
$description .= " until " . $this->eventEnd;
}

if ($this->location) {
$description .= " " . $this->location;
}

return $description;

}
}
5 changes: 5 additions & 0 deletions application/app/Models/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Ticket extends Model
{
Expand Down Expand Up @@ -32,4 +33,8 @@ class Ticket extends Model
protected $dates = [
'checkInTime',
];

public function event(): BelongsTo {
return $this->belongsTo(Event::class, 'eventId');
}
}
78 changes: 44 additions & 34 deletions application/app/Services/EventService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,29 @@

namespace App\Services;

use App\Models\Event;
use App\Exceptions\AppException;
use Illuminate\Support\Facades\Validator;
use App\Models\Event;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;

class EventService
{
public function getEventList($fullInfo = false): Collection
{
class EventService {

public function getEventList($fullInfo = false): Collection {
$selectColumns = [
'uuid',
'name',
'policyIds',
];

if ($fullInfo) {
$selectColumns = array_merge(
$selectColumns,
[
'id',
'nonceValidForMinutes',
'hodlAsset',
'startDateTime',
'endDateTime',
]
);
$selectColumns = array_merge($selectColumns, [
'id',
'nonceValidForMinutes',
'hodlAsset',
'startDateTime',
'endDateTime',
]);
}

return Event::all($selectColumns);
Expand All @@ -37,8 +33,7 @@ public function getEventList($fullInfo = false): Collection
/**
* @throws AppException|ValidationException
*/
public function save(array $payload): void
{
public function save(array $payload): void {
$event = null;
if (!empty($payload['event_id']) && !$event = $this->findById($payload['event_id'])) {
throw new AppException(trans('Event not found'));
Expand All @@ -47,21 +42,38 @@ public function save(array $payload): void
$payload['policyIds'] = array_filter(preg_split("/\r\n|\n|\r/", $payload['policyIds']));

$validationRules = [
'name' => ['required', 'min:3'],
'policyIds' => ['required', 'array', 'min:1'],
'endDateTime' => ['required', 'date'],
'startDateTime' => ['date'],
'hodlAsset' => ['integer'],
'nonceValidForMinutes' => ['required', 'integer', 'min:5']
'name' => [
'required',
'min:3',
],
'policyIds' => [
'required',
'array',
'min:1',
],
'endDateTime' => [
'required',
'date',
],
'startDateTime' => ['date'],
'hodlAsset' => ['integer'],
'nonceValidForMinutes' => [
'required',
'integer',
'min:5',
],
'location' => ['string'],
'eventStart' => ['string'],
'eventEnd' => ['string'],
'eventDate' => ['date'],
'image' => ['string'],
];

$validator = Validator::make($payload, $validationRules);

if ($validator->fails()) {
throw new AppException(sprintf(
'%s: %s',
trans('validation errors'), implode(' ', $validator->errors()->all())
));
throw new AppException(sprintf('%s: %s', trans('validation errors'), implode(' ', $validator->errors()
->all())));
}

if (!$event) {
Expand All @@ -78,15 +90,13 @@ public function save(array $payload): void
$event->save();
}

public function findById(int $eventId): ?Event
{
public function findById(int $eventId): ?Event {
return Event::where('id', $eventId)
->first();
->first();
}

public function findByUUID(string $uuid): ?Event
{
public function findByUUID(string $uuid): ?Event {
return Event::where('uuid', $uuid)
->first();
->first();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ public function assetHodled(string $policyId, string $assetId, string $stakeKey)
throw new AppException(trans('Asset not found in any wallets'));
}

error_log("Blockfrost response:\r\n".print_r($assetAddresses,true));

$firstAssetAddress = $assetAddresses[0]['address'];

$addressInfo = $this->call(
self::HTTP_REQUEST_GET,
"addresses/{$firstAssetAddress}",
);

// error_log("Address details:\r\n".json_encode($addressInfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
error_log("Got address details {$stakeKey} {$addressInfo['stake_address']}");

return $addressInfo['stake_address'] === $stakeKey;
}

Expand Down
Loading

0 comments on commit d38cd19

Please sign in to comment.