wip
This commit is contained in:
		| @@ -7,11 +7,9 @@ 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\Enums\VacationType; | ||||
| use Toby\Domain\VacationTypeConfigRetriever; | ||||
| use Toby\Domain\DailySummaryRetriever; | ||||
| use Toby\Eloquent\Models\Holiday; | ||||
| use Toby\Eloquent\Models\User; | ||||
| use Toby\Eloquent\Models\Vacation; | ||||
| @@ -21,7 +19,7 @@ class SendDailySummaryToSlack extends Command | ||||
|     protected $signature = "toby:slack:daily-summary {--f|force}"; | ||||
|     protected $description = "Sent daily summary to slack"; | ||||
|  | ||||
|     public function handle(VacationTypeConfigRetriever $configRetriever): void | ||||
|     public function handle(DailySummaryRetriever $dailySummaryRetriever): void | ||||
|     { | ||||
|         $now = Carbon::today(); | ||||
|  | ||||
| @@ -29,42 +27,28 @@ class SendDailySummaryToSlack extends Command | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         /** @var Collection $absences */ | ||||
|         $absences = Vacation::query() | ||||
|             ->with(["user", "vacationRequest"]) | ||||
|             ->whereDate("date", $now) | ||||
|             ->approved() | ||||
|             ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => $configRetriever->isVacation($type))) | ||||
|             ->get() | ||||
|         $absences = $dailySummaryRetriever->getAbsences($now) | ||||
|             ->map(fn(Vacation $vacation) => $vacation->user->profile->full_name); | ||||
|  | ||||
|         /** @var Collection $remoteDays */ | ||||
|         $remoteDays = Vacation::query() | ||||
|             ->with(["user", "vacationRequest"]) | ||||
|             ->whereDate("date", $now) | ||||
|             ->approved() | ||||
|             ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => !$configRetriever->isVacation($type))) | ||||
|             ->get() | ||||
|         $remoteDays = $dailySummaryRetriever->getRemoteDays($now) | ||||
|             ->map(fn(Vacation $vacation) => $vacation->user->profile->full_name); | ||||
|  | ||||
|         $birthdays = User::query() | ||||
|             ->whereRelation("profile", "birthday", $now) | ||||
|             ->get() | ||||
|         $birthdays = $dailySummaryRetriever->getBirthdays($now) | ||||
|             ->map(fn(User $user) => $user->profile->full_name); | ||||
|  | ||||
|         $absencesAttachment = Attachment::create() | ||||
|             ->setTitle("Nieobecności :palm_tree:") | ||||
|             ->setColor('#eab308') | ||||
|             ->setColor("#eab308") | ||||
|             ->setText($absences->isNotEmpty() ? $absences->implode("\n") : "Wszyscy dzisiaj pracują :muscle:"); | ||||
|  | ||||
|         $remoteAttachment = Attachment::create() | ||||
|             ->setTitle("Praca zdalna :house_with_garden:") | ||||
|             ->setColor('#d946ef') | ||||
|             ->setColor("#d946ef") | ||||
|             ->setText($remoteDays->isNotEmpty() ? $remoteDays->implode("\n") : "Wszyscy dzisiaj są w biurze :boom:"); | ||||
|  | ||||
|         $birthdayAttachment = Attachment::create() | ||||
|             ->setTitle("Urodziny :birthday:") | ||||
|             ->setColor('#3C5F97') | ||||
|             ->setColor("#3C5F97") | ||||
|             ->setText($birthdays->isNotEmpty() ? $birthdays->implode("\n") : "Dzisiaj nikt nie ma urodzin :cry:"); | ||||
|  | ||||
|         $baseUrl = config("services.slack.url"); | ||||
| @@ -74,8 +58,8 @@ class SendDailySummaryToSlack extends Command | ||||
|             ->post($url, [ | ||||
|                 "channel" => config("services.slack.default_channel"), | ||||
|                 "text" => "Podsumowanie dla dnia {$now->toDisplayString()}", | ||||
|                 'attachments' => collect([$absencesAttachment, $remoteAttachment, $birthdayAttachment])->map( | ||||
|                     fn(Attachment $attachment) => $attachment->toArray() | ||||
|                 "attachments" => collect([$absencesAttachment, $remoteAttachment, $birthdayAttachment])->map( | ||||
|                     fn(Attachment $attachment) => $attachment->toArray(), | ||||
|                 )->toArray(), | ||||
|             ]); | ||||
|     } | ||||
|   | ||||
| @@ -7,12 +7,11 @@ namespace Toby\Infrastructure\Http\Controllers; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Carbon; | ||||
| use Inertia\Response; | ||||
| use Toby\Domain\Enums\VacationType; | ||||
| use Toby\Domain\DailySummaryRetriever; | ||||
| use Toby\Domain\UserVacationStatsRetriever; | ||||
| use Toby\Domain\VacationRequestStatesRetriever; | ||||
| use Toby\Domain\VacationTypeConfigRetriever; | ||||
| use Toby\Eloquent\Helpers\YearPeriodRetriever; | ||||
| use Toby\Eloquent\Models\Vacation; | ||||
| use Toby\Eloquent\Models\VacationRequest; | ||||
| use Toby\Infrastructure\Http\Resources\HolidayResource; | ||||
| use Toby\Infrastructure\Http\Resources\VacationRequestResource; | ||||
| @@ -25,24 +24,14 @@ class DashboardController extends Controller | ||||
|         YearPeriodRetriever $yearPeriodRetriever, | ||||
|         UserVacationStatsRetriever $vacationStatsRetriever, | ||||
|         VacationTypeConfigRetriever $configRetriever, | ||||
|         DailySummaryRetriever $dailySummaryRetriever, | ||||
|     ): Response { | ||||
|         $user = $request->user(); | ||||
|         $now = Carbon::now(); | ||||
|         $yearPeriod = $yearPeriodRetriever->selected(); | ||||
|  | ||||
|         $absences = Vacation::query() | ||||
|             ->with(["user", "vacationRequest"]) | ||||
|             ->whereDate("date", $now) | ||||
|             ->approved() | ||||
|             ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => $configRetriever->isVacation($type))) | ||||
|             ->get(); | ||||
|  | ||||
|         $remoteDays = Vacation::query() | ||||
|             ->with(["user", "vacationRequest"]) | ||||
|             ->whereDate("date", $now) | ||||
|             ->approved() | ||||
|             ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => !$configRetriever->isVacation($type))) | ||||
|             ->get(); | ||||
|         $absences = $dailySummaryRetriever->getAbsences($now); | ||||
|         $remoteDays = $dailySummaryRetriever->getRemoteDays($now); | ||||
|  | ||||
|         if ($user->can("listAll", VacationRequest::class)) { | ||||
|             $vacationRequests = $yearPeriod->vacationRequests() | ||||
|   | ||||
| @@ -8,6 +8,8 @@ use Illuminate\Auth\Access\AuthorizationException; | ||||
| use Illuminate\Http\Request; | ||||
| use Inertia\Response; | ||||
| use Symfony\Component\HttpFoundation\RedirectResponse; | ||||
| use Toby\Domain\Notifications\KeyHasBeenGivenNotification; | ||||
| use Toby\Domain\Notifications\KeyHasBeenTakenNotification; | ||||
| use Toby\Eloquent\Models\Key; | ||||
| use Toby\Eloquent\Models\User; | ||||
| use Toby\Infrastructure\Http\Requests\GiveKeyRequest; | ||||
| @@ -60,6 +62,8 @@ class KeysController extends Controller | ||||
|  | ||||
|         $key->save(); | ||||
|  | ||||
|         $key->notify(new KeyHasBeenTakenNotification($request->user(), $previousUser)); | ||||
|  | ||||
|         return redirect() | ||||
|             ->back() | ||||
|             ->with("success", __("Key no :number has been taken from :user.", [ | ||||
| @@ -81,6 +85,8 @@ class KeysController extends Controller | ||||
|  | ||||
|         $key->save(); | ||||
|  | ||||
|         $key->notify(new KeyHasBeenGivenNotification($request->user(), $recipient)); | ||||
|  | ||||
|         return redirect() | ||||
|             ->back() | ||||
|             ->with("success", __("Key no :number has been given to :user.", [ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user