Skip to content

Commit

Permalink
Observer now registed in model (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankit-canyon authored Dec 11, 2024
1 parent e0013cc commit 1c17652
Show file tree
Hide file tree
Showing 34 changed files with 72 additions and 102 deletions.
3 changes: 3 additions & 0 deletions app-modules/alert/src/Models/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@
use OwenIt\Auditing\Contracts\Auditable;
use Illuminate\Database\Eloquent\Builder;
use App\Models\Scopes\LicensedToEducatable;
use AidingApp\Alert\Observers\AlertObserver;
use App\Models\Concerns\BelongsToEducatable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use AidingApp\Notification\Models\Contracts\Subscribable;
use AidingApp\Audit\Models\Concerns\Auditable as AuditableTrait;
use AidingApp\Notification\Models\Contracts\CanTriggerAutoSubscription;
Expand All @@ -55,6 +57,7 @@
*
* @mixin IdeHelperAlert
*/
#[ObservedBy([AlertObserver::class])]
class Alert extends BaseModel implements Auditable, CanTriggerAutoSubscription
{
use SoftDeletes;
Expand Down
8 changes: 0 additions & 8 deletions app-modules/alert/src/Providers/AlertServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
use Illuminate\Support\ServiceProvider;
use AidingApp\Alert\Enums\AlertSeverity;
use AidingApp\Alert\Events\AlertCreated;
use AidingApp\Alert\Observers\AlertObserver;
use Illuminate\Database\Eloquent\Relations\Relation;
use AidingApp\Alert\Listeners\NotifySubscribersOfAlertCreated;

Expand All @@ -64,18 +63,11 @@ public function boot(): void
'alert' => Alert::class,
]);

$this->registerObservers();

$this->registerEvents();

$this->registerGraphQL();
}

protected function registerObservers(): void
{
Alert::observe(AlertObserver::class);
}

protected function registerEvents(): void
{
Event::listen(
Expand Down
3 changes: 3 additions & 0 deletions app-modules/authorization/src/Models/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@
use Illuminate\Database\Eloquent\SoftDeletes;
use AidingApp\Authorization\Enums\LicenseType;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use AidingApp\Authorization\Observers\LicenseObserver;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use AidingApp\Audit\Models\Concerns\Auditable as AuditableConcern;

/**
* @mixin IdeHelperLicense
*/
#[ObservedBy([LicenseObserver::class])]
class License extends BaseModel implements Auditable
{
use AuditableConcern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
use SocialiteProviders\Manager\SocialiteWasCalled;
use Illuminate\Database\Eloquent\Relations\Relation;
use SocialiteProviders\Google\GoogleExtendSocialite;
use AidingApp\Authorization\Observers\LicenseObserver;
use AidingApp\Authorization\Http\Controllers\Auth\LogoutController;
use Filament\Http\Controllers\Auth\LogoutController as FilamentLogoutController;

Expand All @@ -72,8 +71,6 @@ public function boot(): void
'license' => License::class,
]);

$this->registerObservers();

Event::listen(
events: SocialiteWasCalled::class,
listener: AzureExtendSocialite::class . '@handle'
Expand All @@ -84,9 +81,4 @@ public function boot(): void
listener: GoogleExtendSocialite::class . '@handle'
);
}

