From 7f5e462e4db0b22671add4ef0a3934b90cf05e82 Mon Sep 17 00:00:00 2001 From: Adrian Hopek Date: Tue, 26 Apr 2022 12:46:18 +0200 Subject: [PATCH] #116 - cr fix --- .../Providers/AppServiceProvider.php | 6 +- .../Providers/AuthServiceProvider.php | 10 +-- .../Providers/RouteServiceProvider.php | 2 +- app/Domain/CalendarGenerator.php | 2 +- app/Domain/DailySummaryRetriever.php | 8 ++- app/Domain/Enums/EmploymentForm.php | 2 +- app/Domain/Enums/Role.php | 2 +- app/Domain/Enums/VacationType.php | 2 +- app/Domain/Notifications/Channels.php | 11 +++ .../KeyHasBeenGivenNotification.php | 4 +- .../KeyHasBeenTakenNotification.php | 4 +- app/Domain/Notifications/Notifiable.php | 10 +++ .../VacationRequestCreatedNotification.php | 2 +- ...cationRequestStatusChangedNotification.php | 2 +- ...ionRequestWaitsForApprovalNotification.php | 2 +- app/Domain/PolishHolidaysRetriever.php | 2 +- app/Domain/Slack/Channels/SlackApiChannel.php | 25 ------- app/Domain/Slack/Handlers/DailySummary.php | 55 --------------- app/Domain/TimesheetExport.php | 2 +- app/Domain/TimesheetPerUserSheet.php | 4 +- app/Domain/UserVacationStatsRetriever.php | 8 +-- .../Rules/DoesNotExceedLimitRule.php | 2 +- .../Rules/VacationTypeCanBeSelected.php | 2 +- app/Eloquent/Helpers/YearPeriodRetriever.php | 2 +- app/Eloquent/Models/Key.php | 3 +- app/Eloquent/Models/User.php | 5 +- .../Commands/SendDailySummaryToSlack.php | 68 +++++++++---------- .../Api/CalculateVacationDaysController.php | 2 +- .../GetAvailableVacationTypesController.php | 4 +- .../Http/Controllers/TimesheetController.php | 6 +- .../Controllers/VacationLimitController.php | 2 +- .../Http/Middleware/HandleInertiaRequests.php | 4 +- .../Slack/Channels/SlackApiChannel.php | 36 ++++++++++ .../Slack/Controller.php | 11 +-- .../Slack/Elements/AbsencesAttachment.php | 22 ++++++ .../Slack/Elements/Attachment.php | 12 ++++ .../Slack/Elements/BirthdaysAttachment.php | 22 ++++++ .../Slack/Elements/KeysAttachment.php | 21 ++++++ .../Slack/Elements/ListAttachment.php | 36 ++++++++++ .../Slack/Elements/RemotesAttachment.php | 22 ++++++ .../Exceptions/UserNotFoundException.php | 2 +- .../Slack/Handlers/CatchAll.php | 8 +-- .../Slack/Handlers/DailySummary.php | 36 ++++++++++ .../Slack/Handlers/GiveKeysTo.php | 8 +-- .../Slack/Handlers/Help.php | 10 +-- .../Slack/Handlers/HomeOffice.php | 4 +- .../Slack/Handlers/KeyList.php | 13 ++-- .../Slack/Handlers/SignatureHandler.php | 2 +- .../Slack/Handlers/TakeKeysFrom.php | 8 +-- .../Slack/Rules/SlackUserExistsRule.php | 2 +- .../Slack/Traits/FindsUserBySlackId.php | 4 +- .../Slack/Traits/ListsHandlers.php | 11 +-- config/laravel-slack-slash-command.php | 15 ++-- routes/api.php | 2 +- 54 files changed, 361 insertions(+), 211 deletions(-) create mode 100644 app/Domain/Notifications/Channels.php create mode 100644 app/Domain/Notifications/Notifiable.php delete mode 100644 app/Domain/Slack/Channels/SlackApiChannel.php delete mode 100644 app/Domain/Slack/Handlers/DailySummary.php create mode 100644 app/Infrastructure/Slack/Channels/SlackApiChannel.php rename app/{Domain => Infrastructure}/Slack/Controller.php (80%) create mode 100644 app/Infrastructure/Slack/Elements/AbsencesAttachment.php create mode 100644 app/Infrastructure/Slack/Elements/Attachment.php create mode 100644 app/Infrastructure/Slack/Elements/BirthdaysAttachment.php create mode 100644 app/Infrastructure/Slack/Elements/KeysAttachment.php create mode 100644 app/Infrastructure/Slack/Elements/ListAttachment.php create mode 100644 app/Infrastructure/Slack/Elements/RemotesAttachment.php rename app/{Domain => Infrastructure}/Slack/Exceptions/UserNotFoundException.php (77%) rename app/{Domain => Infrastructure}/Slack/Handlers/CatchAll.php (73%) create mode 100644 app/Infrastructure/Slack/Handlers/DailySummary.php rename app/{Domain => Infrastructure}/Slack/Handlers/GiveKeysTo.php (88%) rename app/{Domain => Infrastructure}/Slack/Handlers/Help.php (68%) rename app/{Domain => Infrastructure}/Slack/Handlers/HomeOffice.php (91%) rename app/{Domain => Infrastructure}/Slack/Handlers/KeyList.php (51%) rename app/{Domain => Infrastructure}/Slack/Handlers/SignatureHandler.php (91%) rename app/{Domain => Infrastructure}/Slack/Handlers/TakeKeysFrom.php (88%) rename app/{Domain => Infrastructure}/Slack/Rules/SlackUserExistsRule.php (91%) rename app/{Domain => Infrastructure}/Slack/Traits/FindsUserBySlackId.php (89%) rename app/{Domain => Infrastructure}/Slack/Traits/ListsHandlers.php (74%) diff --git a/app/Architecture/Providers/AppServiceProvider.php b/app/Architecture/Providers/AppServiceProvider.php index bd8659f..fbfe920 100644 --- a/app/Architecture/Providers/AppServiceProvider.php +++ b/app/Architecture/Providers/AppServiceProvider.php @@ -9,19 +9,19 @@ use Illuminate\Notifications\ChannelManager; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Notification; use Illuminate\Support\ServiceProvider; -use Toby\Domain\Slack\Channels\SlackApiChannel; +use Toby\Infrastructure\Slack\Channels\SlackApiChannel; class AppServiceProvider extends ServiceProvider { public function register(): void { Notification::resolved(function (ChannelManager $service): void { - $service->extend("slack", fn(Application $app) => $app->make(SlackApiChannel::class)); + $service->extend("slack", fn(Application $app): SlackApiChannel => $app->make(SlackApiChannel::class)); }); } public function boot(): void { - Carbon::macro("toDisplayString", fn() => $this->translatedFormat("d.m.Y")); + Carbon::macro("toDisplayString", fn(): string => $this->translatedFormat("d.m.Y")); } } diff --git a/app/Architecture/Providers/AuthServiceProvider.php b/app/Architecture/Providers/AuthServiceProvider.php index cb5b112..62d21c7 100644 --- a/app/Architecture/Providers/AuthServiceProvider.php +++ b/app/Architecture/Providers/AuthServiceProvider.php @@ -30,10 +30,10 @@ class AuthServiceProvider extends ServiceProvider } }); - Gate::define("manageUsers", fn(User $user) => $user->role === Role::AdministrativeApprover); - Gate::define("manageHolidays", fn(User $user) => $user->role === Role::AdministrativeApprover); - Gate::define("manageVacationLimits", fn(User $user) => $user->role === Role::AdministrativeApprover); - Gate::define("generateTimesheet", fn(User $user) => $user->role === Role::AdministrativeApprover); - Gate::define("listMonthlyUsage", fn(User $user) => $user->role === Role::AdministrativeApprover); + Gate::define("manageUsers", fn(User $user): bool => $user->role === Role::AdministrativeApprover); + Gate::define("manageHolidays", fn(User $user): bool => $user->role === Role::AdministrativeApprover); + Gate::define("manageVacationLimits", fn(User $user): bool => $user->role === Role::AdministrativeApprover); + Gate::define("generateTimesheet", fn(User $user): bool => $user->role === Role::AdministrativeApprover); + Gate::define("listMonthlyUsage", fn(User $user): bool => $user->role === Role::AdministrativeApprover); } } diff --git a/app/Architecture/Providers/RouteServiceProvider.php b/app/Architecture/Providers/RouteServiceProvider.php index 2412290..ffd9a41 100644 --- a/app/Architecture/Providers/RouteServiceProvider.php +++ b/app/Architecture/Providers/RouteServiceProvider.php @@ -28,6 +28,6 @@ class RouteServiceProvider extends ServiceProvider protected function configureRateLimiting(): void { - RateLimiter::for("api", fn(Request $request) => Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip())); + RateLimiter::for("api", fn(Request $request): Limit => Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip())); } } diff --git a/app/Domain/CalendarGenerator.php b/app/Domain/CalendarGenerator.php index 30d42b7..b1c6c0f 100644 --- a/app/Domain/CalendarGenerator.php +++ b/app/Domain/CalendarGenerator.php @@ -57,6 +57,6 @@ class CalendarGenerator ->approved() ->with("vacationRequest") ->get() - ->groupBy(fn(Vacation $vacation) => $vacation->date->toDateString()); + ->groupBy(fn(Vacation $vacation): string => $vacation->date->toDateString()); } } diff --git a/app/Domain/DailySummaryRetriever.php b/app/Domain/DailySummaryRetriever.php index 4049738..a2482ef 100644 --- a/app/Domain/DailySummaryRetriever.php +++ b/app/Domain/DailySummaryRetriever.php @@ -22,7 +22,9 @@ class DailySummaryRetriever ->with(["user", "vacationRequest"]) ->whereDate("date", $date) ->approved() - ->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type))) + ->whereTypes( + VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)), + ) ->get(); } @@ -32,7 +34,9 @@ class DailySummaryRetriever ->with(["user", "vacationRequest"]) ->whereDate("date", $date) ->approved() - ->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type))) + ->whereTypes( + VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)), + ) ->get(); } diff --git a/app/Domain/Enums/EmploymentForm.php b/app/Domain/Enums/EmploymentForm.php index daf671d..c3d1767 100644 --- a/app/Domain/Enums/EmploymentForm.php +++ b/app/Domain/Enums/EmploymentForm.php @@ -21,7 +21,7 @@ enum EmploymentForm: string $cases = collect(EmploymentForm::cases()); return $cases->map( - fn(EmploymentForm $enum) => [ + fn(EmploymentForm $enum): array => [ "label" => $enum->label(), "value" => $enum->value, ], diff --git a/app/Domain/Enums/Role.php b/app/Domain/Enums/Role.php index f4be8b9..bd2485c 100644 --- a/app/Domain/Enums/Role.php +++ b/app/Domain/Enums/Role.php @@ -21,7 +21,7 @@ enum Role: string $cases = collect(Role::cases()); return $cases->map( - fn(Role $enum) => [ + fn(Role $enum): array => [ "label" => $enum->label(), "value" => $enum->value, ], diff --git a/app/Domain/Enums/VacationType.php b/app/Domain/Enums/VacationType.php index a93ca3d..7940107 100644 --- a/app/Domain/Enums/VacationType.php +++ b/app/Domain/Enums/VacationType.php @@ -30,7 +30,7 @@ enum VacationType: string $cases = VacationType::all(); return $cases->map( - fn(VacationType $enum) => [ + fn(VacationType $enum): array => [ "label" => $enum->label(), "value" => $enum->value, ], diff --git a/app/Domain/Notifications/Channels.php b/app/Domain/Notifications/Channels.php new file mode 100644 index 0000000..e9c23e2 --- /dev/null +++ b/app/Domain/Notifications/Channels.php @@ -0,0 +1,11 @@ + $this->getName($this->sender), diff --git a/app/Domain/Notifications/KeyHasBeenTakenNotification.php b/app/Domain/Notifications/KeyHasBeenTakenNotification.php index d22467d..71e8b7b 100644 --- a/app/Domain/Notifications/KeyHasBeenTakenNotification.php +++ b/app/Domain/Notifications/KeyHasBeenTakenNotification.php @@ -19,10 +19,10 @@ class KeyHasBeenTakenNotification extends Notification public function via(): array { - return ["slack"]; + return [Channels::SLACK]; } - public function toSlack($notifiable): string + public function toSlack(Notifiable $notifiable): string { return __(":recipient takes key no :key from :sender", [ "recipient" => $this->getName($this->recipient), diff --git a/app/Domain/Notifications/Notifiable.php b/app/Domain/Notifications/Notifiable.php new file mode 100644 index 0000000..b23e554 --- /dev/null +++ b/app/Domain/Notifications/Notifiable.php @@ -0,0 +1,10 @@ +map(fn(Holiday $holiday) => [ + return collect($holidays)->map(fn(Holiday $holiday): array => [ "name" => $holiday->getName([static::LANG_KEY]), "date" => Carbon::createFromTimestamp($holiday->getTimestamp()), ])->values(); diff --git a/app/Domain/Slack/Channels/SlackApiChannel.php b/app/Domain/Slack/Channels/SlackApiChannel.php deleted file mode 100644 index 2741e09..0000000 --- a/app/Domain/Slack/Channels/SlackApiChannel.php +++ /dev/null @@ -1,25 +0,0 @@ -routeNotificationFor("slack", $notification); - - return Http::withToken(config("services.slack.client_token")) - ->post($url, [ - "channel" => $channel, - "text" => $notification->toSlack($notifiable), - ]); - } -} diff --git a/app/Domain/Slack/Handlers/DailySummary.php b/app/Domain/Slack/Handlers/DailySummary.php deleted file mode 100644 index 8a33f80..0000000 --- a/app/Domain/Slack/Handlers/DailySummary.php +++ /dev/null @@ -1,55 +0,0 @@ -make(DailySummaryRetriever::class); - - $now = Carbon::today(); - - $absences = $dailySummaryRetriever->getAbsences($now) - ->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name); - - $remoteDays = $dailySummaryRetriever->getRemoteDays($now) - ->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name); - - $birthdays = $dailySummaryRetriever->getBirthdays($now) - ->map(fn(User $user): string => $user->profile->full_name); - - $absencesAttachment = Attachment::create() - ->setTitle("Nieobecności :sunny:") - ->setColor("#eab308") - ->setText($absences->isNotEmpty() ? $absences->implode("\n") : "Wszyscy dzisiaj pracują :muscle:"); - - $remoteAttachment = Attachment::create() - ->setTitle("Praca zdalna :house_with_garden:") - ->setColor("#527aba") - ->setText($remoteDays->isNotEmpty() ? $remoteDays->implode("\n") : "Wszyscy dzisiaj są w biurze :boom:"); - - $birthdayAttachment = Attachment::create() - ->setTitle("Urodziny :birthday:") - ->setColor("#3c5f97") - ->setText($birthdays->isNotEmpty() ? $birthdays->implode("\n") : "Dzisiaj nikt nie ma urodzin :cry:"); - - return $this->respondToSlack("Podsumowanie dla dnia {$now->toDisplayString()}") - ->withAttachment($absencesAttachment) - ->withAttachment($remoteAttachment) - ->withAttachment($birthdayAttachment); - } -} diff --git a/app/Domain/TimesheetExport.php b/app/Domain/TimesheetExport.php index 8d764d0..47c258d 100644 --- a/app/Domain/TimesheetExport.php +++ b/app/Domain/TimesheetExport.php @@ -18,7 +18,7 @@ class TimesheetExport implements WithMultipleSheets public function sheets(): array { return $this->users - ->map(fn(User $user) => new TimesheetPerUserSheet($user, $this->month, $this->types)) + ->map(fn(User $user): TimesheetPerUserSheet => new TimesheetPerUserSheet($user, $this->month, $this->types)) ->toArray(); } diff --git a/app/Domain/TimesheetPerUserSheet.php b/app/Domain/TimesheetPerUserSheet.php index 8547a5e..891ca34 100644 --- a/app/Domain/TimesheetPerUserSheet.php +++ b/app/Domain/TimesheetPerUserSheet.php @@ -193,8 +193,8 @@ class TimesheetPerUserSheet implements WithTitle, WithHeadings, WithEvents, With ->get() ->groupBy( [ - fn(Vacation $vacation) => $vacation->date->toDateString(), - fn(Vacation $vacation) => $vacation->vacationRequest->type->value, + fn(Vacation $vacation): string => $vacation->date->toDateString(), + fn(Vacation $vacation): string => $vacation->vacationRequest->type->value, ], ); } diff --git a/app/Domain/UserVacationStatsRetriever.php b/app/Domain/UserVacationStatsRetriever.php index 7c11a29..42fdf50 100644 --- a/app/Domain/UserVacationStatsRetriever.php +++ b/app/Domain/UserVacationStatsRetriever.php @@ -42,8 +42,8 @@ class UserVacationStatsRetriever ->states(VacationRequestStatesRetriever::successStates()), ) ->get() - ->groupBy(fn(Vacation $vacation) => strtolower($vacation->date->englishMonth)) - ->map(fn(Collection $items) => $items->count()); + ->groupBy(fn(Vacation $vacation): string => strtolower($vacation->date->englishMonth)) + ->map(fn(Collection $items): int => $items->count()); } public function getPendingVacationDays(User $user, YearPeriod $yearPeriod): int @@ -107,13 +107,13 @@ class UserVacationStatsRetriever { $types = VacationType::all(); - return $types->filter(fn(VacationType $type) => $this->configRetriever->hasLimit($type)); + return $types->filter(fn(VacationType $type): bool => $this->configRetriever->hasLimit($type)); } protected function getNotLimitableVacationTypes(): Collection { $types = VacationType::all(); - return $types->filter(fn(VacationType $type) => !$this->configRetriever->hasLimit($type)); + return $types->filter(fn(VacationType $type): bool => !$this->configRetriever->hasLimit($type)); } } diff --git a/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php b/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php index 299e0a5..3b53892 100644 --- a/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php +++ b/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php @@ -64,6 +64,6 @@ class DoesNotExceedLimitRule implements VacationRequestRule { $types = VacationType::all(); - return $types->filter(fn(VacationType $type) => $this->configRetriever->hasLimit($type)); + return $types->filter(fn(VacationType $type): bool => $this->configRetriever->hasLimit($type)); } } diff --git a/app/Domain/Validation/Rules/VacationTypeCanBeSelected.php b/app/Domain/Validation/Rules/VacationTypeCanBeSelected.php index 2a7050f..a62d675 100644 --- a/app/Domain/Validation/Rules/VacationTypeCanBeSelected.php +++ b/app/Domain/Validation/Rules/VacationTypeCanBeSelected.php @@ -19,7 +19,7 @@ class VacationTypeCanBeSelected implements VacationRequestRule $employmentForm = $vacationRequest->user->profile->employment_form; $availableTypes = VacationType::all() - ->filter(fn(VacationType $type) => $this->configRetriever->isAvailableFor($type, $employmentForm)); + ->filter(fn(VacationType $type): bool => $this->configRetriever->isAvailableFor($type, $employmentForm)); return $availableTypes->contains($vacationRequest->type); } diff --git a/app/Eloquent/Helpers/YearPeriodRetriever.php b/app/Eloquent/Helpers/YearPeriodRetriever.php index cf512cb..d248501 100644 --- a/app/Eloquent/Helpers/YearPeriodRetriever.php +++ b/app/Eloquent/Helpers/YearPeriodRetriever.php @@ -35,7 +35,7 @@ class YearPeriodRetriever $years = YearPeriod::all(); - $navigation = $years->map(fn(YearPeriod $yearPeriod) => $this->toNavigation($yearPeriod)); + $navigation = $years->map(fn(YearPeriod $yearPeriod): array => $this->toNavigation($yearPeriod)); return [ "current" => $this->toNavigation($current), diff --git a/app/Eloquent/Models/Key.php b/app/Eloquent/Models/Key.php index 3b02a68..cb7fc6f 100644 --- a/app/Eloquent/Models/Key.php +++ b/app/Eloquent/Models/Key.php @@ -9,12 +9,13 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Notifications\Notifiable; +use Toby\Domain\Notifications\Notifiable as NotifiableInterface; /** * @property int $id * @property User $user */ -class Key extends Model +class Key extends Model implements NotifiableInterface { use HasFactory; use Notifiable; diff --git a/app/Eloquent/Models/User.php b/app/Eloquent/Models/User.php index 51689d0..dcd3941 100644 --- a/app/Eloquent/Models/User.php +++ b/app/Eloquent/Models/User.php @@ -15,6 +15,7 @@ use Illuminate\Notifications\Notifiable; use Illuminate\Support\Collection; use Toby\Domain\Enums\EmploymentForm; use Toby\Domain\Enums\Role; +use Toby\Domain\Notifications\Notifiable as NotifiableInterface; /** * @property int $id @@ -26,7 +27,7 @@ use Toby\Domain\Enums\Role; * @property Collection $vacationRequests * @property Collection $vacations */ -class User extends Authenticatable +class User extends Authenticatable implements NotifiableInterface { use HasFactory; use Notifiable; @@ -99,7 +100,7 @@ class User extends Authenticatable ->where("email", "ILIKE", "%{$text}%") ->orWhereRelation( "profile", - fn(Builder $query) => $query + fn(Builder $query): Builder => $query ->where("first_name", "ILIKE", "%{$text}%") ->orWhere("last_name", "ILIKE", "%{$text}%"), ); diff --git a/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php b/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php index 2d57e98..139ddb2 100644 --- a/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php +++ b/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php @@ -7,12 +7,13 @@ namespace Toby\Infrastructure\Console\Commands; use Carbon\CarbonInterface; use Illuminate\Console\Command; use Illuminate\Support\Carbon; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Http; -use Spatie\SlashCommand\Attachment; use Toby\Domain\DailySummaryRetriever; use Toby\Eloquent\Models\Holiday; -use Toby\Eloquent\Models\User; -use Toby\Eloquent\Models\Vacation; +use Toby\Infrastructure\Slack\Elements\AbsencesAttachment; +use Toby\Infrastructure\Slack\Elements\BirthdaysAttachment; +use Toby\Infrastructure\Slack\Elements\RemotesAttachment; class SendDailySummaryToSlack extends Command { @@ -27,40 +28,17 @@ class SendDailySummaryToSlack extends Command return; } - $absences = $dailySummaryRetriever->getAbsences($now) - ->map(fn(Vacation $vacation) => $vacation->user->profile->full_name); + $attachments = new Collection([ + new AbsencesAttachment($dailySummaryRetriever->getAbsences($now)), + new RemotesAttachment($dailySummaryRetriever->getRemoteDays($now)), + new BirthdaysAttachment($dailySummaryRetriever->getBirthdays($now)), + ]); - $remoteDays = $dailySummaryRetriever->getRemoteDays($now) - ->map(fn(Vacation $vacation) => $vacation->user->profile->full_name); - - $birthdays = $dailySummaryRetriever->getBirthdays($now) - ->map(fn(User $user) => $user->profile->full_name); - - $absencesAttachment = Attachment::create() - ->setTitle("Nieobecności :palm_tree:") - ->setColor("#eab308") - ->setText($absences->isNotEmpty() ? $absences->implode("\n") : "Wszyscy dzisiaj pracują :muscle:"); - - $remoteAttachment = Attachment::create() - ->setTitle("Praca zdalna :house_with_garden:") - ->setColor("#527aba") - ->setText($remoteDays->isNotEmpty() ? $remoteDays->implode("\n") : "Wszyscy dzisiaj są w biurze :boom:"); - - $birthdayAttachment = Attachment::create() - ->setTitle("Urodziny :birthday:") - ->setColor("#3c5f97") - ->setText($birthdays->isNotEmpty() ? $birthdays->implode("\n") : "Dzisiaj nikt nie ma urodzin :cry:"); - - $baseUrl = config("services.slack.url"); - $url = "{$baseUrl}/chat.postMessage"; - - Http::withToken(config("services.slack.client_token")) - ->post($url, [ - "channel" => config("services.slack.default_channel"), + Http::withToken($this->getSlackClientToken()) + ->post($this->getUrl(), [ + "channel" => $this->getSlackChannel(), "text" => "Podsumowanie dla dnia {$now->toDisplayString()}", - "attachments" => collect([$absencesAttachment, $remoteAttachment, $birthdayAttachment])->map( - fn(Attachment $attachment) => $attachment->toArray(), - )->toArray(), + "attachments" => $attachments, ]); } @@ -78,4 +56,24 @@ class SendDailySummaryToSlack extends Command return true; } + + protected function getUrl(): string + { + return "{$this->getSlackBaseUrl()}/chat.postMessage"; + } + + protected function getSlackBaseUrl(): string + { + return config("services.slack.url"); + } + + protected function getSlackClientToken(): string + { + return config("services.slack.client_token"); + } + + protected function getSlackChannel(): string + { + return config("services.slack.default_channel"); + } } diff --git a/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php b/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php index 79b0bf9..3f3caa5 100644 --- a/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php +++ b/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php @@ -16,6 +16,6 @@ class CalculateVacationDaysController extends Controller { $days = $calculator->calculateDays($request->from(), $request->to()); - return new JsonResponse($days->map(fn(Carbon $day) => $day->toDateString())->all()); + return new JsonResponse($days->map(fn(Carbon $day): string => $day->toDateString())->all()); } } diff --git a/app/Infrastructure/Http/Controllers/Api/GetAvailableVacationTypesController.php b/app/Infrastructure/Http/Controllers/Api/GetAvailableVacationTypesController.php index 22a5f33..48a92a2 100644 --- a/app/Infrastructure/Http/Controllers/Api/GetAvailableVacationTypesController.php +++ b/app/Infrastructure/Http/Controllers/Api/GetAvailableVacationTypesController.php @@ -21,8 +21,8 @@ class GetAvailableVacationTypesController extends Controller $user = User::query()->find($request->get("user")); $types = VacationType::all() - ->filter(fn(VacationType $type) => $configRetriever->isAvailableFor($type, $user->profile->employment_form)) - ->map(fn(VacationType $type) => [ + ->filter(fn(VacationType $type): bool => $configRetriever->isAvailableFor($type, $user->profile->employment_form)) + ->map(fn(VacationType $type): array => [ "label" => $type->label(), "value" => $type->value, ]) diff --git a/app/Infrastructure/Http/Controllers/TimesheetController.php b/app/Infrastructure/Http/Controllers/TimesheetController.php index 16af5f6..2404889 100644 --- a/app/Infrastructure/Http/Controllers/TimesheetController.php +++ b/app/Infrastructure/Http/Controllers/TimesheetController.php @@ -35,8 +35,10 @@ class TimesheetController extends Controller $types = VacationType::all() ->filter( - fn(VacationType $type) => $configRetriever->isAvailableFor($type, EmploymentForm::EmploymentContract) - && $configRetriever->isVacation($type), + fn(VacationType $type): bool => $configRetriever->isAvailableFor( + $type, + EmploymentForm::EmploymentContract, + ) && $configRetriever->isVacation($type), ); $filename = "{$carbonMonth->translatedFormat("F Y")}.xlsx"; diff --git a/app/Infrastructure/Http/Controllers/VacationLimitController.php b/app/Infrastructure/Http/Controllers/VacationLimitController.php index 29c333e..31a7d80 100644 --- a/app/Infrastructure/Http/Controllers/VacationLimitController.php +++ b/app/Infrastructure/Http/Controllers/VacationLimitController.php @@ -30,7 +30,7 @@ class VacationLimitController extends Controller ->sortBy(fn(VacationLimit $limit): string => "{$limit->user->profile->last_name} {$limit->user->profile->first_name}") ->values(); - $limitsResource = $limits->map(fn(VacationLimit $limit) => [ + $limitsResource = $limits->map(fn(VacationLimit $limit): array => [ "id" => $limit->id, "user" => new UserResource($limit->user), "hasVacation" => $limit->hasVacation(), diff --git a/app/Infrastructure/Http/Middleware/HandleInertiaRequests.php b/app/Infrastructure/Http/Middleware/HandleInertiaRequests.php index 7344b7f..15cb0dd 100644 --- a/app/Infrastructure/Http/Middleware/HandleInertiaRequests.php +++ b/app/Infrastructure/Http/Middleware/HandleInertiaRequests.php @@ -32,7 +32,7 @@ class HandleInertiaRequests extends Middleware { $user = $request->user(); - return fn() => [ + return fn(): array => [ "user" => $user ? new UserResource($user) : null, "can" => [ "manageVacationLimits" => $user ? $user->can("manageVacationLimits") : false, @@ -45,7 +45,7 @@ class HandleInertiaRequests extends Middleware protected function getFlashData(Request $request): Closure { - return fn() => [ + return fn(): array => [ "success" => $request->session()->get("success"), "error" => $request->session()->get("error"), "info" => $request->session()->get("info"), diff --git a/app/Infrastructure/Slack/Channels/SlackApiChannel.php b/app/Infrastructure/Slack/Channels/SlackApiChannel.php new file mode 100644 index 0000000..d790555 --- /dev/null +++ b/app/Infrastructure/Slack/Channels/SlackApiChannel.php @@ -0,0 +1,36 @@ +getBaseUrl(); + $url = "{$baseUrl}/chat.postMessage"; + $channel = $notifiable->routeNotificationFor("slack", $notification); + + return Http::withToken($this->getClientToken()) + ->post($url, [ + "channel" => $channel, + "text" => $notification->toSlack($notifiable), + ]); + } + + protected function getClientToken(): string + { + return config("services.slack.client_token"); + } + + protected function getBaseUrl(): string + { + return config("services.slack.url"); + } +} diff --git a/app/Domain/Slack/Controller.php b/app/Infrastructure/Slack/Controller.php similarity index 80% rename from app/Domain/Slack/Controller.php rename to app/Infrastructure/Slack/Controller.php index 616f048..60eaaa5 100644 --- a/app/Domain/Slack/Controller.php +++ b/app/Infrastructure/Slack/Controller.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Toby\Domain\Slack; +namespace Toby\Infrastructure\Slack; use Exception; use Illuminate\Http\Request as IlluminateRequest; @@ -11,6 +11,7 @@ use Illuminate\Support\Collection; use Illuminate\Validation\ValidationException; use Spatie\SlashCommand\Attachment; use Spatie\SlashCommand\Controller as SlackController; +use Spatie\SlashCommand\Exceptions\InvalidRequest; use Spatie\SlashCommand\Exceptions\RequestCouldNotBeHandled; use Spatie\SlashCommand\Exceptions\SlackSlashCommandException; use Spatie\SlashCommand\Response; @@ -18,11 +19,11 @@ use Spatie\SlashCommand\Response; class Controller extends SlackController { /** - * @throws RequestCouldNotBeHandled + * @throws InvalidRequest|RequestCouldNotBeHandled */ public function getResponse(IlluminateRequest $request): IlluminateResponse { - $this->guardAgainstInvalidRequest($request); + $this->verifyWithSigning($request); $handler = $this->determineHandler(); @@ -43,13 +44,13 @@ class Controller extends SlackController { $errors = (new Collection($exception->errors())) ->map( - fn(array $message) => Attachment::create() + fn(array $message): Attachment => Attachment::create() ->setColor("danger") ->setText($message[0]), ); return Response::create($this->request) - ->withText(":x: Komenda `/{$this->request->command} {$this->request->text}` jest niepoprawna:") + ->withText(":x: Polecenie `/{$this->request->command} {$this->request->text}` jest niepoprawna:") ->withAttachments($errors->all()); } } diff --git a/app/Infrastructure/Slack/Elements/AbsencesAttachment.php b/app/Infrastructure/Slack/Elements/AbsencesAttachment.php new file mode 100644 index 0000000..ae00273 --- /dev/null +++ b/app/Infrastructure/Slack/Elements/AbsencesAttachment.php @@ -0,0 +1,22 @@ +setTitle("Nieobecności :palm_tree:") + ->setColor("#eab308") + ->setItems($absences->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name)) + ->setEmptyText("Wszyscy dzisiaj pracują :muscle:"); + } +} \ No newline at end of file diff --git a/app/Infrastructure/Slack/Elements/Attachment.php b/app/Infrastructure/Slack/Elements/Attachment.php new file mode 100644 index 0000000..fe6a342 --- /dev/null +++ b/app/Infrastructure/Slack/Elements/Attachment.php @@ -0,0 +1,12 @@ +setTitle("Urodziny :birthday:") + ->setColor("#3c5f97") + ->setItems($birthdays->map(fn(User $user): string => $user->profile->full_name)) + ->setEmptyText("Dzisiaj nikt nie ma urodzin :cry:"); + } +} \ No newline at end of file diff --git a/app/Infrastructure/Slack/Elements/KeysAttachment.php b/app/Infrastructure/Slack/Elements/KeysAttachment.php new file mode 100644 index 0000000..6702a66 --- /dev/null +++ b/app/Infrastructure/Slack/Elements/KeysAttachment.php @@ -0,0 +1,21 @@ +setColor("#3c5f97") + ->setItems($keys->map(fn(Key $key): string => "Klucz nr {$key->id} - <@{$key->user->profile->slack_id}>")) + ->setEmptyText("Nie ma żadnych kluczy w tobym"); + } +} \ No newline at end of file diff --git a/app/Infrastructure/Slack/Elements/ListAttachment.php b/app/Infrastructure/Slack/Elements/ListAttachment.php new file mode 100644 index 0000000..bccaf7a --- /dev/null +++ b/app/Infrastructure/Slack/Elements/ListAttachment.php @@ -0,0 +1,36 @@ +items = $items; + + return $this; + } + + public function setEmptyText(string $emptyText): static + { + $this->emptyText = $emptyText; + + return $this; + } + + public function toArray(): array + { + $fields = parent::toArray(); + + return array_merge($fields, [ + "text" => $this->items->isNotEmpty() ? $this->items->implode("\n") : $this->emptyText, + ]); + } +} \ No newline at end of file diff --git a/app/Infrastructure/Slack/Elements/RemotesAttachment.php b/app/Infrastructure/Slack/Elements/RemotesAttachment.php new file mode 100644 index 0000000..2b91f44 --- /dev/null +++ b/app/Infrastructure/Slack/Elements/RemotesAttachment.php @@ -0,0 +1,22 @@ +setTitle("Praca zdalna :house_with_garden:") + ->setColor("#527aba") + ->setItems($remoteDays->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name)) + ->setEmptyText("Wszyscy dzisiaj są w biurze :boom:"); + } +} \ No newline at end of file diff --git a/app/Domain/Slack/Exceptions/UserNotFoundException.php b/app/Infrastructure/Slack/Exceptions/UserNotFoundException.php similarity index 77% rename from app/Domain/Slack/Exceptions/UserNotFoundException.php rename to app/Infrastructure/Slack/Exceptions/UserNotFoundException.php index 925e6fb..94a3948 100644 --- a/app/Domain/Slack/Exceptions/UserNotFoundException.php +++ b/app/Infrastructure/Slack/Exceptions/UserNotFoundException.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Toby\Domain\Slack\Exceptions; +namespace Toby\Infrastructure\Slack\Exceptions; use Spatie\SlashCommand\Exceptions\SlackSlashCommandException; diff --git a/app/Domain/Slack/Handlers/CatchAll.php b/app/Infrastructure/Slack/Handlers/CatchAll.php similarity index 73% rename from app/Domain/Slack/Handlers/CatchAll.php rename to app/Infrastructure/Slack/Handlers/CatchAll.php index faeaf7e..ce94256 100644 --- a/app/Domain/Slack/Handlers/CatchAll.php +++ b/app/Infrastructure/Slack/Handlers/CatchAll.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace Toby\Domain\Slack\Handlers; +namespace Toby\Infrastructure\Slack\Handlers; -use Spatie\SlashCommand\Attachment; use Spatie\SlashCommand\Handlers\BaseHandler; use Spatie\SlashCommand\Request; use Spatie\SlashCommand\Response; -use Toby\Domain\Slack\Traits\ListsHandlers; +use Toby\Infrastructure\Slack\Elements\Attachment; +use Toby\Infrastructure\Slack\Traits\ListsHandlers; class CatchAll extends BaseHandler { @@ -24,7 +24,7 @@ class CatchAll extends BaseHandler $handlers = $this->findAvailableHandlers(); $attachmentFields = $this->mapHandlersToAttachments($handlers); - return $this->respondToSlack(":x: Nie rozpoznaję tej komendy. Lista wszystkich komend:") + return $this->respondToSlack(":x: Nie rozpoznaję polecenia. Lista wszystkich poleceń:") ->withAttachment( Attachment::create() ->setColor("danger") diff --git a/app/Infrastructure/Slack/Handlers/DailySummary.php b/app/Infrastructure/Slack/Handlers/DailySummary.php new file mode 100644 index 0000000..5a941ee --- /dev/null +++ b/app/Infrastructure/Slack/Handlers/DailySummary.php @@ -0,0 +1,36 @@ +make(DailySummaryRetriever::class); + + $now = Carbon::today(); + + $attachments = new Collection([ + new AbsencesAttachment($dailySummaryRetriever->getAbsences($now)), + new RemotesAttachment($dailySummaryRetriever->getRemoteDays($now)), + new BirthdaysAttachment($dailySummaryRetriever->getBirthdays($now)), + ]); + + return $this->respondToSlack("Podsumowanie dla dnia {$now->toDisplayString()}") + ->withAttachments($attachments->all()); + } +} diff --git a/app/Domain/Slack/Handlers/GiveKeysTo.php b/app/Infrastructure/Slack/Handlers/GiveKeysTo.php similarity index 88% rename from app/Domain/Slack/Handlers/GiveKeysTo.php rename to app/Infrastructure/Slack/Handlers/GiveKeysTo.php index 0ecb587..7925844 100644 --- a/app/Domain/Slack/Handlers/GiveKeysTo.php +++ b/app/Infrastructure/Slack/Handlers/GiveKeysTo.php @@ -2,16 +2,16 @@ declare(strict_types=1); -namespace Toby\Domain\Slack\Handlers; +namespace Toby\Infrastructure\Slack\Handlers; use Illuminate\Validation\ValidationException; use Spatie\SlashCommand\Request; use Spatie\SlashCommand\Response; use Toby\Domain\Notifications\KeyHasBeenGivenNotification; -use Toby\Domain\Slack\Exceptions\UserNotFoundException; -use Toby\Domain\Slack\Rules\SlackUserExistsRule; -use Toby\Domain\Slack\Traits\FindsUserBySlackId; use Toby\Eloquent\Models\Key; +use Toby\Infrastructure\Slack\Exceptions\UserNotFoundException; +use Toby\Infrastructure\Slack\Rules\SlackUserExistsRule; +use Toby\Infrastructure\Slack\Traits\FindsUserBySlackId; class GiveKeysTo extends SignatureHandler { diff --git a/app/Domain/Slack/Handlers/Help.php b/app/Infrastructure/Slack/Handlers/Help.php similarity index 68% rename from app/Domain/Slack/Handlers/Help.php rename to app/Infrastructure/Slack/Handlers/Help.php index a46d9d1..e5e7ca2 100644 --- a/app/Domain/Slack/Handlers/Help.php +++ b/app/Infrastructure/Slack/Handlers/Help.php @@ -2,19 +2,19 @@ declare(strict_types=1); -namespace Toby\Domain\Slack\Handlers; +namespace Toby\Infrastructure\Slack\Handlers; -use Spatie\SlashCommand\Attachment; use Spatie\SlashCommand\Request; use Spatie\SlashCommand\Response; -use Toby\Domain\Slack\Traits\ListsHandlers; +use Toby\Infrastructure\Slack\Elements\Attachment; +use Toby\Infrastructure\Slack\Traits\ListsHandlers; class Help extends SignatureHandler { use ListsHandlers; protected $signature = "toby pomoc"; - protected $description = "Wyświetl wszystkie dostępne komendy"; + protected $description = "Wyświetl wszystkie dostępne polecenia"; public function handle(Request $request): Response { @@ -22,7 +22,7 @@ class Help extends SignatureHandler $attachmentFields = $this->mapHandlersToAttachments($handlers); - return $this->respondToSlack("Dostępne komendy:") + return $this->respondToSlack("Dostępne polecenia:") ->withAttachment( Attachment::create() ->setColor("good") diff --git a/app/Domain/Slack/Handlers/HomeOffice.php b/app/Infrastructure/Slack/Handlers/HomeOffice.php similarity index 91% rename from app/Domain/Slack/Handlers/HomeOffice.php rename to app/Infrastructure/Slack/Handlers/HomeOffice.php index 5a4cd34..7674539 100644 --- a/app/Domain/Slack/Handlers/HomeOffice.php +++ b/app/Infrastructure/Slack/Handlers/HomeOffice.php @@ -2,16 +2,16 @@ declare(strict_types=1); -namespace Toby\Domain\Slack\Handlers; +namespace Toby\Infrastructure\Slack\Handlers; use Illuminate\Support\Carbon; use Spatie\SlashCommand\Request; use Spatie\SlashCommand\Response; use Toby\Domain\Actions\VacationRequest\CreateAction; use Toby\Domain\Enums\VacationType; -use Toby\Domain\Slack\Traits\FindsUserBySlackId; use Toby\Eloquent\Models\User; use Toby\Eloquent\Models\YearPeriod; +use Toby\Infrastructure\Slack\Traits\FindsUserBySlackId; class HomeOffice extends SignatureHandler { diff --git a/app/Domain/Slack/Handlers/KeyList.php b/app/Infrastructure/Slack/Handlers/KeyList.php similarity index 51% rename from app/Domain/Slack/Handlers/KeyList.php rename to app/Infrastructure/Slack/Handlers/KeyList.php index 9d71bc1..87ef123 100644 --- a/app/Domain/Slack/Handlers/KeyList.php +++ b/app/Infrastructure/Slack/Handlers/KeyList.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace Toby\Domain\Slack\Handlers; +namespace Toby\Infrastructure\Slack\Handlers; -use Spatie\SlashCommand\Attachment; use Spatie\SlashCommand\Request; use Spatie\SlashCommand\Response; use Toby\Eloquent\Models\Key; +use Toby\Infrastructure\Slack\Elements\KeysAttachment; class KeyList extends SignatureHandler { @@ -18,14 +18,9 @@ class KeyList extends SignatureHandler { $keys = Key::query() ->orderBy("id") - ->get() - ->map(fn(Key $key) => "Klucz nr {$key->id} - <@{$key->user->profile->slack_id}>"); + ->get(); return $this->respondToSlack("Lista kluczy :key:") - ->withAttachment( - Attachment::create() - ->setColor("#3c5f97") - ->setText($keys->isNotEmpty() ? $keys->implode("\n") : "Nie ma żadnych kluczy w tobym"), - ); + ->withAttachment(new KeysAttachment($keys)); } } diff --git a/app/Domain/Slack/Handlers/SignatureHandler.php b/app/Infrastructure/Slack/Handlers/SignatureHandler.php similarity index 91% rename from app/Domain/Slack/Handlers/SignatureHandler.php rename to app/Infrastructure/Slack/Handlers/SignatureHandler.php index 626a561..56af5da 100644 --- a/app/Domain/Slack/Handlers/SignatureHandler.php +++ b/app/Infrastructure/Slack/Handlers/SignatureHandler.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Toby\Domain\Slack\Handlers; +namespace Toby\Infrastructure\Slack\Handlers; use Illuminate\Support\Facades\Validator; use Spatie\SlashCommand\Handlers\SignatureHandler as BaseSignatureHandler; diff --git a/app/Domain/Slack/Handlers/TakeKeysFrom.php b/app/Infrastructure/Slack/Handlers/TakeKeysFrom.php similarity index 88% rename from app/Domain/Slack/Handlers/TakeKeysFrom.php rename to app/Infrastructure/Slack/Handlers/TakeKeysFrom.php index e8ac558..5d89eed 100644 --- a/app/Domain/Slack/Handlers/TakeKeysFrom.php +++ b/app/Infrastructure/Slack/Handlers/TakeKeysFrom.php @@ -2,16 +2,16 @@ declare(strict_types=1); -namespace Toby\Domain\Slack\Handlers; +namespace Toby\Infrastructure\Slack\Handlers; use Illuminate\Validation\ValidationException; use Spatie\SlashCommand\Request; use Spatie\SlashCommand\Response; use Toby\Domain\Notifications\KeyHasBeenTakenNotification; -use Toby\Domain\Slack\Exceptions\UserNotFoundException; -use Toby\Domain\Slack\Rules\SlackUserExistsRule; -use Toby\Domain\Slack\Traits\FindsUserBySlackId; use Toby\Eloquent\Models\Key; +use Toby\Infrastructure\Slack\Exceptions\UserNotFoundException; +use Toby\Infrastructure\Slack\Rules\SlackUserExistsRule; +use Toby\Infrastructure\Slack\Traits\FindsUserBySlackId; class TakeKeysFrom extends SignatureHandler { diff --git a/app/Domain/Slack/Rules/SlackUserExistsRule.php b/app/Infrastructure/Slack/Rules/SlackUserExistsRule.php similarity index 91% rename from app/Domain/Slack/Rules/SlackUserExistsRule.php rename to app/Infrastructure/Slack/Rules/SlackUserExistsRule.php index aeb8fe7..500c295 100644 --- a/app/Domain/Slack/Rules/SlackUserExistsRule.php +++ b/app/Infrastructure/Slack/Rules/SlackUserExistsRule.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Toby\Domain\Slack\Rules; +namespace Toby\Infrastructure\Slack\Rules; use Illuminate\Contracts\Validation\Rule; use Illuminate\Support\Str; diff --git a/app/Domain/Slack/Traits/FindsUserBySlackId.php b/app/Infrastructure/Slack/Traits/FindsUserBySlackId.php similarity index 89% rename from app/Domain/Slack/Traits/FindsUserBySlackId.php rename to app/Infrastructure/Slack/Traits/FindsUserBySlackId.php index 0502c3f..b3f1bae 100644 --- a/app/Domain/Slack/Traits/FindsUserBySlackId.php +++ b/app/Infrastructure/Slack/Traits/FindsUserBySlackId.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace Toby\Domain\Slack\Traits; +namespace Toby\Infrastructure\Slack\Traits; use Illuminate\Support\Str; -use Toby\Domain\Slack\Exceptions\UserNotFoundException; use Toby\Eloquent\Models\User; +use Toby\Infrastructure\Slack\Exceptions\UserNotFoundException; trait FindsUserBySlackId { diff --git a/app/Domain/Slack/Traits/ListsHandlers.php b/app/Infrastructure/Slack/Traits/ListsHandlers.php similarity index 74% rename from app/Domain/Slack/Traits/ListsHandlers.php rename to app/Infrastructure/Slack/Traits/ListsHandlers.php index aa8e331..0ec2d1f 100644 --- a/app/Domain/Slack/Traits/ListsHandlers.php +++ b/app/Infrastructure/Slack/Traits/ListsHandlers.php @@ -2,11 +2,12 @@ declare(strict_types=1); -namespace Toby\Domain\Slack\Traits; +namespace Toby\Infrastructure\Slack\Traits; use Illuminate\Support\Collection; use Illuminate\Support\Str; use Spatie\SlashCommand\AttachmentField; +use Spatie\SlashCommand\Handlers\BaseHandler; use Spatie\SlashCommand\Handlers\SignatureHandler; use Spatie\SlashCommand\Handlers\SignatureParts; use Spatie\SlashCommand\HandlesSlashCommand; @@ -16,8 +17,8 @@ trait ListsHandlers protected function findAvailableHandlers(): Collection { return collect(config("laravel-slack-slash-command.handlers")) - ->map(fn(string $handlerClassName) => new $handlerClassName($this->request)) - ->filter(fn(HandlesSlashCommand $handler) => $handler instanceof SignatureHandler) + ->map(fn(string $handlerClassName): BaseHandler => new $handlerClassName($this->request)) + ->filter(fn(HandlesSlashCommand $handler): bool => $handler instanceof SignatureHandler) ->filter(function (SignatureHandler $handler) { $signatureParts = new SignatureParts($handler->getSignature()); @@ -29,13 +30,13 @@ trait ListsHandlers { return $handlers ->sort( - fn(SignatureHandler $handlerA, SignatureHandler $handlerB) => strcmp( + fn(SignatureHandler $handlerA, SignatureHandler $handlerB): int => strcmp( $handlerA->getFullCommand(), $handlerB->getFullCommand(), ), ) ->map( - fn(SignatureHandler $handler) => AttachmentField::create( + fn(SignatureHandler $handler): AttachmentField => AttachmentField::create( $handler->getDescription(), "`/{$handler->getSignature()}`", ), diff --git a/config/laravel-slack-slash-command.php b/config/laravel-slack-slash-command.php index 23eb170..b4f8cfb 100644 --- a/config/laravel-slack-slash-command.php +++ b/config/laravel-slack-slash-command.php @@ -2,17 +2,16 @@ declare(strict_types=1); -use Toby\Domain\Slack\Handlers\CatchAll; -use Toby\Domain\Slack\Handlers\DailySummary; -use Toby\Domain\Slack\Handlers\GiveKeysTo; -use Toby\Domain\Slack\Handlers\Help; -use Toby\Domain\Slack\Handlers\HomeOffice; -use Toby\Domain\Slack\Handlers\KeyList; -use Toby\Domain\Slack\Handlers\TakeKeysFrom; +use Toby\Infrastructure\Slack\Handlers\CatchAll; +use Toby\Infrastructure\Slack\Handlers\DailySummary; +use Toby\Infrastructure\Slack\Handlers\GiveKeysTo; +use Toby\Infrastructure\Slack\Handlers\Help; +use Toby\Infrastructure\Slack\Handlers\HomeOffice; +use Toby\Infrastructure\Slack\Handlers\KeyList; +use Toby\Infrastructure\Slack\Handlers\TakeKeysFrom; return [ "signing_secret" => env("SLACK_SIGNING_SECRET"), - "verify_with_signing" => true, "handlers" => [ TakeKeysFrom::class, GiveKeysTo::class, diff --git a/routes/api.php b/routes/api.php index 9d8bace..3220d19 100644 --- a/routes/api.php +++ b/routes/api.php @@ -3,11 +3,11 @@ declare(strict_types=1); use Illuminate\Support\Facades\Route; -use Toby\Domain\Slack\Controller as SlackController; use Toby\Infrastructure\Http\Controllers\Api\CalculateUserUnavailableDaysController; use Toby\Infrastructure\Http\Controllers\Api\CalculateUserVacationStatsController; use Toby\Infrastructure\Http\Controllers\Api\CalculateVacationDaysController; use Toby\Infrastructure\Http\Controllers\Api\GetAvailableVacationTypesController; +use Toby\Infrastructure\Slack\Controller as SlackController; Route::post("slack", [SlackController::class, "getResponse"]);