Skip to content
Permalink
Browse files

Adds create commenter functionality

  • Loading branch information...
jacobemerick committed May 10, 2016
1 parent 0532616 commit 1a04a164a75ffa18ffa33e245e3c0edb07d66a56
Showing with 48 additions and 0 deletions.
  1. +48 −0 src/Controller/Commenter.php
@@ -0,0 +1,48 @@
<?php
namespace Jacobemerick\CommentService\Controller;
use Interop\Container\ContainerInterface as Container;
use Jacobemerick\CommentService\Model\Commenter as CommenterModel;
use Psr\Http\Message\RequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
class Comment
{
/** @var Container */
protected $container;
/**
* @param Container $container
*/
public function __construct(Container $container)
{
$this->container = $container;
}
/**
* @param Request $request
* @param Response $response
*/
public function createCommenter(Request $req, Response $res)
{
// todo something something validation
$body = $req->getParsedBody();
$commenterModel = new CommenterModel($this->container->get('dbal'));
$commenterId = $commenterModel->findByFields(
$body['commenter']['name'],
$body['commenter']['email'],
$body['commenter']['website']
);
if (!$commenterId) {
$commenterId = $commenterModel->create(
$body['commenter']['name'],
$body['commenter']['email'],
$body['commenter']['website']
);
}
}
}

0 comments on commit 1a04a16

Please sign in to comment.
You can’t perform that action at this time.