public function registerObservers(): void
{
License::observe(LicenseObserver::class);
}
}
3 changes: 3 additions & 0 deletions app-modules/contact/src/Models/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use AidingApp\Authorization\Enums\LicenseType;
use AidingApp\Engagement\Models\EngagementFile;
use AidingApp\Notification\Models\Subscription;
use AidingApp\Contact\Observers\ContactObserver;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Relations\HasMany;
Expand All @@ -63,6 +64,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use AidingApp\Engagement\Models\EngagementFileEntities;
use AidingApp\InventoryManagement\Models\AssetCheckOut;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use AidingApp\Contact\Filament\Resources\ContactResource;
use AidingApp\Notification\Models\Contracts\Subscribable;
Expand All @@ -81,6 +83,7 @@
*
* @mixin IdeHelperContact
*/
#[ObservedBy([ContactObserver::class])]
class Contact extends BaseAuthenticatable implements Auditable, Subscribable, Educatable, HasFilamentResource, NotifiableInterface
{
use AuditableTrait;
Expand Down
3 changes: 3 additions & 0 deletions app-modules/contact/src/Models/OrganizationIndustry.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use AidingApp\Contact\Observers\OrganizationIndustryObserver;
use AidingApp\Audit\Models\Concerns\Auditable as AuditableTrait;

/**
* @mixin IdeHelperOrganizationIndustry
*/
#[ObservedBy([OrganizationIndustryObserver::class])]
class OrganizationIndustry extends Model implements Auditable
{
use HasFactory;
Expand Down
3 changes: 3 additions & 0 deletions app-modules/contact/src/Models/OrganizationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use AidingApp\Contact\Observers\OrganizationTypeObserver;
use AidingApp\Audit\Models\Concerns\Auditable as AuditableTrait;

/**
* @mixin IdeHelperOrganizationType
*/
#[ObservedBy([OrganizationTypeObserver::class])]
class OrganizationType extends Model implements Auditable
{
use HasFactory;
Expand Down
6 changes: 0 additions & 6 deletions app-modules/contact/src/Providers/ContactServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,10 @@
use AidingApp\Contact\Models\ContactSource;
use AidingApp\Contact\Models\ContactStatus;
use AidingApp\Contact\Models\OrganizationType;
use AidingApp\Contact\Observers\ContactObserver;
use AidingApp\Contact\Models\OrganizationIndustry;
use Illuminate\Database\Eloquent\Relations\Relation;
use AidingApp\Contact\Enums\ContactStatusColorOptions;
use AidingApp\Contact\Enums\SystemContactClassification;
use AidingApp\Contact\Observers\OrganizationTypeObserver;
use AidingApp\Contact\Observers\OrganizationIndustryObserver;

class ContactServiceProvider extends ServiceProvider
{
Expand All @@ -72,9 +69,6 @@ public function boot(): void
'organization_industry' => OrganizationIndustry::class,
'organization_type' => OrganizationType::class,
]);
Contact::observe(ContactObserver::class);
OrganizationType::observe(OrganizationTypeObserver::class);
OrganizationIndustry::observe(OrganizationIndustryObserver::class);

$this->discoverSchema(__DIR__ . '/../../graphql/*');
$this->registerEnum(ContactStatusColorOptions::class);
Expand Down
3 changes: 3 additions & 0 deletions app-modules/division/src/Models/Division.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@
use App\Models\NotificationSettingPivot;
use OwenIt\Auditing\Contracts\Auditable;
use Illuminate\Database\Eloquent\SoftDeletes;
use AidingApp\Division\Observers\DivisionObserver;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use AidingApp\Audit\Models\Concerns\Auditable as AuditableTrait;

/**
* @mixin IdeHelperDivision
*/
#[ObservedBy([DivisionObserver::class])]
class Division extends BaseModel implements Auditable
{
use AuditableTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
use AidingApp\Division\DivisionPlugin;
use AidingApp\Division\Models\Division;
use Illuminate\Support\ServiceProvider;
use AidingApp\Division\Observers\DivisionObserver;
use Illuminate\Database\Eloquent\Relations\Relation;

class DivisionServiceProvider extends ServiceProvider
Expand All @@ -59,12 +58,6 @@ public function boot(): void
'division' => Division::class,
]);

$this->registerObservers();
$this->discoverSchema(__DIR__ . '/../../graphql/division.graphql');
}

protected function registerObservers(): void
{
Division::observe(DivisionObserver::class);
}
}
3 changes: 3 additions & 0 deletions app-modules/engagement/src/Models/EmailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@
use Spatie\MediaLibrary\InteractsWithMedia;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use AidingApp\Engagement\Observers\EmailTemplateObserver;

