-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #250 - wip * #250 - wip * #250 - wip * #250 - fix * #250 - fix * #250 - fix * Apply suggestions from code review Co-authored-by: Krzysztof Rewak <[email protected]> --------- Co-authored-by: Krzysztof Rewak <[email protected]>
- Loading branch information
1 parent
3454ecf
commit 16d2277
Showing
5 changed files
with
109 additions
and
5 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
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toby\Infrastructure\Slack\Handlers; | ||
|
||
use Illuminate\Validation\ValidationException; | ||
use Spatie\SlashCommand\Request; | ||
use Spatie\SlashCommand\Response; | ||
use Toby\Domain\Notifications\KeyHasBeenLeftInTheOffice; | ||
use Toby\Eloquent\Models\Key; | ||
use Toby\Infrastructure\Slack\Exceptions\UserNotFoundException; | ||
use Toby\Infrastructure\Slack\Traits\FindsUserBySlackId; | ||
|
||
class LeaveKeysInOffice extends SignatureHandler | ||
{ | ||
use FindsUserBySlackId; | ||
|
||
protected $signature = "toby klucze:biuro:zostaw"; | ||
protected $description = "Leave the keys in the office."; | ||
|
||
/** | ||
* @throws UserNotFoundException | ||
* @throws ValidationException | ||
*/ | ||
public function handle(Request $request): Response | ||
{ | ||
$authUser = $this->findUserBySlackIdOrFail($request->userId); | ||
|
||
/** @var Key|null $key */ | ||
$key = $authUser->keys()->first(); | ||
|
||
if (!$key) { | ||
throw ValidationException::withMessages(["key" => __("You don't have any key to leave in the office.")]); | ||
} | ||
|
||
$key->user()->associate(null); | ||
|
||
$key->save(); | ||
|
||
$key->notify(new KeyHasBeenLeftInTheOffice($authUser)); | ||
|
||
return $this->respondToSlack( | ||
__(":white_check_mark: Key no. :number has been left in the office", ["number" => $key->id]), | ||
); | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toby\Infrastructure\Slack\Handlers; | ||
|
||
use Illuminate\Validation\ValidationException; | ||
use Spatie\SlashCommand\Request; | ||
use Spatie\SlashCommand\Response; | ||
use Toby\Domain\Notifications\KeyHasBeenTakenFromTheOfficeNotification; | ||
use Toby\Eloquent\Models\Key; | ||
use Toby\Infrastructure\Slack\Exceptions\UserNotFoundException; | ||
use Toby\Infrastructure\Slack\Traits\FindsUserBySlackId; | ||
|
||
class TakeKeysFromOffice extends SignatureHandler | ||
{ | ||
use FindsUserBySlackId; | ||
|
||
protected $signature = "toby klucze:biuro:wez"; | ||
protected $description = "Take the keys from the office."; | ||
|
||
/** | ||
* @throws UserNotFoundException | ||
* @throws ValidationException | ||
*/ | ||
public function handle(Request $request): Response | ||
{ | ||
$authUser = $this->findUserBySlackIdOrFail($request->userId); | ||
|
||
/** @var Key|null $key */ | ||
$key = Key::query()->whereNull("user_id")->first(); | ||
|
||
if (!$key) { | ||
throw ValidationException::withMessages(["key" => __("There are no keys in the office.")]); | ||
} | ||
|
||
$key->user()->associate($authUser); | ||
|
||
$key->save(); | ||
|
||
$key->notify(new KeyHasBeenTakenFromTheOfficeNotification($authUser)); | ||
|
||
return $this->respondToSlack( | ||
__(":white_check_mark: Key no. :number has been taken from the office", ["number" => $key->id]), | ||
); | ||
} | ||
} |
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