Skip to content

Commit

Permalink
Updates CommentController to interface with new models
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobemerick committed May 6, 2016
1 parent 2613275 commit fc53361
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions src/Controller/Comment.php
Expand Up @@ -5,6 +5,8 @@
use Interop\Container\ContainerInterface as Container;
use Jacobemerick\CommentService\Model\Comment as CommentModel;
use Jacobemerick\CommentService\Model\Commenter as CommenterModel;
use Jacobemerick\CommentService\Model\CommentBody as CommentBodyModel;
use Jacobemerick\CommentService\Model\CommentLocation as CommentLocationModel;
use Psr\Http\Message\RequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;

Expand Down Expand Up @@ -35,25 +37,46 @@ public function getComments(Request $request, Response $response)
* @param Request $request
* @param Response $response
*/
public function createComment(Request $request, Response $response)
public function createComment(Request $req, Response $res)
{
// todo something something validation

$body = $req->getParsedBody();

// todo option to pass in by commenter id
$commenterModel = new CommenterModel($this->container->get('dbal'));
$commenterId = $commenterModel->findByFields(
$request->getParsedBody()['commenter']['name'],
$request->getParsedBody()['commenter']['email'],
$request->getParsedBody()['commenter']['website']
$body['commenter']['name'],
$body['commenter']['email'],
$body['commenter']['website']
);
if (!$commenterId) {
$commenterId = $commenterModel->create(
$request->getParsedBody()['commenter']['name'],
$request->getParsedBody()['commenter']['email'],
$request->getParsedBody()['commenter']['website']
$body['commenter']['name'],
$body['commenter']['email'],
$body['commenter']['website']
);
}

$bodyModel = new CommentBodyModel($this->container->get('dbal'));
$bodyId = $bodyModel->create($body['body']);

$locationModel = new CommentLocationModel($this->container->get('dbal'));
$locationId = $locationModel->findByFields(
$body['domain'],
$body['path'],
$body['thread']
);
if (!$locationId) {
$locationId = $locationModel->create(
$body['domain'],
$body['path'],
$body['thread']
);
}

var_dump($commenterId);
return $response;
return $res;
}

/**
Expand Down

0 comments on commit fc53361

Please sign in to comment.