wip
This commit is contained in:
		
							
								
								
									
										49
									
								
								app/Domain/Slack/GiveKeysTo.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								app/Domain/Slack/GiveKeysTo.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | ||||
| <?php | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Toby\Domain\Slack; | ||||
|  | ||||
| use Illuminate\Support\Str; | ||||
| use Spatie\SlashCommand\Request; | ||||
| use Spatie\SlashCommand\Response; | ||||
| use Spatie\SlashCommand\Handlers\SignatureHandler; | ||||
| use Toby\Eloquent\Models\Key; | ||||
| use Toby\Eloquent\Models\User; | ||||
|  | ||||
| class GiveKeysTo extends SignatureHandler | ||||
| { | ||||
|     protected $signature = "toby klucze:dla {to}"; | ||||
|  | ||||
|     protected $description = "Daj klucze użytkownikowi {to}"; | ||||
|  | ||||
|     public function handle(Request $request): Response | ||||
|     { | ||||
|         $to = $this->getArgument('to'); | ||||
|  | ||||
|         $id = Str::between($to, "@", "|"); | ||||
|  | ||||
|         $authUser = $this->findUserBySlackId($request->userId); | ||||
|         $user = $this->findUserBySlackId($id); | ||||
|  | ||||
|         /** @var Key $key */ | ||||
|         $key = $authUser->keys()->first(); | ||||
|  | ||||
|         $key->user()->associate($user); | ||||
|  | ||||
|         $key->save(); | ||||
|  | ||||
|         return $this->respondToSlack("<@{$authUser->profile->slack_id}> daje klucz nr {$key->id} użytkownikowi <@{$user->profile->slack_id}>") | ||||
|             ->displayResponseToEveryoneOnChannel(); | ||||
|     } | ||||
|  | ||||
|     protected function findUserBySlackId(string $slackId): User | ||||
|     { | ||||
|         /** @var User $user */ | ||||
|         $user = User::query() | ||||
|             ->whereRelation("profile", "slack_id", $slackId) | ||||
|             ->first(); | ||||
|  | ||||
|         return $user; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										58
									
								
								app/Domain/Slack/HomeOffice.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								app/Domain/Slack/HomeOffice.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,58 @@ | ||||
| <?php | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Toby\Domain\Slack; | ||||
|  | ||||
| use Illuminate\Support\Carbon; | ||||
| use Spatie\SlashCommand\Request; | ||||
| use Spatie\SlashCommand\Response; | ||||
| use Spatie\SlashCommand\Handlers\SignatureHandler; | ||||
| use Toby\Domain\Actions\VacationRequest\CreateAction; | ||||
| use Toby\Domain\Enums\VacationType; | ||||
| use Toby\Eloquent\Models\User; | ||||
| use Toby\Eloquent\Models\YearPeriod; | ||||
|  | ||||
| class HomeOffice extends SignatureHandler | ||||
| { | ||||
|     protected $signature = "toby zdalnie {date=dzisiaj}"; | ||||
|     protected $description = "Praca zdalna {kiedy}"; | ||||
|  | ||||
|     public function handle(Request $request): Response | ||||
|     { | ||||
|         $date = $this->getDateFromArgument($this->getArgument('date')); | ||||
|         $user = $this->findUserBySlackId($request->userId); | ||||
|  | ||||
|         $yearPeriod = YearPeriod::findByYear($date->year); | ||||
|  | ||||
|         app(CreateAction::class)->execute([ | ||||
|             "user_id" => $user->id, | ||||
|             "type" => VacationType::HomeOffice, | ||||
|             "from" => $date, | ||||
|             "to" => $date, | ||||
|             "year_period_id" => $yearPeriod->id, | ||||
|             "flow_skipped" => false, | ||||
|         ], $user); | ||||
|  | ||||
|         return $this->respondToSlack("Praca zdalna dnia {$date->toDisplayString()} została utworzona pomyślnie"); | ||||
|     } | ||||
|  | ||||
|     protected function getDateFromArgument(string $argument): Carbon | ||||
|     { | ||||
|         return match ($argument) { | ||||
|             "dzisiaj" => Carbon::today(), | ||||
|             "jutro" => Carbon::tomorrow(), | ||||
|             default => Carbon::create($argument), | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     protected function findUserBySlackId(string $slackId): User | ||||
|     { | ||||
|         /** @var User $user */ | ||||
|         $user = User::query() | ||||
|             ->whereRelation("profile", "slack_id", $slackId) | ||||
|             ->first(); | ||||
|  | ||||
|         return $user; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										30
									
								
								app/Domain/Slack/KeyList.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								app/Domain/Slack/KeyList.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| <?php | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Toby\Domain\Slack; | ||||
|  | ||||
| use Spatie\SlashCommand\Request; | ||||
| use Spatie\SlashCommand\Response; | ||||
| use Spatie\SlashCommand\Handlers\SignatureHandler; | ||||
| use Toby\Eloquent\Models\Key; | ||||
|  | ||||
| class KeyList extends SignatureHandler | ||||
| { | ||||
|     protected $signature = "toby klucze"; | ||||
|  | ||||
|     protected $description = "Lista wszystkich kluczy"; | ||||
|  | ||||
|     public function handle(Request $request): Response | ||||
|     { | ||||
|         $temp = []; | ||||
|  | ||||
|         foreach (Key::orderBy("id")->get() as $key) { | ||||
|             $temp[] = "Klucz nr {$key->id} - <@{$key->user->profile->slack_id}>"; | ||||
|         } | ||||
|  | ||||
|  | ||||
|         return $this->respondToSlack(implode("\n", $temp)) | ||||
|             ->displayResponseToEveryoneOnChannel(); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										49
									
								
								app/Domain/Slack/TakeKeysFrom.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								app/Domain/Slack/TakeKeysFrom.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | ||||
| <?php | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Toby\Domain\Slack; | ||||
|  | ||||
| use Illuminate\Support\Str; | ||||
| use Spatie\SlashCommand\Request; | ||||
| use Spatie\SlashCommand\Response; | ||||
| use Spatie\SlashCommand\Handlers\SignatureHandler; | ||||
| use Toby\Eloquent\Models\Key; | ||||
| use Toby\Eloquent\Models\User; | ||||
|  | ||||
| class TakeKeysFrom extends SignatureHandler | ||||
| { | ||||
|     protected $signature = "toby klucze:od {from}"; | ||||
|  | ||||
|     protected $description = "Zabierz klucze użytkownikowi {from}"; | ||||
|  | ||||
|     public function handle(Request $request): Response | ||||
|     { | ||||
|         $from = $this->getArgument('from'); | ||||
|  | ||||
|         $id = Str::between($from, "@", "|"); | ||||
|  | ||||
|         $authUser = $this->findUserBySlackId($request->userId); | ||||
|         $user = $this->findUserBySlackId($id); | ||||
|  | ||||
|         /** @var Key $key */ | ||||
|         $key = $user->keys()->first(); | ||||
|  | ||||
|         $key->user()->associate($authUser); | ||||
|  | ||||
|         $key->save(); | ||||
|  | ||||
|         return $this->respondToSlack("<@{$authUser->profile->slack_id}> zabiera klucz nr {$key->id} użytkownikowi <@{$user->profile->slack_id}>") | ||||
|             ->displayResponseToEveryoneOnChannel(); | ||||
|     } | ||||
|  | ||||
|     protected function findUserBySlackId(string $slackId): User | ||||
|     { | ||||
|         /** @var User $user */ | ||||
|         $user = User::query() | ||||
|             ->whereRelation("profile", "slack_id", $slackId) | ||||
|             ->first(); | ||||
|  | ||||
|         return $user; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user