Skip to content

Commit

Permalink
start cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
recursivetree committed Jul 7, 2024
1 parent 6d74794 commit 6d05e13
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@
*
* @package Seat\Web\Events
*/
abstract class AbstractRoleEvent
abstract class AbstractUserRoleChangeEvent
{
use SerializesModels;

/**
* @var int
*/
public $user_id;
public int $user_id;

/**
* @var Role
*/
public $role;
public Role $role;

/**
* UserRoleAdded constructor.
* AbstractUserRoleChangeEvent constructor.
*
* @param int $user_id
* @param \Seat\Web\Models\Acl\Role $role
* @param Role $role
*/
public function __construct(int $user_id, Role $role)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Events/UserRoleAdded.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @package Seat\Web\Events
*/
class UserRoleAdded extends AbstractRoleEvent
class UserRoleAdded extends AbstractUserRoleChangeEvent
{

}
2 changes: 1 addition & 1 deletion src/Events/UserRoleRemoved.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @package Seat\Web\Events
*/
class UserRoleRemoved extends AbstractRoleEvent
class UserRoleRemoved extends AbstractUserRoleChangeEvent
{

}
1 change: 1 addition & 0 deletions src/Http/Controllers/Configuration/ScheduleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function newCharacterSchedulingRule(Request $request)
$rule->role_id = $role->id;
}

// $time_modifier: conversion factor from timeunit to seconds
if($request->timeunit === 'hour') {
$time_modifier = 60 * 60;
} elseif ($request->timeunit === 'day') {
Expand Down
3 changes: 3 additions & 0 deletions src/Listeners/UpdateRefreshTokenSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
use Seat\Web\Events\UserRoleRemoved;
use Seat\Web\Models\CharacterSchedulingRule;

/**
* This listener is triggered when users gain or loose roles. In that case, their refresh token schedule is updated
*/
class UpdateRefreshTokenSchedule
{
public function handle(UserRoleAdded|UserRoleRemoved $event): void
Expand Down
5 changes: 3 additions & 2 deletions src/Models/Acl/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Support\Collection;
use Intervention\Image\Facades\Image;
use OpenApi\Attributes as OA;
Expand Down Expand Up @@ -109,9 +110,9 @@ public function squads()
}

/**
* @return \Illuminate\Database\Eloquent\Relations\HasOne
* @return HasOne
*/
public function character_scheduling_rule(): \Illuminate\Database\Eloquent\Relations\HasOne
public function character_scheduling_rule(): HasOne
{
return $this->hasOne(CharacterSchedulingRule::class);
}
Expand Down
18 changes: 15 additions & 3 deletions src/Models/CharacterSchedulingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace Seat\Web\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Seat\Eveapi\Models\RefreshToken;
use Seat\Eveapi\Models\RefreshTokenSchedule;
use Seat\Services\Models\ExtensibleModel;
Expand All @@ -36,13 +37,24 @@
*/
class CharacterSchedulingRule extends ExtensibleModel
{
const DEFAULT_UPDATE_INTERVAL = 60 * 60;

/**
* @var bool
*/
public $timestamps = false;

/**
* @var string
*/
protected $primaryKey = 'role_id';

/**
* @var bool
*/
public $incrementing = false;

public function role(): \Illuminate\Database\Eloquent\Relations\BelongsTo
const DEFAULT_UPDATE_INTERVAL = 60 * 60; // 1 hour, the esi cache timer for most endpoints

public function role(): BelongsTo
{
return $this->belongsTo(Role::class);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Models/Squads/SquadRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

namespace Seat\Web\Models\Squads;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Seat\Web\Models\Acl\Role;

Expand All @@ -37,12 +38,12 @@
*/
class SquadRole extends Pivot
{
public function role(): \Illuminate\Database\Eloquent\Relations\BelongsTo
public function role(): BelongsTo
{
return $this->belongsTo(Role::class);
}

public function squad(): \Illuminate\Database\Eloquent\Relations\BelongsTo
public function squad(): BelongsTo
{
return $this->belongsTo(Squad::class);
}
Expand Down

0 comments on commit 6d05e13

Please sign in to comment.