Skip to content

Commit

Permalink
issue #237 Вынес ответ в контроллер (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
iMega authored Jan 21, 2017
1 parent 7ca68e6 commit 55caeed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
26 changes: 10 additions & 16 deletions src/Kubikvest/Handler/Checkpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@
namespace Kubikvest\Handler;

use Kubikvest\Resource;
use Kubikvest\Validator\AccuracyLessDistance;
use Kubikvest\Validator\PlayerAtRightPlace;
use Kubikvest\Validator\PlayerFinished;
use Kubikvest\Validator\PointIncludedAccuracyRange;
use Kubikvest\Validator\PositionAroundBorderSector;
use Kubikvest\Validator\PositionInsideSector;
use Kubikvest\Validator;
use Silex\Application;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Kubikvest\Model;

Expand All @@ -45,7 +39,7 @@ public function __construct(Application $app)
/**
* @param Request $request
*
* @return JsonResponse
* @return Resource\Respondent
*/
public function handle(Request $request)
{
Expand All @@ -71,25 +65,25 @@ public function handle(Request $request)
$response->setPoint($point);
$response->setQuest($quest);

$validator = new PlayerAtRightPlace(
new PositionInsideSector($position, $point->getSector()),
new PointIncludedAccuracyRange($position),
new AccuracyLessDistance($position, $point->getSector()),
new PositionAroundBorderSector($position, $point->getSector())
$validator = new Validator\PlayerAtRightPlace(
new Validator\PositionInsideSector($position, $point->getSector()),
new Validator\PointIncludedAccuracyRange($position),
new Validator\AccuracyLessDistance($position, $point->getSector()),
new Validator\PositionAroundBorderSector($position, $point->getSector())
);
if (!$validator->validate()) {
$response->error = 'Не верное место отметки.';
$response->addLink(Model\LinkGenerator::CHECKPOINT);

return (new Resource\Checkpoint\Respondent($response))->response();
return new Resource\Checkpoint\Respondent($response);
}

/**
* @var Resource\Group\Updater $groupUpdater
*/
$groupUpdater = $this->app[Resource\Group\Updater::class];

if ((new PlayerFinished($group, $quest))->validate()) {
if ((new Validator\PlayerFinished($group, $quest))->validate()) {
$group->active = false;
$groupUpdater->update($group);
$response->finish = true;
Expand All @@ -108,6 +102,6 @@ public function handle(Request $request)
]
);

return (new Resource\Checkpoint\Respondent($response))->response();
return new Resource\Checkpoint\Respondent($response);
}
}
4 changes: 3 additions & 1 deletion web/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
]
);

return (new \Kubikvest\Handler\Checkpoint($app))->handle($request);
$respondent = (new \Kubikvest\Handler\Checkpoint($app))->handle($request);

return $respondent->response();
});

$app->get('/finish', function (Request $request) use ($app) {
Expand Down

0 comments on commit 55caeed

Please sign in to comment.