Skip to content

Commit

Permalink
Check if good answer is not in bad answers (#43)
Browse files Browse the repository at this point in the history
* Check if good answer is not in bad answers
  • Loading branch information
NolwennD authored Feb 20, 2023
1 parent 7b9868f commit 4a721a4
Show file tree
Hide file tree
Showing 25 changed files with 950 additions and 1,083 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.idea
8 changes: 4 additions & 4 deletions qvgds-back/app/Http/Controllers/DTO/RestGame.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private function __construct(
private string $player,

#[OA\Property]
private int $step,
private int $level,

#[OA\Property]
private int $shitcoins,
Expand All @@ -49,9 +49,9 @@ public function getPlayer(): string
return $this->player;
}

public function getStep(): int
public function getLevel(): int
{
return $this->step;
return $this->level;
}

public function getShitcoins(): int
Expand All @@ -75,7 +75,7 @@ public static function from(Game $game): self
return new self(
$game->id()->get(),
$game->player(),
$game->step(),
$game->step()->value,
$game->shitCoins()->amount(),
$game->status(),
RestJoker::fromGame($game)
Expand Down
2 changes: 1 addition & 1 deletion qvgds-back/app/Http/Controllers/GamesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function currentQuestion(string $gameId): Response
$currentQuestion = $game->currentQuestion();

$json = [
"reward" => ShitCoins::fromLevel($game->step(), $game->status())->amount(),
"reward" => ShitCoins::from($game->step()->value)->amount(),
"step" => $game->step(),
"question" => $currentQuestion->text(),
"answers" => $this->serializeAnswers($currentQuestion),
Expand Down
2 changes: 1 addition & 1 deletion qvgds-back/app/Http/Controllers/SessionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static function serializeQuestion(Question $question): array
return [
"id" => $question->id()->get(),
"text" => $question->text(),
"step" => $question->step(),
"step" => $question->level(),
"goodAnswer" => $question->goodAnswer()->text,
"badAnswers" => array_map(fn(Answer $answer): string => $answer->text, $question->badAnswers())
];
Expand Down
3 changes: 2 additions & 1 deletion qvgds-back/app/Repositories/LaravelGamesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use QVGDS\Game\Domain\Joker\Jokers;
use QVGDS\Game\Domain\Joker\JokerStatus;
use QVGDS\Game\Domain\Joker\JokerType;
use QVGDS\Game\Domain\Level;
use QVGDS\Session\Domain\Session;
use Ramsey\Uuid\Uuid;

Expand Down Expand Up @@ -83,7 +84,7 @@ private function toDomain(LaravelGame $laravelGame): Game
new Jokers(...$laravelGame->jokers()->get()->map(fn(LaravelJoker $joker) => $this->buildJoker($joker))->toArray()),
$laravelGame->session()->get()->map(fn(LaravelSession $session): Session => LaravelSessionsRepository::toDomain($session))->first(),
$this->buildGameStatus($laravelGame->status),
$laravelGame->step
Level::from($laravelGame->step)
);
}

Expand Down
5 changes: 3 additions & 2 deletions qvgds-back/app/Repositories/LaravelSessionsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use App\Models\LaravelQuestion;
use App\Models\LaravelSession;
use QVGDS\Game\Domain\Level;
use QVGDS\Session\Domain\Question\Answer;
use QVGDS\Session\Domain\Question\BadAnswers;
use QVGDS\Session\Domain\Question\GoodAnswer;
Expand Down Expand Up @@ -58,7 +59,7 @@ public static function toDomain(LaravelSession $laravelSession): Session
$questions = $laravelSession->questions()->get()->map(
fn(LaravelQuestion $q): Question => new Question(
new QuestionId(Uuid::fromString($q->id)),
$q->step,
Level::from($q->step,),
$q->question,
new GoodAnswer(new Answer($q->good_answer)),
new BadAnswers(
Expand All @@ -82,7 +83,7 @@ private function toLaravelQuestion(Question $question, SessionId $sessionId): vo
[
"id" => $question->id()->get(),
"session" => $sessionId->get(),
"step" => $question->step(),
"step" => $question->level(),
"question" => $question->text(),
"good_answer" => $question->goodAnswer()->text,
"bad_answer1" => $question->badAnswers()[0]->text,
Expand Down
2 changes: 1 addition & 1 deletion qvgds-back/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^6.1",
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^9",
"phpunit/phpunit": "^10",
"spatie/laravel-ignition": "^1.0"
},
"scripts": {
Expand Down
Loading

0 comments on commit 4a721a4

Please sign in to comment.