/**
* @mixin IdeHelperEmailTemplate
*/
#[ObservedBy([EmailTemplateObserver::class])]
class EmailTemplate extends BaseModel implements HasMedia
{
use InteractsWithMedia;
Expand Down
3 changes: 3 additions & 0 deletions app-modules/engagement/src/Models/Engagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
use AidingApp\Timeline\Timelines\EngagementTimeline;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use AidingApp\Engagement\Observers\EngagementObserver;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use AidingApp\Engagement\Enums\EngagementDeliveryStatus;
use AidingApp\Notification\Models\Contracts\Subscribable;
use AidingApp\Timeline\Models\Contracts\ProvidesATimeline;
Expand All @@ -67,6 +69,7 @@
*
* @mixin IdeHelperEngagement
*/
#[ObservedBy([EngagementObserver::class])]
class Engagement extends BaseModel implements Auditable, CanTriggerAutoSubscription, ProvidesATimeline, HasMedia
{
use AuditableTrait;
Expand Down
3 changes: 3 additions & 0 deletions app-modules/engagement/src/Models/EngagementBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use AidingApp\Engagement\Observers\EngagementBatchObserver;
use AidingApp\Engagement\Models\Concerns\HasManyEngagements;

/**
* @mixin IdeHelperEngagementBatch
*/
#[ObservedBy([EngagementBatchObserver::class])]
class EngagementBatch extends BaseModel implements HasMedia
{
use HasManyEngagements;
Expand Down
3 changes: 3 additions & 0 deletions app-modules/engagement/src/Models/EngagementFileEntities.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphPivot;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use AidingApp\Notification\Models\Contracts\Subscribable;
use AidingApp\Engagement\Observers\EngagementFileEntitiesObserver;
use AidingApp\Notification\Models\Contracts\CanTriggerAutoSubscription;

/**
* @mixin IdeHelperEngagementFileEntities
*/
#[ObservedBy([EngagementFileEntitiesObserver::class])]
class EngagementFileEntities extends MorphPivot implements CanTriggerAutoSubscription
{
protected $table = 'engagement_file_entities';
Expand Down
3 changes: 3 additions & 0 deletions app-modules/engagement/src/Models/SmsTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use AidingApp\Engagement\Observers\SmsTemplateObserver;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;

/**
* @mixin IdeHelperSmsTemplate
*/
#[ObservedBy([SmsTemplateObserver::class])]
class SmsTemplate extends BaseModel
{
use SoftDeletes;
Expand Down
17 changes: 0 additions & 17 deletions app-modules/engagement/src/Providers/EngagementServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@
use AidingApp\Engagement\Actions\DeliverEngagements;
use Illuminate\Database\Eloquent\Relations\Relation;
use AidingApp\Engagement\Models\EngagementDeliverable;
use AidingApp\Engagement\Observers\EngagementObserver;
use AidingApp\Engagement\Models\EngagementFileEntities;
use AidingApp\Engagement\Observers\SmsTemplateObserver;
use AidingApp\Engagement\Observers\EmailTemplateObserver;
use AidingApp\Engagement\Observers\EngagementBatchObserver;
use AidingApp\Engagement\Observers\EngagementFileEntitiesObserver;

class EngagementServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -93,16 +87,5 @@ public function boot(): void
->onOneServer()
->withoutOverlapping();
});

$this->registerObservers();
}

public function registerObservers(): void
{
EmailTemplate::observe(EmailTemplateObserver::class);
Engagement::observe(EngagementObserver::class);
EngagementBatch::observe(EngagementBatchObserver::class);
EngagementFileEntities::observe(EngagementFileEntitiesObserver::class);
SmsTemplate::observe(SmsTemplateObserver::class);
}
}
3 changes: 3 additions & 0 deletions app-modules/inventory-management/src/Models/AssetCheckIn.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use AidingApp\Timeline\Timelines\AssetCheckInTimeline;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use AidingApp\Timeline\Models\Contracts\ProvidesATimeline;
use AidingApp\Audit\Models\Concerns\Auditable as AuditableTrait;
use AidingApp\InventoryManagement\Observers\AssetCheckInObserver;

/**
* @mixin IdeHelperAssetCheckIn
*/
#[ObservedBy([AssetCheckInObserver::class])]
class AssetCheckIn extends BaseModel implements Auditable, ProvidesATimeline
{
use AuditableTrait;
Expand Down
3 changes: 3 additions & 0 deletions app-modules/inventory-management/src/Models/AssetCheckOut.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use AidingApp\Timeline\Timelines\AssetCheckOutTimeline;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use AidingApp\Timeline\Models\Contracts\ProvidesATimeline;
use AidingApp\InventoryManagement\Enums\AssetCheckOutStatus;
use AidingApp\Audit\Models\Concerns\Auditable as AuditableTrait;
use AidingApp\InventoryManagement\Observers\AssetCheckOutObserver;

/**
* @mixin IdeHelperAssetCheckOut
*/
#[ObservedBy([AssetCheckOutObserver::class])]
class AssetCheckOut extends BaseModel implements Auditable, ProvidesATimeline
{
use AuditableTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use AidingApp\Timeline\Models\Contracts\ProvidesATimeline;
use AidingApp\Timeline\Timelines\MaintenanceActivityTimeline;
use AidingApp\Audit\Models\Concerns\Auditable as AuditableTrait;
use AidingApp\InventoryManagement\Enums\MaintenanceActivityStatus;
use AidingApp\InventoryManagement\Observers\MaintenanceActivityObserver;

/**
* @mixin IdeHelperMaintenanceActivity
*/
#[ObservedBy([MaintenanceActivityObserver::class])]
class MaintenanceActivity extends BaseModel implements Auditable, ProvidesATimeline
{
use AuditableTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
use AidingApp\InventoryManagement\InventoryManagementPlugin;
use AidingApp\InventoryManagement\Models\MaintenanceActivity;
use AidingApp\InventoryManagement\Models\MaintenanceProvider;
use AidingApp\InventoryManagement\Observers\AssetCheckInObserver;
use AidingApp\InventoryManagement\Observers\AssetCheckOutObserver;
use AidingApp\InventoryManagement\Observers\MaintenanceActivityObserver;

class InventoryManagementServiceProvider extends ServiceProvider
{
Expand All @@ -71,14 +68,5 @@ public function boot()
'maintenance_activity' => MaintenanceActivity::class,
'maintenance_provider' => MaintenanceProvider::class,
]);

$this->registerObservers();
}

public function registerObservers(): void
{
AssetCheckIn::observe(AssetCheckInObserver::class);
AssetCheckOut::observe(AssetCheckOutObserver::class);
MaintenanceActivity::observe(MaintenanceActivityObserver::class);
}
}
Loading

0 comments on commit 1c17652

Please sign in to comment.