-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from deanblackborough/main
v0.16.0
- Loading branch information
Showing
13 changed files
with
272 additions
and
90 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,88 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace App\Actions\Game; | ||
|
||
use App\Actions\Action; | ||
use App\Api\Service; | ||
use App\Models\ShareToken; | ||
|
||
/** | ||
* @author Dean Blackborough <[email protected]> | ||
* @copyright Dean Blackborough (Costs to Expect) 2018-2022 | ||
* https://github.com/costs-to-expect/yahtzee/blob/main/LICENSE | ||
*/ | ||
class DeletePlayer extends Action | ||
{ | ||
public function __invoke( | ||
Service $api, | ||
string $resource_type_id, | ||
string $resource_id, | ||
string $game_id, | ||
string $player_id | ||
): int | ||
{ | ||
// Delete the score sheet if it exists for the player | ||
$score_sheet_response = $api->getPlayerScoreSheet( | ||
$resource_type_id, | ||
$resource_id, | ||
$game_id, | ||
$player_id | ||
); | ||
|
||
if ($score_sheet_response['status'] === 200) { | ||
|
||
$response = $api->deletePlayerScoreSheet( | ||
$resource_type_id, | ||
$resource_id, | ||
$game_id, | ||
$score_sheet_response['content']['key'] | ||
); | ||
|
||
if ($response['status'] !== 204) { | ||
throw new \RuntimeException('Unable to delete score sheet for player with id ' . | ||
$score_sheet_response['content']['key'] . ', error ' . $response['content']); | ||
} | ||
} | ||
|
||
// Delete the player from the assignments | ||
// We need all the players to work out which id to delete | ||
$assigned_players_response = $api->getAssignedGamePlayers( | ||
$resource_type_id, | ||
$resource_id, | ||
$game_id | ||
); | ||
|
||
if ($assigned_players_response['status'] !== 200) { | ||
throw new \RuntimeException('Unable to fetch the assigned game players'); | ||
} | ||
|
||
foreach($assigned_players_response['content'] as $player) { | ||
|
||
if ($player['category']['id'] === $player_id) { | ||
$response = $api->deleteAssignedGamePlayer( | ||
$resource_type_id, | ||
$resource_id, | ||
$game_id, | ||
$player['id'] | ||
); | ||
|
||
if ($response['status'] !== 204) { | ||
throw new \RuntimeException( | ||
'Unable to delete player with id ' . $player['id'] . ', error ' . | ||
$response['content'] | ||
); | ||
} | ||
|
||
break; | ||
} | ||
} | ||
|
||
ShareToken::query() | ||
->where('game_id', $game_id) | ||
->where('player_id', $player_id) | ||
->delete(); | ||
|
||
return 204; | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Oops, something went wrong.