Merged in create-ticket/comment (pull request #18)

Create ticket/comment
This commit is contained in:
Ivan Diaz 2016-07-08 04:02:55 -03:00
commit 89b2e52e87
11 changed files with 101 additions and 21 deletions

View File

@ -1,9 +1,11 @@
<?php <?php
include 'ticket/create.php'; include 'ticket/create.php';
include 'ticket/comment.php';
$ticketControllers = new ControllerGroup(); $ticketControllers = new ControllerGroup();
$ticketControllers->setGroupPath('/ticket'); $ticketControllers->setGroupPath('/ticket');
$ticketControllers->addController(new CreateController); $ticketControllers->addController(new CreateController);
$ticketControllers->addController(new CommentController);
$ticketControllers->finalize(); $ticketControllers->finalize();

View File

@ -0,0 +1,32 @@
<?php
use RedBeanPHP\Facade as RedBean;
class CommentController extends Controller {
const PATH = '/comment';
private $ticketId;
private $content;
public function handler() {
$this->requestData();
$this->storeComment();
Response::respondSuccess();
}
private function requestData() {
$this->ticketId = Controller::request('ticketId');
$this->content = Controller::request('content');
}
private function storeComment() {
$comment = new Comment();
$comment->setProperties(array(
'content' => $this->content
));
$ticket = Ticket::getTicket($this->ticketId);
$ticket->addComment($comment);
$ticket->store();
}
}

View File

@ -1,4 +1,5 @@
<?php <?php
use RedBeanPHP\Facade as RedBean;
use Respect\Validation\Validator as DataValidator; use Respect\Validation\Validator as DataValidator;
@ -51,11 +52,12 @@ class CreateController extends Controller {
'file' => '', 'file' => '',
'date' => date('F j, Y, g:i a'), 'date' => date('F j, Y, g:i a'),
'unread' => false, 'unread' => false,
'closed' => false, 'closed' => false
'author' => '',
'owner'=> '',
'ownComments' => []
)); ));
//TODO: Add logged user as author
$ticket->setAuthor(User::getUser(1));
$ticket->store(); $ticket->store();
} }
} }

View File

@ -45,6 +45,7 @@ class LoginController extends Controller {
return array( return array(
'userId' => $userInstance->id, 'userId' => $userInstance->id,
'list' => count($userInstance->ownTicketList),
'userEmail' => $userInstance->email, 'userEmail' => $userInstance->email,
'token' => $this->getSession()->getToken() 'token' => $this->getSession()->getToken()
); );

View File

@ -1,4 +1,5 @@
<?php <?php
use RedBeanPHP\Facade as RedBean;
class SignUpController extends Controller { class SignUpController extends Controller {
const PATH = '/signup'; const PATH = '/signup';

View File

@ -1,7 +1,7 @@
<?php <?php
class Comment extends DataStore { class Comment extends DataStore {
const TABLE = 'comments'; const TABLE = 'comment';
public static function getProps() { public static function getProps() {
return array( return array(

View File

@ -1,11 +1,14 @@
<?php <?php
use RedBeanPHP\Facade as RedBean;
class Ticket extends DataStore { class Ticket extends DataStore {
const TABLE = 'tickets'; const TABLE = 'ticket';
private $author;
public static function getProps() { public static function getProps() {
return array( return array(
'ticketId', 'ticketNumber',
'title', 'title',
'content', 'content',
'language', 'language',
@ -16,11 +19,38 @@ class Ticket extends DataStore {
'closed', 'closed',
'author', 'author',
'owner', 'owner',
'ownComments' 'ownCommentList'
); );
} }
protected function getDefaultProps() { public static function getTicket($value, $property = 'id') {
return array(); return parent::getDataStore($value, $property);
}
public function getDefaultProps() {
return array(
'owner' => null
);
}
public function setAuthor(User $user) {
$this->author = $user;
$this->author->addTicket($this);
$this->setProperties(array(
'author' => $this->author->getBeanInstance()
));
}
public function addComment(Comment $comment) {
$this->getBeanInstance()->ownCommentList[] = $comment->getBeanInstance();
}
public function store() {
parent::store();
if ($this->author instanceof User) {
$this->author->store();
}
} }
} }

View File

@ -1,7 +1,8 @@
<?php <?php
use RedBeanPHP\Facade as RedBean;
class User extends DataStore { class User extends DataStore {
const TABLE = 'users'; const TABLE = 'user';
public static function authenticate($userEmail, $userPassword) { public static function authenticate($userEmail, $userPassword) {
$user = User::getUser($userEmail, 'email'); $user = User::getUser($userEmail, 'email');
@ -14,19 +15,16 @@ class User extends DataStore {
'email', 'email',
'password', 'password',
'name', 'name',
'verificationToken', 'verificationToken'
'ownTickets'
); );
} }
public function getDefaultProps() { public function getDefaultProps() {
return array( return array();
'ownTickets' => []
);
} }
public function addTicket($ticket) { public function addTicket(Ticket $ticket) {
$this->ownTickets[] = $ticket; $this->getBeanInstance()->sharedTicketList[] = $ticket->getBeanInstance();
} }
public static function getUser($value, $property = 'id') { public static function getUser($value, $property = 'id') {

14
tests/ticket/comment.rb Normal file
View File

@ -0,0 +1,14 @@
describe 'ticket/comment/' do
it 'should fail if not logged' do
end
describe 'on successful request' do
it 'should add comment to current ticket' do
end
it 'should link the comment to author' do
end
end
end

View File

@ -50,7 +50,7 @@ describe '/ticket/create' do
}) })
(result['status']).should.equal('success') (result['status']).should.equal('success')
ticket = $database.getRow('tickets','Winter is coming','title') ticket = $database.getRow('ticket','Winter is coming','title')
(ticket['content']).should.equal('The north remembers') (ticket['content']).should.equal('The north remembers')
end end
end end

View File

@ -5,7 +5,7 @@ describe '/user/signup' do
'password' => 'custom' 'password' => 'custom'
}) })
userRow = $database.getRow('users', response['data']['userId']) userRow = $database.getRow('user', response['data']['userId'])
(userRow['email']).should.equal('steve@jobs.com') (userRow['email']).should.equal('steve@jobs.com')
end end