-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eea3cbb
commit 7e42c48
Showing
42 changed files
with
1,609 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions\Spork; | ||
|
||
use App\Actions\Spork\CustomAction; | ||
use App\Contracts\ActionInterface; | ||
use App\Models\Credential; | ||
use App\Models\Domain; | ||
use App\Models\ExternalRssFeed; | ||
use App\Models\Finance\Account; | ||
use App\Models\Finance\Transaction; | ||
use App\Models\Page; | ||
use App\Models\Person; | ||
use App\Models\Research; | ||
use App\Models\Tag; | ||
use App\Services\Factories\DomainServiceFactory; | ||
use App\Services\Factories\RegistrarServiceFactory; | ||
use Illuminate\Contracts\Bus\Dispatcher; | ||
use Illuminate\Http\Request; | ||
|
||
class ApplyTagToModelAction extends CustomAction implements ActionInterface | ||
{ | ||
public function __construct( | ||
$name = 'Apply Tag', | ||
$slug = 'apply-tag' | ||
) { | ||
parent::__construct($name, $slug, models: [ | ||
Domain::class, | ||
Credential::class, | ||
ExternalRssFeed::class, | ||
Transaction::class, | ||
Research::class, | ||
Person::class, | ||
Account::class, | ||
Page::class, | ||
]); | ||
} | ||
|
||
public function __invoke(Dispatcher $dispatcher, Request $request) | ||
{ | ||
$request->validate([ | ||
'items' => 'required|array', | ||
'tag' => 'required|string', | ||
]); | ||
} | ||
|
||
public function fields(): array | ||
{ | ||
return [ | ||
'tag' => [ | ||
'type' => 'select', | ||
'label' => 'Tag', | ||
'required' => true, | ||
'options' => Tag::all(), | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace App\Jobs\Notifications; | ||
|
||
use App\Contracts\Services\News\NewsServiceContract; | ||
use App\Contracts\Services\WeatherServiceContract; | ||
use App\Models\Article; | ||
use App\Models\Finance\Transaction; | ||
use App\Models\Person; | ||
use App\Models\User; | ||
use App\Notifications\Daily\SummaryNotification; | ||
use Carbon\Carbon; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class BuildSummaryNotificationJob implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
public function handle( | ||
WeatherServiceContract $weatherService, | ||
): void | ||
{ | ||
$now = Carbon::now(); | ||
$nowLocal = Carbon::now('America/Detroit'); | ||
$page = 1; | ||
$headlines = Article::query() | ||
->limit(10) | ||
->distinct('headline') | ||
->where('last_modified', '>=', $nowLocal->copy()->startOfDay()) | ||
->inRandomOrder() | ||
->get(); | ||
|
||
do { | ||
$userPaginator = User::query() | ||
->paginate( | ||
1, | ||
['*'], | ||
'page', | ||
$page++ | ||
); | ||
|
||
/** @var User $user */ | ||
foreach ($userPaginator->items() as $user) { | ||
/** @var Person $person */ | ||
$person = $user->person(); | ||
if (empty($person)) { | ||
continue; | ||
} | ||
|
||
$weather = null; | ||
|
||
if (!empty($person->primary_address)) { | ||
$weatherResponse = $weatherService->query($person->primary_address); | ||
$weather = collect($weatherResponse)->first(); | ||
} | ||
|
||
$user->notify(new SummaryNotification( | ||
$weather, | ||
$headlines->toArray(), | ||
Transaction::query() | ||
->whereIn('account_id', $user->accounts()->pluck('account_id')) | ||
->where('date', '<=', $nowLocal->copy()->addDay()->endOfDay()) | ||
->where('date', '>=', $nowLocal->copy()->subDays(7)->startOfDay()) | ||
->where('name', 'not like', '%Transfer%') | ||
->orderBy('date', 'desc') | ||
->get() | ||
->groupBy('date'), | ||
$user->accounts | ||
)); | ||
} | ||
} while ($userPaginator->hasMorePages()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Notifications; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use Illuminate\Notifications\Notification; | ||
use NotificationChannels\Webhook\WebhookChannel; | ||
|
||
abstract class AbstractNotification extends Notification | ||
{ | ||
use Queueable; | ||
|
||
public static function getNotificationOptions(): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace App\Notifications\Daily; | ||
|
||
use App\Forecast; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Database\Eloquent\Collection; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use Illuminate\Notifications\Notification; | ||
|
||
class SummaryNotification extends Notification | ||
{ | ||
use Queueable; | ||
|
||
public function __construct( | ||
// weather forecast near a user | ||
// article headlines | ||
// Transactions from a period, | ||
// domain expirations | ||
public ?Forecast $weather, | ||
public ?array $articles, | ||
public Collection $transactions, | ||
public Collection $accounts, | ||
) | ||
{ | ||
// | ||
} | ||
|
||
public function via(object $notifiable): array | ||
{ | ||
return ['mail']; | ||
} | ||
|
||
public function toMail(object $notifiable): MailMessage | ||
{ | ||
$message = (new MailMessage); | ||
$message->view( | ||
'emails.daily.summary', | ||
[ | ||
'weather' => $this->weather, | ||
'articles' => $this->articles, | ||
'transactions' => $this->transactions, | ||
'accounts' => $this->accounts, | ||
] | ||
); | ||
return $message; | ||
} | ||
|
||
public function toArray(object $notifiable): array | ||
{ | ||
return []; | ||
} | ||
} |
Oops, something went wrong.